[R] Problems using save to store NAMED R objects
Julio Sergio Santana
juliosergio at gmail.com
Fri Nov 13 03:41:03 CET 2015
I have to store (in a file) an R object that was created with is name as
a string of characters, as follows:
: nn <- "xxx"
: assign(nn, 5)
: xxx
[1] 5
I don't want to store the object nn but the object xxx. I tried the
following two expressions but none of them worked:
: save(get(nn), file="f.RData")
Error in save(get(nn), file = "f.RData") : object ‘get(nn)’ not found
: save(eval(nn), file="f.RData")
Error in save(eval(nn), file = "f.RData") : object ‘eval(nn)’ not
found
I know that both save(xxx, ..), and save("xxx", ..) work, but the fact
is that the string is going to be provided by an user:
: nn <- readline("Your variable->")
and
: save(nn, file="f.RData")
stores the objet nn not xxx
Do you have any comments on this?
Thanks
-Sergio.
More information about the R-help
mailing list