[R] saving a 'get' object in R

Greg Snow 538280 at gmail.com
Tue Jun 24 22:45:39 CEST 2014


I think that you are looking for the `list` argument in `save`.

save( list=foo, file=paste0(foo, '.Rdata') )

In general it is best to avoid using the assign function (and get when
possible).  Usually there are better alternatives.

On Tue, Jun 24, 2014 at 2:35 PM, David Stevens <david.stevens at usu.edu> wrote:
> R community,
>
> Apologies if this has been answered. The concept I'm looking for is to
> save() an object retrieved using get() for an object
> that resulted from using assign. Something like
>
> save(get(foo),file=paste(foo,'rData',sep=''))
>
> where assign(foo,obj) creates an object named foo with the contents of obj
> assigned. For example, if
>
> x <- data.frame(v1=c(1,2,3,4),v2=c('1','2','3','4'))
> foo = 'my.x'
> assign(foo,x)
> # (... then modify foo as needed)
> save(get(foo),file=paste(foo,'.rData',sep=''))
>
> # though this generates " in save(get(foo), file = paste(foo, ".rData", sep
> = "")) :
> object ‘get(foo)’ not found", whereas
>
> get(foo)
>
> at the command prompt yields the contents of my.x
>
> There's a concept I'm missing here. Can anyone help?
>
> Regards
>
> David Stevens
>
> --
> David K Stevens, P.E., Ph.D.
> Professor and Head, Environmental Engineering
> Civil and Environmental Engineering
> Utah Water Research Laboratory
> 8200 Old Main Hill
> Logan, UT  84322-8200
> 435 797 3229 - voice
> 435 797 1363 - fax
> david.stevens at usu.edu
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Gregory (Greg) L. Snow Ph.D.
538280 at gmail.com



More information about the R-help mailing list