This function stores the cache_dir path on your local machine and loads it
for future sessions. Use gb_detect_cache_dir() to find the cache directory
path.
Arguments
- cache_dir
A path to a cache directory. If missing, the function will store the cache files in a temporary directory (see
base::tempdir()).- overwrite
Logical. If
TRUE, overwrite an existingcache_dir.- install
Logical. If
TRUE, install the cache path on your local machine for use in future sessions. Defaults toFALSE. Ifcache_diris missing or empty, this parameter is set toFALSEautomatically.- quiet
Logical. If
TRUE, suppress informational messages.
Details
By default, when no cache_dir is set the package uses a folder inside
base::tempdir(), so files are temporary and are removed when the R
session ends. To persist a cache across R sessions, use
gb_set_cache_dir(path, install = TRUE), which writes the chosen path to a
small configuration file under tools::R_user_dir("geobounds", "config").
Caching strategies
For occasional use, rely on the default
tempdir()-based cache with no installation.Modify the cache for a single session with
gb_set_cache_dir(cache_dir = "a/path/here").For reproducible workflows, install a persistent cache that is kept across R sessions with
gb_set_cache_dir(cache_dir = "a/path/here", install = TRUE).To cache specific files, use the
cache_dirargument in the corresponding function. Seegb_get().
See also
Other cache utilities:
gb_clear_cache(),
gb_detect_cache_dir()
Examples
# Caution! This may modify your current state.
# \dontrun{
my_cache <- gb_detect_cache_dir()
#> ℹ /tmp/RtmplLi8Ac/geobounds
# Set an example cache.
ex <- file.path(tempdir(), "example", "cachenew")
gb_set_cache_dir(ex)
#> ✔ geobounds cache directory is /tmp/RtmplLi8Ac/example/cachenew.
#> ℹ To install your `cache_dir` path for use in future sessions run this function with `install = TRUE`.
gb_detect_cache_dir()
#> ℹ /tmp/RtmplLi8Ac/example/cachenew
#> [1] "/tmp/RtmplLi8Ac/example/cachenew"
# Restore the initial cache.
gb_set_cache_dir(my_cache)
#> ✔ geobounds cache directory is /tmp/RtmplLi8Ac/geobounds.
#> ℹ To install your `cache_dir` path for use in future sessions run this function with `install = TRUE`.
identical(my_cache, gb_detect_cache_dir())
#> ℹ /tmp/RtmplLi8Ac/geobounds
#> [1] TRUE
# }
gb_detect_cache_dir()
#> ℹ /tmp/RtmplLi8Ac/geobounds
#> [1] "/tmp/RtmplLi8Ac/geobounds"
