[R] how to get how many lines there are in a file.

David Whiting david.whiting at ncl.ac.uk
Mon Dec 6 18:52:40 CET 2004

Thomas Lumley <tlumley at u.washington.edu> writes:


> If the file is large enough that you don't want to read the whole
> thing at once you can read it in chunks using readLines(). If all the
> lines are the same length you can find the size of the file and divide
> by the length of a line.
> Also, you don't say what OS you are on.  If it isn't Windows the
> easiest thing would be to use wc.

Part of the reason I got into Linux was because I needed to do
(little?)  things that I found tricky to do in Windows and bit-by-bit
I accumulated various *nix tools that had been ported to DOS/Windows,
such as these found here:


So if your OS is Windows you could stick with it and still use wc
(assuming that it works in the same way as under Linux---I haven't
tested the version at this location).


David Whiting
University of Newcastle upon Tyne, UK

More information about the R-help mailing list