Skip to content
Prev 245567 / 398503 Next

Write.table eol argument

At least on Windows, you need to open the
file in "binary" mode (as opposed to "text"
mode) to prevent the usual OS-dependent way
of encoding end-of-line. E.g.,

  > z <- data.frame(x=1:3, y=state.name[1:3])
  > f <- file("tmp.csv", open="wb")
  > write.table(z, file=f, quote=FALSE, sep=";", eol="\n")
  > close(f) # do not forget to close it!
  > system("e:\\cygwin\\bin\\od -c --width=8 tmp.csv")
  0000000   x   ;   y  \n   1   ;   1   ;
  0000010   A   l   a   b   a   m   a  \n
  0000020   2   ;   2   ;   A   l   a   s
  0000030   k   a  \n   3   ;   3   ;   A
  0000040   r   i   z   o   n   a  \n
  0000047

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com