避免 write.table 在导出的 .txt 文件中保存 R 的 (\)

avoid write.table to save R's (\) in the exported .txt file

考虑以下字符串:

my_string <- c('this is "my_string", it uses "double-"qoutes" because"" I need them"')

write.table(my_string, "my_string.txt")

当我打开 my_string.txt 文件时,输出如下:

"x"
"1" "this is \"my_string\", it uses \"double-\"qoutes\" because\"\" I need them\""

基本上它添加了 "x" 和“1”,最烦人的是所有文件中都存在反斜杠 ()。

我怎样才能避免这种恼人的事情?

使用 row.names=Fcol.names=Fquote=F

即:

write.table(my_string, "my_string.txt",quote=F,row.names=F, col.names=F)

?write.table 更多选项

我在某处找到的另一种可能的方法是:

fileConn<-file("my_string.txt")

writeLines(my_string, fileConn)

close(fileConn)