[R] Loading data into a list of environments

Charles C. Berry cberry at tajo.ucsd.edu
Sat May 31 23:28:16 CEST 2008


On Sat, 31 May 2008, Powell, Jeff wrote:

> Dear All,
>
> Thanks to an answer which I received from a previous post, I'm now able to create a series of
> environments using the following:
>
>  nmes <- c("en1", "en2", "en3")
>  for(i in nmes) assign(i, new.env(parent = .GlobalEnv))
>
> My next question is how, using "load", can I automatically place data into each of these
> newly created environments.
>
> The following, and variations thereof, does not work:
>
>  nmes <- c("en1", "en2", "en3")
>  for(i in nmes) load(file = "/home/testData/Data.RData", i)
>
> I've tried, among other attempts, to use "as.environment(i)" without success.  My "i" is seen
> as a character, but I want it to be seen as the environment which it represents.

More generally as the object it represents...

Try

 	for(i in nmes) load(file = "/home/testData/Data.RData", get( i ))


See

 	?get

HTH,

Chuck

>
> Kind regards,
> J.Powell
>
> LEI
> Visserij
> Alexanderveld 5
> 2585 DB Den Haag
> The Netherlands
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901



More information about the R-help mailing list