Skip to content
Prev 345283 / 398500 Next

Using readLines on a file without resetting internal file offset parameter?

Open your file object before calling readLines and close it when you
are done with
a sequence of calls to readLines.

  > tf <- tempfile()
  > cat(sep="\n", letters[1:10], file=tf)
  > f <- file(tf)
  > open(f)
  > # or f <- file(tf, "r") instead of previous 2 lines
  > readLines(f, n=1)
  [1] "a"
  > readLines(f, n=1)
  [1] "b"
  > readLines(f, n=2)
  [1] "c" "d"
  > close(f)

I/O operations on an unopened connection generally open it, do the operation,
then close it.

Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Wed, Oct 29, 2014 at 8:23 AM, Thomas Nyberg <tomnyberg at gmail.com> wrote: