tags:

views:

97

answers:

2

Hi all,

How can I test for the EOF flag in R? e.g.

f <- file(fname, "rb")
while (???) {
    a <- readBin(f, "int", n=1)
}

Thanks.

+1  A: 

The readLines function will return a zero-length value when it reaches the EOF.

Ben Hoffstein
A: 

Try checking the length of data returned by readBin:

while (length(a <- readBin(f, 'int', n=1)) > 0) {
    # do something
}
ars