Skip to content

unexpected behavior from gzfile and unz

1 message · Matthew Suderman

#
I get unexpected behavior from "readLines()" and
"scan()" depending on how the file is opened with
"gzfile" or "unz".  More specifically:
[1] "a\tb\tc"
[1] "a\tb\tc"
It seems that the stream is rewound between calls to
readLines.  The same is true if I replace readLines
with scan.

However, if I set argument 'open="r"', then rewinding
does not occur:
[1] "a\tb\tc"
[1] "1\t2\t3"
Once again, I get the same behavior for scan.  The
rewinding behavior just described also appears if I
open a zip file with "unz".
[1] "a\tb\tc"
[1] "a\tb\tc"
If I add the 'open="r"' argument to the call then I
get an error from readLines:
Error in readLines(file, 1) : seek not enabled for
this connection
Error in readLines(file, 1) : seek not enabled for
this connection
However, if I instead use "scan" to read the file,
then there are no errors and I get the rewind/no
rewind behavior described above.
Read 3 items
[1] "a" "b" "c"
Read 3 items
[1] "a" "b" "c"
Read 3 items
[1] "a" "b" "c"
Read 3 items
[1] "1" "2" "3"
Is this a bug?

Matt



      ____________________________________________________________________________________
Be a better friend, newshound, and