You misunderstand what load
does. It restores an object to the same name it had when you save()
d it. What you are seeing in M
is the return value of the load()
function. Calling load()
has the additional side effect of loading the object back under the same name that it was saved with.
Consider:
require("e1071")
data(iris)
## classification mode
# default with factor response:
model <- svm (Species~., data=iris)
## Save it
save(model, file = "my-svm.RData")
## delete model
rm(model)
## load the model
M <- load("my-svm.RData")
Now look at the workspace
> ls()
[1] "iris" "M" "model"
Hence model
was restored as a side effect of load()
.
From ?load
we see the reason M
contains the name of the objects created (and hence saved originally)
Value:
A character vector of the names of objects created, invisibly.
If you want to restore an object to a new name, use saveRDS()
and readRDS()
:
saveRDS(model, "svm-model.rds")
newModel <- readRDS( "svm-model.rds")
ls()
> ls()
[1] "iris" "M" "model" "newModel"
If you want to know more about saveRDS()
and readRDS()
see the relevant help ?saveRDS()
and you might be interested in a blog post I wrote on this topic.