[R] Loading a list into the environment

Rui Barradas ruipbarradas at sapo.pt
Sat Feb 2 00:49:46 CET 2013


Hello,

Something like this?

myfun <- function(x, envir = .GlobalEnv){
	nm <- names(x)
	for(i in seq_along(nm))
		assign(nm[i], x[[i]], envir)
}

myvariables <- list(a=1:10,b=20)

myfun(myvariables)
a
b


Hope this helps,

Rui Barradas

Em 01-02-2013 22:24, Jonathan Greenberg escreveu:
> R-helpers:
>
> Say I have a list:
>
> myvariables <- list(a=1:10,b=20)
>
> Is there a way to load the list components into the environment as
> variables based on the component names?  i.e. by applying this theoretical
> function to myvariables I would have the variables a and b loaded into the
> environment without having to explicitly define them.
>
> --j
>



More information about the R-help mailing list