Rev 54003 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/base/man/serialize.Rd% Part of the R package, http://www.R-project.org% Copyright 1995-2011 R Core Development Team% Distributed under GPL 2 or later\name{serialize}\alias{serialize}\alias{unserialize}\title{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)}\arguments{\item{object}{\R object to serialize.}\item{connection}{an open \link{connection} or (for \code{serialize})\code{NULL} or (for \code{unserialize}) a raw vector(see \sQuote{Details}).}\item{ascii}{a logical. If \code{TRUE}, an ASCII representation iswritten; otherwise (default except for text-mode connections), abinary one is used.}\item{refhook}{a hook function for handling reference objects.}}\details{The function \code{serialize} writes \code{object} to the specifiedconnection. If \code{connection} is \code{NULL} then \code{object} isserialized to a raw vector, which is returned as the result of\code{serialize}.Sharing of reference objects is preserved within the object but notacross separate calls to \code{serialize}.\code{unserialize} reads an object (as written by \code{serialize})from \code{connection} or a raw vector.The \code{refhook} functions can be used to customize handling ofnon-system reference objects (all external pointers and weakreferences, and all environments other than name space and packageenvironments and \code{.GlobalEnv}). The hook function for\code{serialize} should return a character vector for references itwants to handle; otherwise it should return \code{NULL}. The hook for\code{unserialize} will be called with character vectors supplied to\code{serialize} and should return an appropriate object.For a text-mode connection, the default value of \code{ascii} is setto \code{TRUE}: only ASCII representations can be written to text-modeconnections and attempting to use \code{ascii = FALSE} will throw anerror.The format consists of a single line followed by the data: the firstline contains a single character: \code{X} for binary serializationand \code{A} for ASCII serialization, followed by a new line.}\section{Warning}{These functions are still experimental. Names, interfaces andvalues might change in future versions (and the value of\code{serialize} was changed for \R 2.4.0).A raw vector is limited to \eqn{2^{31} - 1}{2^31 - 1} bytes, but \Robjects can exceed this and their serializations will normally belarger than the objects.}\value{For \code{serialize}, \code{NULL} unless \code{connection = NULL}, whenthe result is returned in a raw vector.For \code{unserialize} an \R object.}\seealso{\code{\link{.saveRDS}} for a more convenient interface to serialize anobject to a file or connection.\code{\link{save}} and \code{\link{load}} to serialize and restore oneor more named objects.The \sQuote{R Internals} manual for details of the format used.}\examples{x <- serialize(list(1,2,3), NULL)unserialize(x)}\keyword{file}\keyword{connection}