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

2004-12-06 Thread Marc Schwartz
On Mon, 2004-12-06 at 22:12 +0800, Hu Chen wrote: hi all If I wanna get the total number of lines in a big file without reading the file's content into R as matrix or data frame, any methods or functions? thanks in advance. Regards See ?readLines You can use: length(readLines(FileName))

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

2004-12-06 Thread Uwe Ligges
Hu Chen wrote: hi all If I wanna get the total number of lines in a big file without reading the file's content into R as matrix or data frame, any methods or functions? You must read it in R, or how do you think should one determine the number of lines in a file (if you don't want to use another

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

2004-12-06 Thread Liaw, Andy
From: Marc Schwartz On Mon, 2004-12-06 at 22:12 +0800, Hu Chen wrote: hi all If I wanna get the total number of lines in a big file without reading the file's content into R as matrix or data frame, any methods or functions? thanks in advance. Regards See ?readLines You can

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

2004-12-06 Thread Thomas Lumley
On Mon, 6 Dec 2004, Uwe Ligges wrote: Hu Chen wrote: hi all If I wanna get the total number of lines in a big file without reading the file's content into R as matrix or data frame, any methods or functions? You must read it in R, or how do you think should one determine the number of lines in a

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

2004-12-06 Thread Liaw, Andy
From: Liaw, Andy From: Marc Schwartz On Mon, 2004-12-06 at 22:12 +0800, Hu Chen wrote: hi all If I wanna get the total number of lines in a big file without reading the file's content into R as matrix or data frame, any methods or functions? thanks in advance.

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

2004-12-06 Thread Marc Schwartz
On Mon, 2004-12-06 at 12:26 -0500, Liaw, Andy wrote: Marc alerted me off-list that count.fields() might spent time delimiting fields, which is not needed for the purpose of counting lines, and suggested using sep=\n as a possible way to make it more efficient. (Thanks, Marc!) Here are

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

2004-12-06 Thread David Whiting
Thomas Lumley [EMAIL PROTECTED] 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

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

2004-12-06 Thread Uwe Ligges
David Whiting wrote: Thomas Lumley [EMAIL PROTECTED] 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

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

2004-12-06 Thread Liaw, Andy
From: Marc Schwartz On Mon, 2004-12-06 at 12:26 -0500, Liaw, Andy wrote: Marc alerted me off-list that count.fields() might spent time delimiting fields, which is not needed for the purpose of counting lines, and suggested using sep=\n as a possible way to make it more efficient.

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

2004-12-06 Thread Kjetil Brinchmann Halvorsen
Liaw, Andy wrote: From: Marc Schwartz On Mon, 2004-12-06 at 22:12 +0800, Hu Chen wrote: hi all If I wanna get the total number of lines in a big file without reading the file's content into R as matrix or data frame, any methods or functions? thanks in advance. Regards See

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

2004-12-06 Thread Marc Schwartz
On Mon, 2004-12-06 at 14:00 -0500, Liaw, Andy wrote: Marc, I wrote the following function to read the file in chunks: countLines - function(file, chunk=1e3) { f - file(file, r) on.exit(close(f)) nLines - 0 while((n - length(readLines(f, chunk))) 0) nLines - nLines + n

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

2004-12-06 Thread Richard A. O'Keefe
Hu Chen asked If I wanna get the total number of lines in a big file without reading the file's content into R as matrix or data frame, any methods or functions? _Something_ must read it, but it doesn't have to be R. On a UNIX system, you can simply do