Given a vector of strings, I would like to create an expression without the quotation marks.
# eg, I would like to go from
c("string1", "string2")
# to... (notice the lack of '"' marks)
quote(list(string1, string2))
I am encountering some difficulty dropping the quotation marks
input <- c("string1", "string2")
output <- paste0("quote(list(", paste(input, collapse=","), "))")
# not quite what I am looking for.
as.expression(output)
expression("quote(list(string1,string2))")
This is for use in data.table column selection, in case relevant.
What I am looking for should be able to fit into data.table as follows:
library(data.table)
mydt <- data.table(id=1:3, string1=LETTERS[1:3], string2=letters[1:3])
result <- ????? # some.function.of(input)
> mydt[ , eval( result )]
string1 string2
1: A a
2: B b
3: C c
as.quoted
from the plyr package. egoutput <- paste0("list(", paste(input, collapse=","), ")"); as.quoted(output)[[1]]
. I also findsprintf
useful, egsprintf('list(%s)', paste(input, collapse = ', '))
– Cornellcornelle