[R] Fast way to determine number of lines in a file

Indian_R_Analyst besteconometrician at gmail.com
Wed Feb 10 12:08:29 CET 2010


Hi Hadley,

Hope this is what you are looking for. This approach provides number
of lines in a large 'bzip' file using chunks.

testconn <- file("xyzxyz.csv.bz2", open="r")
csize <- 10000
nolines <- 0
while((readnlines <- length(readLines(testconn,csize))) >0 ) nolines
<- nolines+readnlines
close(testconn)
nolines

Regards,
Indian_R_Analyst.


On Feb 8, 7:16 pm, Hadley Wickham <had... at rice.edu> wrote:
> Hi all,
>
> Is there afastwayto determine the number of lines in a file?  I'm
> looking for something like count.lines analogous to count.fields.
>
> Hadley
>
> --http://had.co.nz/
>
> ______________________________________________
> R-h... at r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list