R:从带有换行符的用户输入中读取一行

R: read in a line from user input with newline character

我正在尝试使用 readline() 读取用户输入。不幸的是,我的输入有一个换行符,它被转义了。

> readline(prompt = "Tell me: ")
Tell me: first\nsecond
[1] "first\nsecond"

如何获得

[1] "first\nsecond"

您只想删除多余的 \ 吗?如果是:

x
#> [1] "first\nsecond"

gsub("\n", "\n", x, fixed = TRUE)
#> [1] "first\nsecond"

reprex package (v2.0.1)

创建于 2022-01-04