Re: [R] load ing and saving R objects

From: Barry Rowlingson <B.Rowlingson_at_lancaster.ac.uk>
Date: Tue 14 Jun 2005 - 23:24:53 EST

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.

  Save them to individual files when you generate them?

  for(i in 1:15000){

   m=generateBigMatrix(i)

   filename=paste("BigMatrix-",i,".Rdata",sep='')    save(m,file=filename)
  }

Note that load will always overwrite 'm', so to load a sample of them in you'll need to do something like this:

  bigSamples=list()

  for(i in sample(15000,N)){
    filename=paste("BigMatrix-",i,".Rdata",sep='')     load(filename)
    bigSamples[[i]]=m
  }

  But there may be a more efficient way to string up a big list like that, I can never remember - get it working, then worry about optimisation.

  I hope your filesystem is happy with 15000 objects in it. I would dedicate a folder or directory for just these objects' files, since it then becomes near impossible to see anything other than the big matrix files...

Baz



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 Received on Tue Jun 14 23:28:43 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:34 EST