[R] appending objects to a file created by save()

Adaikalavan Ramasamy ramasamy at cancer.org.uk
Fri Mar 10 12:36:25 CET 2006


Another flexible approach is to zip/tar all the required individual .rda
files together. There are two advantages that I see :
 1) You can extract a single file from the collection if you want.
 2) You can easily list what objects are in the zipped/tarred file. 

In R you have to load all object from a single .rda if you want to
extract a single object or even to list what objects are stored.

In terms of size, the zipped/tarred file gives comparable if not smaller
size than R's function save() with compress=TRUE option. But I have
tested this feature in depth.

Regards, Adai



On Fri, 2006-03-10 at 09:49 +0000, David Whiting wrote:
> On Fri, 2006-03-10 at 03:46 -0500, Rajarshi Guha wrote:
> > Hi,
> >   I've been slowly transitioning to saving sets of objects for a project
> > using save() rather than cluttering my workspace and then doing
> > save.image()
> > 
> > However, sometimes after I have done say:
> > 
> > save(x,y,z, file='work.Rda')
> > 
> > and I reload it a little later and  I see that I also want to save
> > object p. Currently I need to do:
> > 
> > save(x,y,z,p, file='work.Rda')
> > 
> > Is there any way to instruct save to append an object to a previously
> > created binary data file?
> 
> I use this approach. One potential problem with this approach is that if
> you have large saved objects you could get into problems because you
> need to load them before saving them. 
> 
> ## Function to append an object to an R data file.
> append.Rda <- function(x, file) {
>   old.objects <- load(file, new.env())
>   save(list = c(old.objects, deparse(substitute(x))), file = file)
> }
> 
> 
> ## Example:
> x <- 1:10
> y <- letters[1:10]
> save(list = c("x", "y"), file = "temp.Rda")
> z <- "fred"
> append.Rda(z, "temp.Rda")
> 
> 
> Dave
> 
> > 
> > Thanks,
> > 
> > -------------------------------------------------------------------
> > Rajarshi Guha <rxg218 at psu.edu> <http://jijo.cjb.net>
> > GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE
> > -------------------------------------------------------------------
> > CChheecckk yyoouurr dduupplleexx sswwiittcchh..
> > 
> > ______________________________________________
> > R-help at 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-help at 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
>




More information about the R-help mailing list