[R] load ing and saving R objects

Roger D. Peng rpeng at jhsph.edu
Tue Jun 14 15:38:27 CEST 2005


I would suggest saving each object to an individual file with 
some sort of systematic file name.  That way, you can implement a 
  rudimentary key-value database and load only the objects you 
want.  You might be interested in the 'serialize()' and 
'unserialize()' functions for this purpose.

If having ~15000 files is not desirable, then you need a database 
like GDBM.  If you can live with something simpler, you might 
take a look at my 'filehash' package at 
http://sandybox.typepad.com/software/.  It hasn't been tested 
much but it may suit your needs.

-roger

Richard Mott wrote:
> Does anyone know a way to do the following:
> 
> Save a large number of R objects to a file (like load() does) but then 
> read back only a small named subset of them . As far as I can see, 
> load() reads back everything.
> 
> The context is:
> 
> I have an application which will generate a large number of large 
> matrices (approx 15000 matrices each of dimension 2000*30). I can 
> generate these matrices using an R-package I wrote, but it requires a 
> large amouint of memory and is slow so I want to do this only once.  
> However, I then want to do some subsequent processing, comprising a very 
> large number of runs in which small  (~ 10) random selection of matrices 
> from the previously computed set are used for linear modeling.  So I 
> need a way to load back named objects previously saved in a call to 
> save(). I can;t see anyway of doing this. Any ideas?
> 
> Thanks
> 
> Richard Mott
>  
> 

-- 
Roger D. Peng
http://www.biostat.jhsph.edu/~rpeng/




More information about the R-help mailing list