This bug report follows discussion in the R-devel mailing list starting with this post:
In summary: writing a file using
x <- data.frame(a = I("a \" quote"), b = pi)
write.csv(x, file = "foo.csv", fileEncoding = "UTF-16LE")
produced bad results. Prior to R-devel revision 70247 there was an issue with
strings being truncated at null bytes, but that has been fixed. However, there
are still problems on Windows, because it will insert single byte \r characters
as it writes the file in text mode, leading to an invalid file.
There appear to be two approaches for a solution on Windows: First, we could tell Windows the encoding as part of the mode argument when the output file was opened. Then it would insert the correct two-byte \r character.
An alternative requires a bigger change, but I think would be better: we could handle the \r insertions ourselves, rather than telling Windows to do it. This would have the advantage that we would not be restricted to the limited set
of encodings that Windows text mode can handle (UNICODE, UTF-8, and UTF-16LE). If all text file handling were done in R, we could make it easier for both Unix and Windows to write text files with line-endings in either format. This would require adding an "eol" argument to a number of functions, e.g. to file().