ID EN
I/O & Files

seek

R Base 3.6.2

Functions to re-position connections.

Syntax

R
seek(con, …)
# S3 method for connection
seek(con, where = NA, origin = "start", rw = "", &#8230;)<p></p><p>isSeekable(con)</p><p>truncate(con, &#8230;)</p>

Arguments

Parameter Description
con a connection.
where numeric. A file position (relative to the origin specified by origin), or NA.
rw character string. Empty or "read" or "write", partial matches allowed.
origin character string. One of "start", "current", "end": see ‘Details’.
&#8230; further arguments passed to or from other methods.

Return Value

seek returns the current position (before any move), as a (numeric) byte offset from the origin, if relevant, or 0 if not. Note that the position can exceed the largest representable number in an R integer on 64-bit builds, and on some 32-bit builds. truncate returns NULL: it stops with an error if it fails (or is not implemented). isSeekable returns a logical value, whether the connection supports seek.

Details

seek with where = NA returns the current byte offset of a connection (from the beginning), and with a non-missing where argument the connection is re-positioned (if possible) to the specified position. isSeekable returns whether the connection in principle supports seek: currently only (possibly gz-compressed) file connections do. where is stored as a real but should represent an integer: non-integer values are likely to be truncated. Note that the possible values can exceed the largest representable number in an R integer on 64-bit builds, and on some 32-bit builds. File connections can be open for both writing/appending, in which case R keeps separate positions for reading and writing. Which seek refers to can be set by its rw argument: the default is the last mode (reading or writing) w

See Also

connections