[R] load object

Douglas Bates bates at wisc.edu
Thu Jan 13 20:27:18 CET 2005


Weiwei Shi wrote:
> Hi,
> I happen to re-write my codes to save memory and my
> approach is write my obj into file first and later I
> load it.
> 
> However, it seems like:
> load(filename) can load the object but the function
> returns the name of the object instead of the
> reference to it. For example, I have an object called
> r0.prune, which is saved by
> save(r0.prune, file='r0.prune')
> 
> and later, I want to load it by using:
> load('r0.prune')
> but I need to put the reference to the object r0.prune
> into a var or a list. I tried:
> t<-load('r0.prune'),
> and class(t) gave me a char, which means t stores the
> name of obj instead of the obj itself.
> 
> Sorry for the dumb question but please help...
> 
> Weiwei

I was going to suggest that you read the help page for load but when I 
looked at it myself I found that it was not obvious what the effect of 
calling load at the prompt is.  The help page is accurate but it is a 
bit confusing if you don't know what the default environment is.

Anyway, when called from the prompt, load has the side effect of loading 
the object into the global environment.  Try

save(r0.prune, file='r0.prune')
rm(r0.prune)
find(r0.prune)  # should produce an error message
load('r0.prune')
find(r0.prune)  # should show the object in the global environment
str(r0.prune)   # etc.




More information about the R-help mailing list