`stringr::str_glue`:如何转义反斜杠 (\)?

`stringr::str_glue`: how to escape backslash (\)?

我希望 str_glue 在粘贴时保留 \,但我不知道如何转义它。

我有这个 reprex 我所做的合乎逻辑的尝试:(逃避逃避等)

library(stringr)
var <- "darkness"

str_glue("Hello {var} my old friend \
I've come to talk with you again")
#> Hello darkness my old friend 
#> I've come to talk with you again

str_glue("Hello {var} my old friend \
I've come to talk with you again")
#> Hello darkness my old friend I've come to talk with you again

str_glue("Hello {var} my old friend \\
I've come to talk with you again")
#> Hello darkness my old friend I've come to talk with you again

由 reprex 包 (v2.0.0) 创建于 2021-04-28

我想要的输出:

"Hello darkness my old friend \
I've come to talk with you again"
var <- "darkness"
stringr::str_glue("Hello {var} my old friend \\ \n I've come to talk with you again")
#> Hello darkness my old friend \ 
#> I've come to talk with you again

reprex package (v2.0.0)

于 2021-04-28 创建