[R] How to manipulate the pointer of a file?

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Apr 12 18:00:36 CEST 2007


On Thu, 12 Apr 2007, Yuchen Luo wrote:

> With file( ) to obtain a pointer of a file,  every time we use scan ( ) to
> read one row of it, the pointer will point to the next row of the file. In
> the following example, d1 and d2 are obtained the same way but they
> correspond to different rows of the same file because the pointer of the
> file moves down a row when a row of the file is read.

Yes, as documented.  Isn't that good?

[...]

> My question is, how to manipulate the pointer of the file further? For
> example, what if I need the pointer to go back to the previous row?

See ?seek, which is linked from the help page for file().

Using accurate terminology helps: file() gives you a connection.  Part of 
a connection is two positions (one each for read and write).

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list