[R] EOF revisited

Steve Lianoglou mailinglist.honeypot at gmail.com
Fri Jul 24 17:43:40 CEST 2009


Hi,

On Jul 24, 2009, at 11:12 AM, <mauede at alice.it> <mauede at alice.it> wrote:

> I learnt from this forum to test for EOF reached with fiunction  
> readLines as follows:
>
> con <- file("MyFle.txt","r")
>  repeat {
>   line <-  readLines(con,n=1)
>   if (length(line) == 0) break
>  }
>
> It works fine if I read one line at a time.
> Since now I have a huge file so that it would take forever to read  
> one line at a time,
> I wonder how to test for EOF whenreading blocks of,say, 100 lines at  
> a time.
> Will the following work ?
>
> con <- file("MyFle.txt","r")
>  repeat {
>   line <-  readLines(con,n=100)
>   if (length(line) < 100) break
>  }

I'm guessing that by now you've already rigged up a small 10 line text  
file and set n to be less than (but not a factor of) 10 to test this  
and see for yourself, no?

-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
   |  Memorial Sloan-Kettering Cancer Center
   |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact




More information about the R-help mailing list