Why and how do I get rid of the \ in deparse:
variable <- "Only output text"
deparse(variable)
Output: [1] "\"Only output text\""
I would just like to get "Only text" as output.
For example this does not work:
result_description <- paste("result =", cat(deparse(variable)))
result_description
The \
is simply telling you that the double quote following it is part of the string itself. So it is not a \
that is the undesired character in your text, it is the double quotes. You can remove these with a gsub
command very easily:
variable <- "Only output text"
gsub("\"", "", deparse(variable))
#> [1] "Only output text"
However, it's really not clear why you would do this. The line gsub("\"", "", deparse(variable))
is identical to variable
:
gsub("\"", "", deparse(variable)) == variable
#> [1] TRUE
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.