簡體   English   中英

為什么在 R 中使用 deparse 時,在 output 中會出現 \?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM