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 the serialization format version to use. If RFormat is FALSE, this must be NULL. If RFormat is TRUE, version may also be 2 or 3. If RFormat is TRUE and version is NULL, the version defaults to 3. This default can be changed by setting the environment variable R_DEFAULT_SERIALIZE_VERSION to "2".
refhook a hook function to handle reference objects.
RFormat a logical flag. If TRUE, the R compatible RData format is used. If FALSE, the Spotfire Enterprise Runtime for R specific SData format is used. See below.

Details

The serialize function supports the RData and (Spotfire Enterprise Runtime for R specific) SData formats. R can load most files saved from Spotfire Enterprise Runtime for R with RFormat=TRUE with a few exceptions. If the file contains complicated model objects such as a glm model, the load might fail or the model might be corrupt. This is because the model contains references to implementation-specific functions which are different between Spotfire Enterprise Runtime for R and R. Some non-trivial environments might also cause problems.
Value
serializereturns NULL if connection is not NULL, or returns a raw vector if connection is NULL.
unserializereturns an object.
Differences between Spotfire Enterprise Runtime for R and Open-source R
The RFormat argument is Spotfire 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 6.1.1-7
Package Index