Save R Objects to a File and Reload Saved Datasets
Mar 31, 2008save()函数把R对象(列表、矩阵、数据框等等)保存到指定文件中
save.image()函数把R的当前工作空间保存到指定文件,等价于退出R的命令q(“yes”)
用法 save(…, list = character(0), file = stop(“‘file’ must be specified”), ascii = FALSE, version = NULL, envir = parent.frame(), compress = !ascii, eval.promises = TRUE)
save.image(file = “.RData”, version = NULL, ascii = FALSE, compress = !ascii, safe = TRUE)
举例 x <- stats::runif(20) y <- list(a = 1, b = TRUE, c = “oops”) save(x, y, file = “xy.Rdata”) save.image() unlink(“xy.Rdata”) unlink(“.RData”)
set save defaults using option:
options(save.defaults=list(ascii=TRUE, safe=FALSE)) save.image() unlink(“.RData”) 更多…
load()函数用来加载保存R对象的文件
用法: load(file, envir = parent.frame())
举例:
save all data
xx <- pi # to ensure there is some data save(list = ls(all=TRUE), file= “all.Rdata”) rm(xx)
restore the saved values to the current environment
local({ load(“all.Rdata”) ls() })
restore the saved values to the user’s workspace
load(“all.Rdata”, .GlobalEnv) unlink(“all.Rdata”) 更多…