ID EN
Miscellaneous

serialize

R Base 3.6.2

A simple low-level interface for serializing to connections.

Syntax

R
serialize(object, connection, ascii, xdr = TRUE,
          version = NULL, refhook = NULL)<p></p><p>unserialize(connection, refhook = NULL)</p>

Arguments

Parameter Description
object R object to serialize.
connection an open connection or (for serialize) NULL or (for unserialize) a raw vector (see ‘Details’).
ascii a logical. If TRUE or NA, an ASCII representation is written; otherwise (default) a binary one. See also the comments in the help for save.
xdr a logical: if a binary representation is used, should a big-endian one (XDR) be used?
version the workspace format version to use. NULL specifies the current default version (3). The only other supported value is 2, the default from R 1.4.0 to R 3.5.0.
refhook a hook function for handling reference objects.

Return Value

For serialize, NULL unless connection = NULL, when the result is returned in a raw vector. For unserialize an R object.

Details

The function serialize serializes object to the specified connection. If connection is NULL then object is serialized to a raw vector, which is returned as the result of serialize. Sharing of reference objects is preserved within the object but not across separate calls to serialize. unserialize reads an object (as written by serialize) from connection or a raw vector. 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 namespace 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 seri

Examples

Example
R
# NOT RUN {
x <- serialize(list(1,2,3), NULL)
unserialize(x)

## see also the examples for saveRDS
# }

See Also

saveRDS for a more convenient interface to serialize an object to a file or connection. save and load to serialize and restore one or more named objects. The ‘R Internals’ manual for details of the format used.