serialize                package:base                R Documentation

_S_i_m_p_l_e _S_e_r_i_a_l_i_z_a_t_i_o_n _I_n_t_e_r_f_a_c_e

_D_e_s_c_r_i_p_t_i_o_n:

     A simple low level interface for serializing to connections.

_U_s_a_g_e:

     serialize(object, connection, ascii = FALSE, refhook = NULL)
     unserialize(connection, refhook = NULL)
     .saveRDS(object, file = "", ascii = FALSE, version = NULL,
              compress = FALSE, refhook = NULL)
     .readRDS(file, refhook = NULL)

_A_r_g_u_m_e_n_t_s:

  object: R object to serialize.

    file: a connection or the name of the file where the R object is
          saved to or read from, or 'NULL' for 'serialize' or for
          'unserialize' an object returned by 'serialize' (see
          Details).

   ascii: a logical.  If 'TRUE', an ASCII representation is written;
          otherwise (default), a more compact binary one is used.

 version: the workspace format version to use.  'NULL' specifies the
          current default format.  The version used from R 0.99.0 to R
          1.3.1 was version 1.  The default format as from R 1.4.0 is
          version 2.

compress: a logical specifying whether saving to a named file is to use
          compression.  Ignored when 'file' is a connection and for
          workspace format version 1.

connection: an open connection.

 refhook: a hook function for handling reference objects.

_D_e_t_a_i_l_s:

     The function 'serialize' writes 'object' to the specified
     connection.  Sharing of reference objects is preserved within the
     object but not across separate calls to serialize.  If
     'connection' is 'NULL' then 'object' is serialized to a scalar
     string, which is returned as the result of 'serialize'. For a text
     mode connection, the default value of 'ascii' is set to 'TRUE'.

     'unserialize' reads an object (as written by 'serialize') from
     'connection'.

     The 'refhook' functions can be used to customize handling of
     non-system reference objects (all external pointers and weak
     references, and all environments other than name space and package
     environments and '.GlobalEnv').  The hook function for 'serialize'
     should return a character vector for references it wants to
     handle; otherwise it should return 'NULL'.  The hook for
     'unserialize' will be called with character vectors supplied to
     'serialize' and should return an appropriate object.

_V_a_l_u_e:

     For 'serialize', 'NULL' unless 'connection=NULL', when the result
     is stored in the first element of a character vector (but is not a
     normal character string unless 'ascii = TRUE' and should not be
     processed except by 'unserialize').

     For 'unserialize' and '.readRDS', an R object.

     For '.saveRDS', 'NULL' invisibly.

_W_a_r_n_i_n_g:

     These functions are still experimental.  Both names, interfaces
     and values might change in future versions (and are expected to
     for R 2.4.0). '.saveRDS' and '.readRDS' are intended for internal
     use.

_E_x_a_m_p_l_e_s:

     x <- serialize(list(1,2,3), NULL)
     unserialize(x)
     (y <- charToRaw(x))
     unserialize(y)

