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"))
... | 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.
| |||||||||
compression_level |
the compression level to use. The defaults are:
| |||||||||
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 TIBCO 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. |
# 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")