serialize
Simple Serialization Interface

Description

Provides a low-level serialization and unserialization interface for a simple object.

Usage

serialize(object, connection, ascii = FALSE, version = NULL,
    refhook = NULL, RFormat = getOption("saveRFormat"))

unserialize(connection, refhook = NULL)

Arguments

object any object to be serialized.
connection a connection to or from which object is serialized. For serialize, the connection can be NULL. For unserialize, the connection can be a raw vector.
ascii a logical value. If TRUE, the file format is ASCII. If FALSE (the default), the format is binary.
version a version string. Must be NULL or, when RData=TRUE, 2.
refhook a hook function to handle reference objects.
RFormat a logical flag. If TRUE, the R compatible RData format is used. If FALSE, this engine-specific SData fomat is used. See Details for more information.

Details

The serialize and unserialize functions support the RData and (this engine-specific) SData formats. The SData format is tailor-made for this engine; therefore, it is much faster to save and load. Also, it can sometimes produce much smaller file sizes because sequences are stored in a very compact form.
Value
serializereturns NULL if connection is not NULL, or returns a raw vector if connection is NULL.
unserializereturns an object.
Differences between TIBCO Enterprise Runtime for R and Open-source R
The RFormat argument is TIBCO Enterprise Runtime for R-specific.
See Also
readRDS, saveRDS, load, save
Examples
# Connection is linked to a file.
lm.freeny <- lm(y ~ ., data=Sdatasets::freeny)
tfreeny <- tempfile()
freeny.con <- bzfile(tfreeny, "wb")
serialize(lm.freeny, freeny.con)
close(freeny.con)
# Restore with different name.
freeny.con <- bzfile(tfreeny, "rb")
lm.freeny1 <- unserialize(freeny.con)
close(freeny.con)
identical(lm.freeny1, lm.freeny)
## [1] TRUE

# Connection is NULL. list.xyz <- list(x = 1:5, y = paste(1:5), z = letters[1:5]) xyz.raw <- serialize(list.xyz, NULL) list.xyz1 <- unserialize(xyz.raw) identical(list.xyz, list.xyz1) ## [1] TRUE

Package base version 4.0.0-28
Package Index