I would like to transform c('1','2', 'text')
into a character vector with only one elemenent c('1','2', 'text')
.
I have tried this:
> quote(c('1','2', 'text'))
c("1", "2", "text")
but
> class(quote(c('1','2', 'text')))
[1] "call"
and this:
> toString(quote(c('1','2', 'text')))
[1] "c, 1, 2, text"
which removes all the punctuation (while I would like to keep the exact same string).
deparse
is for converting expressions to character strings.
deparse(c('1','2', 'text'))
#[1] "c(\"1\", \"2\", \"text\")"
cat(deparse(c('1','2', 'text')))
#c("1", "2", "text")
gsub("\"", "'", deparse(c('1','2', 'text')))
#[1] "c('1', '2', 'text')"
deparse(quote(c('1','2', 'text')))
#[1] "c(\"1\", \"2\", \"text\")"
Also look at substitute
deparse(substitute(c(1L, 2L)))
#[1] "c(1L, 2L)"
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