[英]Why do I get \ in output when using deparse in R?
為什么以及如何在 deparse 中擺脫 \:
variable <- "Only output text"
deparse(variable)
Output: [1] "\"Only output text\""
我只想獲得“僅文本”為 output。
例如,這不起作用:
result_description <- paste("result =", cat(deparse(variable)))
result_description
\
只是告訴您它后面的雙引號是字符串本身的一部分。 因此,文本中不需要的字符不是\
,而是雙引號。 您可以使用gsub
命令非常輕松地刪除它們:
variable <- "Only output text"
gsub("\"", "", deparse(variable))
#> [1] "Only output text"
但是,目前還不清楚您為什么要這樣做。 行gsub("\"", "", deparse(variable))
與variable
相同:
gsub("\"", "", deparse(variable)) == variable
#> [1] TRUE
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.