This generic and some methods will do whatever is required to prepare an object for
saving to disk (or RAM) via e.g., saveRDS. Some objects (e.g., terra's Spat*)
cannot be saved without first wrapping them. Also, file-backed objects are similar.
.wrap(
obj,
cachePath = getOption("reproducible.cachePath"),
preDigest,
drv = getDrv(getOption("reproducible.drv", NULL)),
conn = getOption("reproducible.conn", NULL),
verbose = getOption("reproducible.verbose"),
outputObjects = NULL,
cacheId = NULL,
...
)# S3 method for list
.wrap(
obj,
cachePath = getOption("reproducible.cachePath"),
preDigest,
drv = getDrv(getOption("reproducible.drv", NULL)),
conn = getOption("reproducible.conn", NULL),
verbose = getOption("reproducible.verbose"),
outputObjects = NULL,
cacheId = NULL,
...
)
# S3 method for environment
.wrap(
obj,
cachePath = getOption("reproducible.cachePath"),
preDigest,
drv = getDrv(getOption("reproducible.drv", NULL)),
conn = getOption("reproducible.conn", NULL),
verbose = getOption("reproducible.verbose"),
outputObjects = NULL,
cacheId = NULL,
...
)
# S3 method for default
.wrap(
obj,
cachePath = getOption("reproducible.cachePath"),
preDigest,
drv = getDrv(getOption("reproducible.drv", NULL)),
conn = getOption("reproducible.conn", NULL),
verbose = getOption("reproducible.verbose"),
outputObjects = NULL,
cacheId = NULL,
...
)
# S3 method for default
.unwrap(
obj,
cachePath = getOption("reproducible.cachePath"),
cacheId = NULL,
drv = getDrv(getOption("reproducible.drv", NULL)),
conn = getOption("reproducible.conn", NULL),
...
)
.unwrap(
obj,
cachePath = getOption("reproducible.cachePath"),
cacheId = NULL,
drv = getDrv(getOption("reproducible.drv", NULL)),
conn = getOption("reproducible.conn", NULL),
...
)
# S3 method for environment
.unwrap(
obj,
cachePath = getOption("reproducible.cachePath"),
cacheId = NULL,
drv = getDrv(getOption("reproducible.drv", NULL)),
conn = getOption("reproducible.conn", NULL),
...
)
# S3 method for list
.unwrap(
obj,
cachePath = getOption("reproducible.cachePath"),
cacheId = NULL,
drv = getDrv(getOption("reproducible.drv", NULL)),
conn = getOption("reproducible.conn", NULL),
...
)
# S3 method for PackedSpatExtent2
.unwrap(
obj,
cachePath = getOption("reproducible.cachePath"),
cacheId = NULL,
drv = getDrv(getOption("reproducible.drv", NULL)),
conn = getOption("reproducible.conn", NULL),
...
)
# S3 method for PackedSpatVector2
.unwrap(
obj,
cachePath = getOption("reproducible.cachePath"),
cacheId = NULL,
drv = getDrv(getOption("reproducible.drv", NULL)),
conn = getOption("reproducible.conn", NULL),
...
)
# S3 method for data.table
.unwrap(
obj,
cachePath = getOption("reproducible.cachePath"),
cacheId = NULL,
drv = getDrv(getOption("reproducible.drv", NULL)),
conn = getOption("reproducible.conn", NULL),
...
)
# S3 method for PackedSpatVector
.unwrap(
obj,
cachePath = getOption("reproducible.cachePath"),
cacheId = NULL,
drv = getDrv(getOption("reproducible.drv", NULL)),
conn = getOption("reproducible.conn", NULL),
...
)
Returns an object that can be saved to disk e.g., via saveRDS.
Any arbitrary R object.
A repository used for storing cached objects.
This is optional if Cache is used inside a SpaDES module.
The list of preDigest that comes from CacheDigest of an object
If using a database backend, drv must be an object that
inherits from DBIDriver (e.g., RSQLite::SQLite).
an optional DBIConnection object, as returned by dbConnect().
Numeric, -1 silent (where possible), 0 being very quiet,
1 showing more messaging, 2 being more messaging, etc.
Default is 1. Above 3 will output much more information about the internals of
Caching, which may help diagnose Caching challenges. Can set globally with an
option, e.g., options('reproducible.verbose' = 0) to reduce to minimal
Optional character vector indicating which objects to return. This is only relevant for list, environment (or similar) objects
Used strictly for messaging. This should be the cacheId of the object being recovered.
Default is NULL.
Arguments passed to methods; default does not use anything in ....
# For SpatExtent
if (requireNamespace("terra")) {
ex <- terra::ext(c(0, 2, 0, 3))
exWrapped <- .wrap(ex)
ex1 <- .unwrap(exWrapped)
}
Run the code above in your browser using DataLab