保存字符向量,以便输出文件显示正则表达式特殊字符[重复]

I have a character vector which includes regex special characters such as \n. I want to save this vector to a txt-file which shows the \n.

The code below creates a txt file, but when opening the file e.g. in notepad, the \n are translated into linebreaks. I don't want to see the linebreaks, I want to see \n.

library(tidyverse)
my_text <- "hello\n, nice to meet you.\n\n. how are you?"
my_text
readr::write_file(my_text, "my_text.txt")

这是记事本显示的内容:

hello
, nice to meet you.

. how are you?

但我想看看

"hello\n, nice to meet you.\n\n. how are you?"

我以为有某种“原始选项”,但似乎我错了。谢谢!

评论