3

Here's some primitive code for an example:

mydf <- data.frame(letters[1:10])

write.table(mydf, "out1r",   eol="\r")
write.table(mydf, "out1x0D", eol=rawToChar(as.raw(13L)))

write.table(mydf, "out1")
write.table(mydf, "out1n",   eol="\n")
write.table(mydf, "out1x0A", eol=rawToChar(as.raw(10L)))

write.table(mydf, "out1rn", eol="\r\n")
write.table(mydf, "out1nr", eol="\n\r")

On the output, first two files are written correctly, with '\r' line-endings, as expected. But next three variants are all written with '\r\n', even if I ask explicitly to put only '\n'! Is it hidden somewhere in R options to force this conversion under Windows?

Vasily A
  • 8,256
  • 10
  • 42
  • 76
  • 1
    My suspicion with these sorts of questions is almost always that it's not R, it's Windows. [This](http://stackoverflow.com/a/1761086/324364) SO question seems to imply that I'm right. – joran Nov 16 '13 at 03:12

1 Answers1

2

?write.table

To write a Unix-style file on Windows, use a binary connection e.g. 'file = file("filename", "wb")'.

antonio
  • 10,629
  • 13
  • 68
  • 136
  • but then it ignores the fileEncoding parameter. so you're writing "binary", except you are not, because you write.table is silently converting your text to the ecoding supported by windows. Due to its reliance on Windows character sets, R on windows is infuriating when it comes to write/read anything. – user27636 Apr 25 '16 at 14:44