mt1022
mt1022

Reputation: 17299

How to load the content of a named list into global environment?

Suppose I have a named list x:

x <- list(a = 1, b = 2)

How can I load the content of x into the global environment so that I can access a and b from the global environment?:

a
# [1] 1
b
# [2] 2

(why I do this: in reality, the x is derived from a .mat file produced by matlab. It's more like an .Rdata file)

Upvotes: 6

Views: 360

Answers (2)

C.Lloyd
C.Lloyd

Reputation: 51

You could also use attach(x) to make a and b available in the search list.

Upvotes: 1

akrun
akrun

Reputation: 887571

We can use list2env

list2env(x, .GlobalEnv)
a
#[1] 1
b
#[1] 2

Upvotes: 8

Related Questions