I know this is simple, but I cannot find a straightforward solution.
How can I tell the interpreter to read vector contents as string without using quotation marks? Example:
vector<-c("AAA", "BBB", "CCC", "DDD", "EEE", "FFF", "GGG", "HHH")
vector
[1] "AAA" "BBB" "CCC" "DDD" "EEE" "FFF" "GGG" "HHH"
What if I want to build the same object with:
vector<-c(AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH)
Error: object 'AAA' not found
Do we have some function like "to.character" or something? It would help me much. Thanks in advance, sorry for naive question.
Without quotes, AAA
etc will be interpreted as names and an object with this name will be sought for. So you will need nonstandard evaluation (using the argument "as is", without evaluating -- substitute
returns the unevaluated expression, and deparse
converts it to a string), something like
c__ <- function(...) sapply(substitute(list(...)),deparse)[-1]
vec <-c__(AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH)
vec
# [1] "AAA" "BBB" "CCC" "DDD" "EEE" "FFF" "GGG" "HHH"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With