This is because scan() has a private pushback. Either:
1) Read the file a whole line at a time: I cannot see why you need to do so here nor in your sketched application.
or
2) Use an explicit separator, e.g. " " in your example.
scan() is not designed to read parts of lines of a file,
On Tue, 18 Jan 2005, Tim Howard wrote:
R gurus,
My use of scan() seems to be dropping the first digit of sequential scans on a connection. It looks like it happens only within a line:
cat("TITLE extra line", "235 335 535 735", "115 135 175",file="ex.data", sep="\n")Read 2 itemscn.x <- file("ex.data", open="r") a <- scan(cn.x, skip=1, n=2)a[1] 235 335b <- scan(cn.x, n=2)Read 2 itemsb[1] 35 735c <- scan(cn.x, n=2)Read 2 itemsc[1] 115 135d <- scan(cn.x, n=1)Read 1 itemsd[1] 75
Note in b, I should get 535, not 35 as the first value. In d, I should get 175. Does anyone know how to get these digits?
The reason I'm not scanning the entire file at once is that my real dataset is much larger than a Gig and I'll need to pull only portions of the file in at once. I got readLines to work, but then I have to figure out how to convert each entire line into a data.frame. Scan seems a lot cleaner, with the exception of the funny character dropping issue.
Thanks so much! Tim Howard
______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
-- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
