From: "R A F" <raf1729 at hotmail.com>
To: spencer.graves at pdf.com, ripley at stats.ox.ac.uk
CC: R-help at stat.math.ethz.ch
Subject: Re: [R] Scanning data files line-by-line
Date: Wed, 30 Apr 2003 15:21:23 +0000
Hi all, thanks to everyone again for helping out. I don't want to
generate too many messages, but this problem seems common enough that
maybe it's worth a summary.
What I can do is this. Let's say "file" has lines of double, string,
double with variable number of spaces between fields followed by EOF.
aaa <- file( "file", "r" )
while( length( ( x <- scan( aaa, nlines = 1, list( 0, "", 0 ) ) )[[1]] )
{
check to see if x is empty again (by length( x[[1]] ) > 0 ) since
we would read in the EOF character into x still
if not empty
start processing
}
close( aaa )
Here x is a list and x[[1]] is the first field, etc.
Professor Ripley also suggested textConnections, but I didn't
experiment -- I'm usually happy to find something that works. :-)
Thanks again.