movedCache {reproducible} | R Documentation |
Deal with moved cache issues
Description
If a user manually copies a complete Cache folder (including the db file and rasters folder), there are issues that must be addressed, depending on the Cache backend used. If using DBI (e.g., RSQLite or Postgres), the db table must be renamed. Run this function after a manual copy of a cache folder. See examples for one way to do that.
Usage
movedCache(
new,
old,
drv = getDrv(getOption("reproducible.drv", NULL)),
conn = getOption("reproducible.conn", NULL),
verbose = getOption("reproducible.verbose")
)
Arguments
new |
Either the path of the new |
old |
Optional, if there is only one table in the |
drv |
if using a database backend, drv must be an object that inherits from DBIDriver e.g., from package RSQLite, e.g., SQLite |
conn |
an optional DBIConnection object, as returned by dbConnect(). |
verbose |
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., |
Details
When the backend database for a reproducinle
cache is an SQL database, the files
on disk cannot be copied manually to a new location because they contain internal
tables. Because reproducible
gives the main table a name based on the cachePath
path, calls to Cache
will attempt to call this internally if it detects a
name mismatch.
Value
movedCache
does not return anything; it is called for its side effects.
Examples
data.table::setDTthreads(2)
tmpdir <- "tmpdir"
tmpCache <- "tmpCache"
tmpCacheDir <- normalizePath(file.path(tempdir(), tmpCache), mustWork = FALSE)
tmpdirPath <- normalizePath(file.path(tempdir(), tmpdir), mustWork = FALSE)
bb <- Cache(rnorm, 1, cachePath = tmpCacheDir)
# Copy all files from tmpCache to tmpdir
froms <- normalizePath(dir(tmpCacheDir, recursive = TRUE, full.names = TRUE),
mustWork = FALSE
)
dir.create(file.path(tmpdirPath, "rasters"), recursive = TRUE, showWarnings = FALSE)
dir.create(file.path(tmpdirPath, "cacheOutputs"), recursive = TRUE, showWarnings = FALSE)
file.copy(
from = froms, overwrite = TRUE,
to = gsub(tmpCache, tmpdir, froms)
)
# Can use 'movedCache' to update the database table, though will generally
# happen automatically, with message indicating so
movedCache(new = tmpdirPath, old = tmpCacheDir)
bb <- Cache(rnorm, 1, cachePath = tmpdirPath) # should recover the previous call