Re: [R] load object

2005-01-14 Thread Fernando Henrique Ferraz P. da Rosa
Weiwei Shi writes:
 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.

As load() when used interactively will load it into the Global
workspace by default, you can just use get() on it.

r0.prune - 1:10
save(r0.prune,file='dados.dat')
rm(r0.prune)
t - get(load('dados.dat'))
t

--
Fernando Henrique Ferraz P. da Rosa
http://www.ime.usp.br/~feferraz

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] load object

2005-01-13 Thread Weiwei Shi
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

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] load object

2005-01-13 Thread Douglas Bates
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.
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] load object

2005-01-13 Thread Marc Schwartz
On Thu, 2005-01-13 at 11:00 -0800, 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...


Does the following help?


# create the object
 r0.prune - 1:10

# display the object
 r0.prune
 [1]  1  2  3  4  5  6  7  8  9 10

# save the object
 save(r0.prune, file='r0.prune')

# show the object is present
 ls()
[1] r0.prune

# remove the object
 rm(r0.prune)

# show that the object is gone
 ls()
character(0)

# reload the object into the current workspace
 load('r0.prune')

# show the object is back
 ls()
[1] r0.prune

# display the object
 r0.prune
 [1]  1  2  3  4  5  6  7  8  9 10


# now remove the object again
 rm(r0.prune)

# It's gone
 ls()
character(0)

# now use:
 t - load('r0.prune')

# See what is now present
 ls()
[1] r0.prune t

 t
[1] r0.prune

 r0.prune
 [1]  1  2  3  4  5  6  7  8  9 10


't' returns the _name(s)_ of the loaded object(s) as a character vector,
just as documented.

The object itself is available in the workspace. You can use 'r0.prune'
just as per normal routine:

 mean(r0.prune)
[1] 5.5

 MyList - list(r0.prune)

 MyList
[[1]]
 [1]  1  2  3  4  5  6  7  8  9 10


HTH,

Marc Schwartz

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] load object

2005-01-13 Thread Ray Brownrigg
 From: Douglas Bates [EMAIL PROTECTED] Fri Jan 14 08:35:33 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
 
Well ?load does say:
Value:

 A character vector of the names of objects created, invisibly.

Note the plurals.  The point is that the file being loaded may contain
the definition of more than one R object.  You can say:
tt - get(load('r0.prune')) # t is not a good example name to use
which will do what you want, but:
1) load() has a side-effect of also creating r0.prune (in your case)
2) if the file 'r0.prune' contains more than one object, only the first
is assigned to tt (but all of them are loaded into memory with their
original names).

Hope this helps,
Ray Brownrigg

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] load object

2005-01-13 Thread Weiwei Shi
Hi,
thanks for everyone.
I think function get is what I wanted.
?get returns like:
Description:
Search for an R object with a given name and return
it.

Actually I need such reference to handle this obj.
Sorry if there is a misleading description in my
previous email.

weiwei

--- Ray Brownrigg [EMAIL PROTECTED] wrote:

  From: Douglas Bates [EMAIL PROTECTED] Fri Jan 14
 08:35:33 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
  
 Well ?load does say:
 Value:
 
  A character vector of the names of objects
 created, invisibly.
 
 Note the plurals.  The point is that the file being
 loaded may contain
 the definition of more than one R object.  You can
 say:
 tt - get(load('r0.prune'))   # t is not a good
 example name to use
 which will do what you want, but:
 1) load() has a side-effect of also creating
 r0.prune (in your case)
 2) if the file 'r0.prune' contains more than one
 object, only the first
 is assigned to tt (but all of them are loaded into
 memory with their
 original names).
 
 Hope this helps,
 Ray Brownrigg


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html