Rev 46474 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/base/man/seek.Rd% Part of the R package, http://www.R-project.org% Copyright 1995-2007 R Core Development Team% Distributed under GPL 2 or later\name{seek}\alias{seek}\alias{seek.connection}\alias{truncate}\alias{truncate.connection}\alias{isSeekable}\title{Functions to Reposition Connections}\description{Functions to re-position connections.}\usage{seek(con, \dots)\method{seek}{connection}(con, where = NA, origin = "start", rw = "", \dots)isSeekable(con)truncate(con, \dots)}\arguments{\item{con}{a connection.}\item{where}{numeric. A file position (relative to the originspecified by \code{origin}), or \code{NA}.}\item{rw}{character. Empty or \code{"read"} or \code{"write"},partial matches allowed.}\item{origin}{character. One of \code{"start"}, \code{"current"},\code{"end"}: see \sQuote{Details}.}\item{\dots}{further arguments passed to or from other methods.}}\details{\code{seek} with \code{where = NA} returns the current byte offsetof a connection (from the beginning), and with a non-missing \code{where}argument the connection is re-positioned (if possible) to thespecified position. \code{isSeekable} returns whether the connectionin principle supports \code{seek}: currently only (possiblygz-compressed) file connections do. \code{gzfile} connections do notsupport \code{origin = "end"}; the file position they use is thatof the uncompressed file.\code{where} is stored as a real but should represent an integer:non-integer values are likely to be truncated. Note that the possiblevalues can exceed the largest representable number in an \R\code{integer} on 64-bit OSes, and on some 32-bit OSes.#ifdef windowsClipboard connections can seek too.We have found so many errors in the Windows implementation of filepositioning that users are advised to use it only at their own risk,and asked not to waste the \R developers' time with bug reports on Windows'deficiencies.#endifFile connections can be open for both writing/appending, in which case\R keeps separate positions for reading and writing. Which \code{seek}refers to can be set by its \code{rw} argument: the default is thelast mode (reading or writing) which was used. Most files areonly opened for reading or writing and so default to that state. If afile is open for both reading and writing but has not been used, thedefault is to give the reading position (0).The initial file position for reading is always at the beginning.The initial position for writing is at the beginning of the filefor modes \code{"r+"} and \code{"r+b"}, otherwise at the end of thefile. Some platforms only allow writing at the end of the file inthe append modes. (The reported write position for a file opened inan append mode will typically be unreliable until the file has beenwritten to.)If \code{seek} is called with a non-\code{NA} value of \code{where},any pushback on a text-mode connection is discarded.\code{truncate} truncates a file opened for writing at its currentposition. It works only for \code{file} connections, and is notimplemented on all platforms: on others (including Windows) it willnot work for large (> 2Gb) files.}\value{\code{seek} returns the current position (before any move), as a(numeric) byte offset from the origin, if relevant, or \code{0} ifnot. Note that the position can exceed the largest representablenumber in an \R \code{integer} on 64-bit OSes, and on some 32-bitOSes.\code{truncate} returns \code{NULL}: it stops with an error ifit fails (or is not implemented).\code{isSeekable} returns a logical value, whether the connectionsupports \code{seek}.}\seealso{\code{\link{connections}}}\keyword{file}\keyword{connection}