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

Uwe Ligges ligges at statistik.uni-dortmund.de
Mon Dec 6 19:13:33 CET 2004


David Whiting wrote:

> 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:
> 
> http://unxutils.sourceforge.net/
> 
> 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).

Well, the also tools required to compile R and packages under Windows 
contain wc.

Anyway, the question is whether you want to write code that performs 
best for a given problem on a given machine, or you want to write 
portable code (e.g. to be used on machines without having wc installed).

Uwe Ligges


> Dave
>




More information about the R-help mailing list