This function stores your cache_dir path on your local machine and
loads it for future sessions. Type gb_detect_cache_dir() to find
your 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 this is set to
TRUE, it will overwrite an existingcache_dir.- install
Logical. If
TRUE, will install the key in your local machine for use in future sessions. Defaults toFALSE. Ifcache_dirisFALSEthis parameter is set toFALSEautomatically.- quiet
logical. If
TRUEsuppresses informational messages.
Value
An (invisible()) character with the path to your cache_dir.
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 (no install).Modify the cache for a single session by setting
gb_set_cache_dir(cache_dir = "a/path/here").For reproducible workflows, install a persistent cache with
gb_set_cache_dir(cache_dir = "a/path/here", install = TRUE)that will be kept across R sessions.For caching 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()
#> ℹ C:\Users\RUNNER~1\AppData\Local\Temp\RtmpaMSHV8/geobounds
# Set an example cache
ex <- file.path(tempdir(), "example", "cachenew")
gb_set_cache_dir(ex)
#> ✔ geobounds cache dir is C:\Users\RUNNER~1\AppData\Local\Temp\RtmpaMSHV8/example/cachenew.
#> ℹ To install your `cache_dir` path for use in future sessions run this function with `install = TRUE`.
gb_detect_cache_dir()
#> ℹ C:\Users\RUNNER~1\AppData\Local\Temp\RtmpaMSHV8/example/cachenew
#> [1] "C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\RtmpaMSHV8/example/cachenew"
# Restore initial cache
gb_set_cache_dir(my_cache)
#> ✔ geobounds cache dir is C:\Users\RUNNER~1\AppData\Local\Temp\RtmpaMSHV8/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())
#> ℹ C:\Users\RUNNER~1\AppData\Local\Temp\RtmpaMSHV8/geobounds
#> [1] TRUE
# }
gb_detect_cache_dir()
#> ℹ C:\Users\RUNNER~1\AppData\Local\Temp\RtmpaMSHV8/geobounds
#> [1] "C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\RtmpaMSHV8/geobounds"
