Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 保存字符向量,以便输出文件显示正则表达式特殊字符_R_Regex_String_Readr - Fatal编程技术网

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

R 保存字符向量,以便输出文件显示正则表达式特殊字符,r,regex,string,readr,R,Regex,String,Readr,我有一个字符向量,其中包括regex特殊字符,如\n。 我想将此向量保存到一个txt文件中,该文件显示\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") 下面的代码创建了一个txt文件,但在记事本中打开该文件时,\n会转换为换行符。我不想看到换行符,我想看到\n library(ti

我有一个字符向量,其中包括
regex
特殊字符,如
\n
。 我想将此向量保存到一个txt文件中,该文件显示
\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")
下面的代码创建了一个txt文件,但在记事本中打开该文件时,
\n
会转换为换行符。我不想看到换行符,我想看到
\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\n, nice to meet you.\n\n. how are you?"

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

所以,
my_text@WiktorStribiżew非常感谢。对不起,我的问题应该更清楚。我知道在使用stringr/stringi等搜索文本时会转义反斜杠等。我想知道是否有某种保存/写入命令可以满足转义的需要,例如,在实际将向量保存到文件时会转义反斜杠。你是说类似于
stringi::stri_escape_unicode(my_text)
my_text@WiktorStribiżew非常感谢。对不起,我的问题应该更清楚。我知道在使用stringr/stringi等搜索文本时会转义反斜杠等。我想知道是否有某种保存/写入命令可以满足转义的需要,例如在实际将向量保存到文件时转义反斜杠。你是指类似于
stringi::stri_escape_unicode(my_text)