Tag Archives: save() function

Solving the problem of saving object set by save() function in R language

Solve the save() function in R language to save the collection of objects – & GT; The Art of R programming, P195

>ls()
[1] "j"              "joe"            "k"              "o"              "print.employee" "z"             
> z<-rnorm(100000)
> hz<-hist(z)
> save(hz,"hzfile.RData")
Error in save(hz, "hzfile.RData") : The target object 'hzfile.Rdata' does not exist.
> save(hz,"hzfile")
Error in save(hz, "hzfile") : The target 'hzfile' does not exist.
> save(hz,file="hzfile.RData")
> ls()
[1] "hz"             "j"              "joe"            "k"              "o"              "print.employee" "z"             
> rm(hz)
> ls()
[1] "j"              "joe"            "k"              "o"              "print.employee" "z"             
> load("hzfile")
Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection
In addition: Warning message:
In readChar(con, 5L, useBytes = TRUE) :
  cannot open compressed file 'hzfile', probable reason 'No such file or directory'
> load("hzfile.RData")
> ls()
[1] "hz"             "j"              "joe"            "k"              "o"              "print.employee" "z"             

As shown below:


When you use save(), you use the “file” parameter, and the suffix of the file is “.rdata “. If you use load(), the suffix of the file is “.rdata”