[R] save() unable to find object
    Ivan Krylov 
    kry|ov@r00t @end|ng |rom gm@||@com
       
    Thu Oct 31 10:25:08 CET 2019
    
    
  
On Thu, 31 Oct 2019 14:39:48 +0530
Christofer Bogaso <bogaso.christofer using gmail.com> wrote:
> Error in save("Date", paste("AAA", format(Date, "%d"), sep = ""), file
> = "Save.RData") :
>   object ‘paste("AAA", format(Date, "%d"), sep = "")’ not found
save() uses non-standard evaluation [*], which means that, instead of
just getting parameter values, it gets the expressions supplied to it
by the caller in their original form. This makes it possible to pass
variable names to save() unquoted: save() will still get the name, not
the value of the variable.
This also causes error messages like yours. To prevent the non-standard
evaluation from causing problems, pass the names of the variables as a
character vector in the list = ... argument to save().
Alternatively, consider avoiding "variable variable names". Restricting
objects with programmatically generated names to a named list might
lead to cleaner code:
mydata <- list()
mydata[paste('AAA', format(Date, "%d"), sep = ""] <- 5
saveRDS(mydata, 'mydata.rds')
-- 
Best regards,
Ivan
[*] https://adv-r.hadley.nz/metaprogramming.html
    
    
More information about the R-help
mailing list