[R] Reading newlines with read.table?

Allan Engelhardt allane at cybaea.com
Fri Jun 4 15:49:47 CEST 2010

I have a text file that is UTF-16LE encoded with CRLF line endings and 
'@' as field separators that I want to read in R on a Linux system.  
Which would be fine as

read.table("foo.txt", file.encoding = "UTF-16LE", sep = "@", ...)

*except* that the data may contain the LF character which R treats as 
end-of-line and then barfs that there are too few elements on that line.

Any suggestions for how to process this one efficiently in R?  There is 
probably a solution using read.table(..., nrows = 1, ...) to get the 
header, split it on '@', build a list with that many character(0) 
elements, and then using scan(..., multi.line=TRUE, ...) ..... but that 
all sounds very complicated.


More information about the R-help mailing list