| serialize {base} | R Documentation |
Simple Serialization Interface
Description
A simple low level interface for serializing to connections.
Usage
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)
Arguments
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 |
ascii |
a logical. If |
version |
the workspace format version to use. |
compress |
a logical specifying whether saving to a named file is
to use compression. Ignored when |
connection |
an open connection. |
refhook |
a hook function for handling reference objects. |
Details
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 from connection.
connection may also be a scalar string.
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.
Value
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.
Warning
These functions are still experimental. Both names, interfaces and
values might change in future versions. .saveRDS and
.readRDS are intended for internal use.
Examples
x <- serialize(list(1,2,3), NULL)
unserialize(x)