| esp_set_cache_dir | R Documentation |
This function stores your cache_dir path on your local machine and loads
it for future sessions. Use Sys.getenv("MAPSPAIN_CACHE_DIR") or
esp_detect_cache_dir() to find the cached path.
esp_set_cache_dir(
cache_dir = NULL,
overwrite = FALSE,
install = FALSE,
verbose = TRUE
)
esp_detect_cache_dir()
cache_dir |
A path to a cache directory. When |
overwrite |
Logical. If |
install |
Logical. If |
verbose |
A logical value indicating whether to display informational messages. |
By default, when no cache_dir is set, the package uses a folder inside
base::tempdir() (files are temporary and removed when the R session
ends). To persist a cache across R sessions, use
esp_set_cache_dir(cache_dir, install = TRUE), which writes the chosen
path to a configuration file under tools::R_user_dir("mapSpain", "config").
esp_set_cache_dir() returns an invisible character string with the path
to your cache_dir. It is primarily called for its side effect.
esp_detect_cache_dir() returns the path to the cache_dir used in the
current session.
Functions that download data store files in cache_dir. When cache_dir
is NULL, they use the active package cache, which defaults to a temporary
directory. Set update_cache = TRUE to replace an existing cached file.
See Caching strategies in esp_set_cache_dir() to configure a
persistent cache.
Some files can be read from their online source without caching using the
option cache = FALSE. Otherwise the source files are downloaded to
your computer. mapSpain implements the following caching options:
For occasional use, rely on the default base::tempdir()-based cache (no
install).
Modify the cache for a single session by setting
esp_set_cache_dir(cache_dir = "a/path/here").
For reproducible workflows, install a persistent cache with
esp_set_cache_dir(cache_dir = "a/path/here", install = TRUE), which
persists across R sessions.
For caching specific files, use the cache_dir argument in the
corresponding function.
Sometimes cached files may be corrupted. In that case, try re-downloading
the data by setting update_cache = TRUE in the corresponding function.
If you experience download problems, try downloading the file by another
method and save it to your cache_dir. Use verbose = TRUE to debug the
API query and esp_detect_cache_dir() to identify your cache path.
In mapSpain >= 1.0.0, the configuration file location has
moved from rappdirs::user_config_dir("mapSpain", "R") to
tools::R_user_dir("mapSpain", "config"). A migration function automatically
transfers previous configuration files from the old to the new location.
A message appears once during this migration.
tools::R_user_dir().
Cache management utilities:
esp_clear_cache()
# Do not run this. It would modify your current state.
## Not run:
my_cache <- esp_detect_cache_dir()
# Set an example cache.
ex <- file.path(tempdir(), "example", "cachenew")
esp_set_cache_dir(ex)
esp_detect_cache_dir()
# Restore the initial cache.
esp_set_cache_dir(my_cache)
identical(my_cache, esp_detect_cache_dir())
## End(Not run)
esp_detect_cache_dir()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.