簡體   English   中英

避免使用write.table將R(\\)保存在導出的.txt文件中

[英]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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM