| qs_cache | R Documentation |
Helper function for caching objects for long running tasks
qs_cache(
expr,
name,
envir = parent.frame(),
cache_dir = ".cache",
clear = FALSE,
prompt = TRUE,
qs_save_params = list(),
qs_read_params = list(),
verbose = TRUE
)
expr |
The expression to evaluate. |
name |
The cached expression name (see details). |
envir |
The environment to evaluate |
cache_dir |
The directory to store cached files in. |
clear |
Set to |
prompt |
Whether to prompt before clearing. |
qs_save_params |
List of parameters passed on to |
qs_read_params |
List of parameters passed on to |
verbose |
Boolean. If |
This is a (very) simple helper function to cache results of long running calculations. There are other packages specializing in caching data that are more feature complete.
The evaluated expression is saved with qs_save() in <cache_dir>/<name>.qs2.
If the file already exists instead, the expression is not evaluated and the cached result is read using qs_read() and returned.
To clear a cached result, you can manually delete the associated .qs2 file, or you can call qs_cache() with clear = TRUE.
If prompt is also TRUE a prompt will be given asking you to confirm deletion.
If name is not specified, all cached results in cache_dir will be removed.
cache_dir <- tempdir()
a <- 1
b <- 5
# not cached
result <- qs_cache({a + b},
name="aplusb",
cache_dir = cache_dir,
qs_save_params = list(compress_level = 5))
# cached
result <- qs_cache({a + b},
name="aplusb",
cache_dir = cache_dir,
qs_save_params = list(compress_level = 5))
# clear cached result
qs_cache(name="aplusb", clear=TRUE, prompt=FALSE, cache_dir = cache_dir)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.