serialize {IsoriX} | R Documentation |
Save and read objects produced by IsoriX using RDS files
Description
Because files created with IsoriX contain terra::SpatRaster
and
terra::SpatVector
objects, they cannot be saved using base::saveRDS
or base::save
functions. The reason is that objects created with terra
point to data stored in memory which are not contained in the R objects
themselves. Adapting the approach implemented in the terra package, we
provide a wrapper for base::saveRDS
and base::readRDS
functions,
which allows one to save and read objects produced with IsoriX by simply
using saveRDS()
and readRDS()
.
Usage
saveRDS_IsoriX(
object,
file = "",
ascii = FALSE,
version = NULL,
compress = TRUE,
refhook = NULL
)
## S3 method for class 'ISOSCAPE'
saveRDS(
object,
file = "",
ascii = FALSE,
version = NULL,
compress = TRUE,
refhook = NULL
)
## S3 method for class 'CALIBFIT'
saveRDS(
object,
file = "",
ascii = FALSE,
version = NULL,
compress = TRUE,
refhook = NULL
)
## S3 method for class 'ISOFIND'
saveRDS(
object,
file = "",
ascii = FALSE,
version = NULL,
compress = TRUE,
refhook = NULL
)
## S3 method for class 'character'
readRDS(file, refhook = NULL)
## S4 method for signature 'ISOSCAPE'
saveRDS(
object,
file = "",
ascii = FALSE,
version = NULL,
compress = TRUE,
refhook = NULL
)
## S4 method for signature 'CALIBFIT'
saveRDS(
object,
file = "",
ascii = FALSE,
version = NULL,
compress = TRUE,
refhook = NULL
)
## S4 method for signature 'ISOFIND'
saveRDS(
object,
file = "",
ascii = FALSE,
version = NULL,
compress = TRUE,
refhook = NULL
)
## S4 method for signature 'character'
readRDS(file, refhook = NULL)
Arguments
object |
(definition copied from |
file |
(definition copied from |
ascii |
(definition copied from |
version |
(definition copied from |
compress |
(definition copied from |
refhook |
(definition copied from |
Details
base::saveRDS
and base::readRDS
are standard S3 functions. So in
order to be able to have a specific behaviour for objects produced with
IsoriX, we imported saveRDS
and readRDS
S4 generics from terra to
dispatch both S3 and S4 IsoriX-specific methods (see Methods_for_S3). The
S3 implementation is consistent with the rest of the package and presents all
usual benefits associated with S3 methods (e.g. simple access to the code).
The S4 implementation makes IsoriX methods compatible with the use of
terra::saveRDS
and terra::readRDS
.
Value
For saveRDS
, NULL
invisibly.
For readRDS
, an R object.
Functions
-
saveRDS_IsoriX()
: S3 function to save IsoriX objects into a RDS file -
saveRDS(ISOSCAPE)
: S3 method to save anISOSCAPE
object into a RDS file -
saveRDS(CALIBFIT)
: S3 method to save aCALIBFIT
object into a RDS file -
saveRDS(ISOFIND)
: S3 method to save anISOFIND
object into a RDS file -
readRDS(character)
: S3 method to read an object produced with IsoriX (or other) stored in a RDS file -
saveRDS(ISOSCAPE)
: S4 method to save anISOSCAPE
object into a RDS file -
saveRDS(CALIBFIT)
: S4 method to save anCALIBFIT
object into a RDS file -
saveRDS(ISOFIND)
: S4 method to save anISOFIND
object into a RDS file -
readRDS(character)
: S4 method to read an object produced with IsoriX (or other) stored in a RDS file
Examples
if (getOption_IsoriX("example_maxtime") > 30) {
## We prepare the data
GNIPDataDEagg <- prepsources(data = GNIPDataDE)
## We fit the models
GermanFit <- isofit(
data = GNIPDataDEagg,
mean_model_fix = list(elev = TRUE, lat_abs = TRUE)
)
## We build the isoscapes
GermanScape <- isoscape(raster = ElevRasterDE, isofit = GermanFit)
## Saving as RDS
filename <- tempfile(fileext = ".rds") # or whatever names you want
saveRDS(GermanScape, file = filename)
## Reading RDS
GermanScape2 <- readRDS(filename)
GermanScape2
}