[R] loading saved files with objects in same names

Duncan Murdoch murdoch.duncan at gmail.com
Sat Aug 23 01:09:27 CEST 2014


On 22/08/2014, 1:14 PM, Jinsong Zhao wrote:
> On 2014/8/22 1:02, Martin Maechler wrote:
>>
>>> Have you tried the 'envir' argument to load()?  E.g.,
>>>     envA <- new.environment()
>>>     load("A.RData", envir=envA)
>>>     envB <- new.environment()
>>>     load("B.RData", envir=envB)
>>>     plot(A$object, B$object)
>>
>>> Bill Dunlap
>>> TIBCO Software
>>> wdunlap tibco.com
>>
>> An alternative that I have been advocating is using
>>
>>    attach("A.RData")
>>
>> etc. It does something similar as the above, but more
>> conveniently:
>> It loads the objects into a new environment  *and* attaches that
>> environment to your search()  path, so you can access them
>> directly, but attach() will never accidentally destroy existing
>> R objects in your global environment ( = search()[[1]] ).
>>
>> Martin
>>
> 
> Thanks a lot.
> 
> I try your method, and I got:
> 
>  > attach("D2.1.RData")
> The following objects are masked _by_ .GlobalEnv:
> 
>      coda.jags.1, df.1, jags.1, Mean, N
> 
> In this case, how to access the masked objects?

Don't ever use attach(), and this won't be a problem.  Martin gave you
bad advice.

Duncan Murdoch



More information about the R-help mailing list