rluech
rluech

Reputation: 616

converting character vector to unquoted names of objects

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

Upvotes: 2

Views: 950

Answers (1)

rluech
rluech

Reputation: 616

And this would be the answer based on @Moody_Mudskipper's comment

x <- "hello"
y <- "world"
obj <- c("x", "y")
do.call(save, c(lapply(obj, as.name), file="./test.rda"))

analog with devtools::use_data()

Upvotes: 4

Related Questions