[R] Write.table eol argument
William Dunlap
wdunlap at tibco.com
Tue Dec 21 23:09:20 CET 2010
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
> -----Original Message-----
> From: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] On Behalf Of Jim Moon
> Sent: Tuesday, December 21, 2010 1:37 PM
> To: R-help at r-project.org
> Subject: [R] Write.table eol argument
>
> Hello All,
>
> R 2.11.1
> Windows XP, 32-bit
>
> Help says that default is eol='\n'. To me, that represents
> Linefeed (LF)
>
> >From Help:
> eol the character(s) to print at the end of each line
> (row). For example, eol="\r\n" will produce Windows' line
> endings on a Unix-alike OS, and eol="\r" will produce files
> as expected by Mac OS Excel 2004.
>
> I would like for write.table to end each line with LF only-no
> carriage return (CR).
>
> Default eol='\n' generates CRLF
> Explicit eol='\n' generates CRLF
> eol='\r' generates CR
> eol='\r\n' generates (predictably) CRCRLF
>
> Thank you for your time.
>
> Jim
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list