Configures the cache directory used by CatastRoNav. Use
Sys.getenv("CATASTRONAV_CACHE_DIR") or
catrnav_detect_cache_dir() to inspect the current path.
Usage
catrnav_set_cache_dir(
cache_dir = NULL,
overwrite = FALSE,
install = FALSE,
verbose = TRUE
)
catrnav_detect_cache_dir()Arguments
- cache_dir
Path to a cache directory. On
NULL, the function stores cached files in a temporary directory (seebase::tempdir()).- overwrite
A logical value indicating whether to overwrite an existing
CATASTRONAV_CACHE_DIRvalue.- install
Logical. If
TRUE, installs the key on your local machine for use in future sessions. Defaults toFALSE. Ifcache_dirisFALSE, this argument is set toFALSEautomatically.- verbose
Logical. If
TRUE, displays informational messages.
Value
catrnav_set_cache_dir() invisibly returns the cache path as a character
string. It is primarily called for its side effect.
catrnav_detect_cache_dir() returns the cache path used in the current
session.
Details
By default, when no cache_dir is set, CatastRoNav uses a directory
inside base::tempdir(). Files in this directory are temporary and are
removed when the R session ends. To persist a cache across R sessions, use
catrnav_set_cache_dir(cache_dir, install = TRUE). This writes the chosen
path to a configuration file under
tools::R_user_dir("CatastRoNav", "config").
Note
The configuration location has moved from
rappdirs::user_config_dir("CatastRoNav", "R") to
tools::R_user_dir("CatastRoNav", "config"). Existing configuration files
are migrated automatically. A migration message is shown only once.
Caching strategies
Source files are cached after download. CatastRoNav implements the following caching options:
For occasional use, rely on the default
tempdir()-based cache without installing a persistent path.Modify the cache for a single session by setting
catrnav_set_cache_dir(cache_dir = "a/path/here").For reproducible workflows, install a persistent cache with
catrnav_set_cache_dir(cache_dir = "a/path/here", install = TRUE). This cache is kept across R sessions.To cache specific files elsewhere, use the
cache_dirargument in the corresponding function.
Cached files can occasionally become corrupt. In that case, download the
data again by setting update_cache = TRUE in the corresponding function.
If a download fails, use verbose = TRUE to inspect the request and
catrnav_detect_cache_dir() to identify the active cache path.
See also
Manage the local cache:
catrnav_clear_cache()
Examples
# Caution! This modifies your current state.
# \dontrun{
my_cache <- catrnav_detect_cache_dir()
#> ℹ /tmp/RtmpqpGbxS/CatastRoNav
example_cache <- file.path(tempdir(), "example", "cache")
catrnav_set_cache_dir(example_cache)
#> ℹ CatastRoNav cache directory is /tmp/RtmpqpGbxS/example/cache.
#> ℹ To reuse this cache directory in future sessions, set `install` to `TRUE`.
catrnav_detect_cache_dir()
#> ℹ /tmp/RtmpqpGbxS/example/cache
#> [1] "/tmp/RtmpqpGbxS/example/cache"
# Restore the initial cache.
catrnav_set_cache_dir(my_cache)
#> ℹ CatastRoNav cache directory is /tmp/RtmpqpGbxS/CatastRoNav.
#> ℹ To reuse this cache directory in future sessions, set `install` to `TRUE`.
identical(my_cache, catrnav_detect_cache_dir())
#> ℹ /tmp/RtmpqpGbxS/CatastRoNav
#> [1] TRUE
# }
catrnav_detect_cache_dir()
#> ℹ /tmp/RtmpqpGbxS/CatastRoNav
#> [1] "/tmp/RtmpqpGbxS/CatastRoNav"
