[R] how to read a file one line at a time?
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Fri Nov 12 17:51:45 CET 1999
"Terry Westley" <twestley at buffalo.veridian.com> writes:
> Is there a way to read a file one line at a time?
> My file is potentially very large (multiple gigabytes)
> so I'd like to read and process one line at a time.
>
> The only choices I see are:
>
> 1) Direct the file to standard input and use readline(),
> but then I have to parse the data columns myself.
>
> 2) Call scan() with nlines=1 over and over again, incrementing
> skip, but I suspect that it will read the whole file each
> time.
>
> Any suggestions?
Somewhere in the attic of my mind lies a plan to implement something
similar to the streams datatype of S4, but I don't think it will
happen soon.
I think the expedient way is to write a trio of short C routines for
dyn.loading and R wrappers: OpenFile, GetLine, CloseFile.
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list