[R] How can I test for End-Of-FIle
jim holtman
jholtman at gmail.com
Mon Jul 13 01:36:21 CEST 2009
You can do something like this:
con <- file("MyFle.txt","r")
repeat {
line <- readLines(con,n=1)
if (length(line) == 0) break
ParseLine(line)
}
On Sun, Jul 12, 2009 at 6:20 PM, <mauede at alice.it> wrote:
> I have a long text file with uneven record length and variable structure.
> Therefore I have to read it line-by-line.
> I found out I can open a connection to the file and read in one line at a time.
> Something like:
>
> con <- file("MyFle.txt","r")
> while (End-Of-File) {
> line <- readLines(con,n=1)
> ParseLine(line)
> }
>
> But I realized I do not know how to test for the End-Of-File condition using R language.
> I found a ghost documentation page mentioning an R built-in function "isEof(connection)".
> But such a function is not listed in R "utils" package it seems to belong to.
>
> I would appreciate any comment and/or suggestion.
> Thank you in advance.
> Maura
>
>
>
>
>
>
> tutti i telefonini TIM!
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?
More information about the R-help
mailing list