Seymour
Seymour

Reputation: 3284

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:

"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.

How can I avoid this annoying thing?

Upvotes: 0

Views: 44

Answers (2)

Seymour
Seymour

Reputation: 3284

Another possible approach I found somewhere is:

fileConn<-file("my_string.txt")

writeLines(my_string, fileConn)

close(fileConn)

Upvotes: 0

dpel
dpel

Reputation: 2143

Use row.names=F, col.names=F and quote=F

That is:

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

?write.table for more options

Upvotes: 3

Related Questions