[英]avoid write.table to save R's (\) in the exported .txt file
Considering the following string: 考虑以下字符串:
my_string <- c('this is "my_string", it uses "double-"qoutes" because"" I need them"')
write.table(my_string, "my_string.txt")
When I open the my_string.txt
file the output is exactly the following: 当我打开
my_string.txt
文件时,输出将完全是以下内容:
"x"
"1" "this is \"my_string\", it uses \"double-\"qoutes\" because\"\" I need them\""
Basically it added "x" and "1" and the most annoying thing are the back-slash () present in all the file. 基本上,它添加了“ x”和“ 1”,最令人讨厌的是所有文件中都存在反斜杠()。
How can I avoid this annoying thing? 如何避免这种烦人的事情?
Use row.names=F
, col.names=F
and quote=F
使用
row.names=F
, col.names=F
和quote=F
That is: 那是:
write.table(my_string, "my_string.txt",quote=F,row.names=F, col.names=F)
?write.table
for more options ?write.table
获得更多选项
Another possible approach I found somewhere is: 我在某处找到的另一种可能的方法是:
fileConn<-file("my_string.txt")
writeLines(my_string, fileConn)
close(fileConn)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.