### Warning: this example will generate a temporary .Rds
### file in your temp folder, and will then delete it
library(isotree)
set.seed(1)
X <- matrix(rnorm(100), nrow = 20)
iso <- isolation.forest(X, ntrees=10, nthreads=1)
temp_file <- file.path(tempdir(), "iso.Rds")
saveRDS(iso, temp_file)
iso2 <- readRDS(temp_file)
file.remove(temp_file)
cat("Model pointer after loading is this: \n")
print(iso2$cpp_obj$ptr)
### now unpack it
isotree.restore.handle(iso2)
cat("Model pointer after unpacking is this: \n")
print(iso2$cpp_obj$ptr)
Run the code above in your browser using DataLab