Thanks to all for the replies. I tried all three and they work great. I
was misinterpreting the list = parameter in save(...) and I get your
point about overwriting existing objects. I've heard about not using
assign/get before. Can anyone point me to why and what alternatives
there are?
Regards
David
On 6/24/2014 2:50 PM, Henrik Bengtsson wrote:
I recommend to use saveRDS()/readRDS() instead. More convenient and
avoids the risk that load() has of overwriting existing variables with
the same name.
/Henrik
On Tue, Jun 24, 2014 at 1:45 PM, Greg Snow <538...@gmail.com> wrote:
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.stev...@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.stev...@usu.edu
______________________________________________
R-help@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.
538...@gmail.com
______________________________________________
R-help@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.
--
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.stev...@usu.edu
______________________________________________
R-help@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.