seek                  package:base                  R Documentation

_F_u_n_c_t_i_o_n_s _t_o _R_e_p_o_s_i_t_i_o_n _C_o_n_n_e_c_t_i_o_n_s

_D_e_s_c_r_i_p_t_i_o_n:

     Functions to re-position connections.

_U_s_a_g_e:

     seek(con, ...)
     ## S3 method for class 'connection':
     seek(con, where = NA, origin = "start", rw = "", ...)

     isSeekable(con)

     truncate(con, ...)

_A_r_g_u_m_e_n_t_s:

     con: a connection.

   where: numeric.  A file position (relative to the origin specified
          by 'origin'), or 'NA'.

      rw: character.  Empty or '"read"' or '"write"', partial matches
          allowed.

  origin: character.  One of '"start"', '"current"', '"end"': see
          'Details'.

     ...: further arguments passed to or from other methods.

_D_e_t_a_i_l_s:

     '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.  'gzfile' connections do not support 'origin
     = "end"'; the file position they use is that of the uncompressed
     file.

     '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 OSes, and on some 32-bit OSes.

     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) which was used.  Most files are
     only opened for reading or writing and so default to that state. 
     If a file is open for both reading and writing but has not been
     used, the default 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 file
     for modes '"r+"' and '"r+b"', otherwise at the end of the file. 
     Some platforms only allow writing at the end of the file in the
     append modes.  (The reported write position for a file opened in
     an append mode will typically be unreliable until the file has
     been written to.)

     If 'seek' is called with a non-'NA' value of 'where', any pushback
     on a text-mode connection is discarded.

     'truncate' truncates a file opened for writing at its current
     position.  It works only for 'file' connections, and is not
     implemented on all platforms: on others (including Windows) it
     will not work for large (> 2Gb) files.

_V_a_l_u_e:

     '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 OSes, and on some 32-bit OSes.

     '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'.

_S_e_e _A_l_s_o:

     'connections'

