save
Save Objects

Description

Writes the representation of objects to a file or connection.

Usage

save(..., list = character(0L), 
    file = stop("'file' must be specified"), 
    ascii = FALSE, version = NULL, envir = parent.frame(), 
    compress = !ascii, compression_level, eval.promises = TRUE, 
    precheck = TRUE, RFormat = getOption("saveRFormat")) 
save.image(file = ".TERRData", version = NULL, ascii = FALSE, 
    compress = !ascii, safe = TRUE, RFormat = getOption("saveRFormat"))

Arguments

... the objects to save. An object can be either a symbol or a character string.
list a character string vector of object names to save.
file a character string containing the file name or an opened connection object where data is saved.
ascii a logical flag. If TRUE, the data is written in ASCII format. If FALSE (the default), the data is written in binary format.
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_SAVE_VERSION to "2".
envir an environment where the objects are searched and saved.
compress a logical flag or a character string specifying if the file is compressed. This argument is ignored if version is 1 or if file is a connection.
  • If TRUE, then "gzip" compression is used.
  • If specified as a character string, then it can be "bzip2", "xz", or "gzip", representing the bzip2, xz, and gzip compression algorithms, respectively.
compression_level the compression level to use. The defaults are:
Algorithm Level
bzip2 9
xz 9
gzip 6
eval.promises a logical flag. If TRUE (the default), the evaluation of promises closure is forced.
precheck a logical flag. If TRUE (the default), the existence of objects is checked before they are saved. Currently, only precheck=TRUE is supported.
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.
safe a logical flag. If TRUE (the default), a safe way of saving an image file is used. That is, a temporary file is created as an output file, and then it is renamed to the specified file name after the save succeeds. The safe flag avoids damaging an existing file if the save fails.

Details

save writes the representation of specified objects, with other options, to a file or connection. The objects stored in the specified file or connection can be reloaded with load function later. Compression is supported when saving objects.
save.image is just another quick and convenient way to save the current workspace to a specified file. (The default is ".TERRData".) save.image calls save internally.
The save and save.image functions support 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
returns nothing. (These functions just create or update invisibly the specified file or connection.)
Differences between Spotfire Enterprise Runtime for R and Open-source R
See Also
load, data, dput, dump, serialize, readRDS
Examples
# Example to save to a file.
rm(list = ls())  
x <- runif(10)
y <- rnorm(10)
z <- lm(y~x)
a <- matrix(1:12, nrow = 3)
save(list = ls(), file = "test.data", compress = "bzip2")
# same as: save(x, y, z, a, file = "test.data", compress = "bzip2")
save.image("testimage.TERRData")
rm(list = ls())  
load("test.data")
ls()
rm(list = ls())  
unlink("test.data")
load("testimage.TERRData")
ls()
rm(list = ls())

# save objects from another environment my_env <- new.env() assign("x.new.env", runif(5), envir = my_env) assign("y.new.env", rnorm(5), envir = my_env) assign("z.new.env", lm(my_env$y.new.env~my_env$x.new.env), envir = my_env) ls(envir = my_env) save(file = "test.data", envir = my_env) rm(envir = my_env) load("test.data", envir = my_env) ls(envir = my_env) unlink("test.data")

# Example to save to a connection rm(list = ls()) x <- runif(10) y <- rnorm(10) z <- lm(y~x) a <- matrix(1:12, nrow = 3) file.create("test.data") con <- file("test.data", "wb") save(list = c('x','y','z','a'), file = con) close(con) rm(list = ls()) con <- file("test.data", "rb") load(con) ls() close(con) unlink("test.data")

Package base version 6.1.1-7
Package Index