[英]Why do I get \ in output when using deparse in R?
Why and how do I get rid of the \ in deparse:为什么以及如何在 deparse 中摆脱 \:
variable <- "Only output text"
deparse(variable)
Output: [1] "\"Only output text\""
Output: [1] "\"Only output text\""
I would just like to get "Only text" as output.我只想获得“仅文本”为 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:您可以使用gsub
命令非常轻松地删除它们:
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
相同:
gsub("\"", "", deparse(variable)) == variable
#> [1] TRUE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.