Sets the active cache directory and optionally saves it for future sessions.
Use gb_detect_cache_dir() to find the active cache directory.
Arguments
- cache_dir
A path to a cache directory. If
NULL, the function stores cached archives in a temporary directory. Seebase::tempdir().- overwrite
A logical value. If
TRUE, replace a cache directory already saved in the configuration file.- install
A logical value. If
TRUE, save the cache directory for use in future sessions. Defaults toFALSE. Ifcache_dirisNULL, this parameter is set toFALSEautomatically.- quiet
A logical value. If
TRUE, suppress informational messages.
Details
By default, when no cache_dir is set, geobounds uses a directory
inside base::tempdir(). Cached archives in this directory are removed when
the R session ends. To reuse a cache directory across R sessions, use
gb_set_cache_dir(cache_dir = "a/path/here", install = TRUE). This saves the
directory in a configuration file under
tools::R_user_dir("geobounds", "config").
Cache strategies
For occasional use, use the default temporary cache directory.
Set the cache directory for the current session with
gb_set_cache_dir(cache_dir = "a/path/here").Save a persistent cache directory for future R sessions with
gb_set_cache_dir(cache_dir = "a/path/here", install = TRUE).Set the cache directory for an individual download with the
cache_dirargument. Seegb_get().
See also
tools::R_user_dir() identifies standard locations for
user-specific files.
Cache management functions:
gb_clear_cache(),
gb_detect_cache_dir()
Examples
# Caution: this may modify your current state.
# \dontrun{
my_cache <- gb_detect_cache_dir()
#> ℹ /tmp/RtmpMujlMf/geobounds
# Set an example cache directory.
ex <- file.path(tempdir(), "example", "cachenew")
gb_set_cache_dir(ex)
#> ✔ geobounds cache directory is /tmp/RtmpMujlMf/example/cachenew.
#> ℹ To use this cache directory in future sessions, call `gb_set_cache_dir()` with `install = TRUE`.
gb_detect_cache_dir()
#> ℹ /tmp/RtmpMujlMf/example/cachenew
#> [1] "/tmp/RtmpMujlMf/example/cachenew"
# Restore the initial cache.
gb_set_cache_dir(my_cache)
#> ✔ geobounds cache directory is /tmp/RtmpMujlMf/geobounds.
#> ℹ To use this cache directory in future sessions, call `gb_set_cache_dir()` with `install = TRUE`.
identical(my_cache, gb_detect_cache_dir())
#> ℹ /tmp/RtmpMujlMf/geobounds
#> [1] TRUE
# }
gb_detect_cache_dir()
#> ℹ /tmp/RtmpMujlMf/geobounds
#> [1] "/tmp/RtmpMujlMf/geobounds"
