[R] appending objects to a file created by save()
David Whiting
david.whiting at ncl.ac.uk
Fri Mar 10 10:49:52 CET 2006
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
More information about the R-help
mailing list