How can I pass a character vector naming existing objects to a function that only accepts unquoted names of existing objects?
devtools::use_data(..., )
?use_data: ... Unquoted names of existing objects to save.
for example an alternative interface is provided by ?save():
base::save(..., list=, )
?save: list A character vector containing the names of objects to be saved.
Example:
x <- "hello"
y <- "world"
save(x, y, file="./test.rda") # works fine
save(c("x", "y"), file="./test.rda")
>> Error in save(c("x", "y"), file = "./test.rda") : Objekt ‘c("x", "y")’ nicht gefunden
I'm sure this has been asked and answered many times but I couldn't find a solution. I unsuccesfully tried with the usual suspects as.name(), noquote(), get(), eval(), parse(), substitute(), etc.
The closest I got was
unquote(c("x", "y")
Thanks for any help or redirection
save(list = c("x", "y"), file="./test.rda")do.call(function(...) save(...,file="./test.rda"), as.list(c("x", "y")))though you might want something looking more likedo.call(function(...) save(...,file="./test.rda"), lapply(c("x", "y"), as.name))for other cases.rlang/tidyverseyou can also useinvoke(save, lapply(obj, as.name), file="./test.rda")which is less awkward to deal with additional arguments.