serialize(object, connection, ascii = FALSE, version = NULL, refhook = NULL, RFormat = getOption("saveRFormat"))unserialize(connection, refhook = NULL)
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. |
serialize | returns NULL if connection is not NULL, or returns a raw vector if connection is NULL. |
unserialize | returns an object. |
# 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