Title: | Cache and Retrieve Computation Results |
---|---|
Description: | Easily cache and retrieve computation results. The package works seamlessly across interactive R sessions, R scripts and Rmarkdown documents. |
Authors: | Olivier Binette [aut, cre] |
Maintainer: | Olivier Binette <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.3 |
Built: | 2024-11-23 03:00:34 UTC |
Source: | https://github.com/olivierbinette/cache |
Cache or retrieve an evaluated expression. Results are always made available in the current environment.
cache(..., .cachedir = here(".cache-R"), .rerun = FALSE)
cache(..., .cachedir = here(".cache-R"), .rerun = FALSE)
... |
Named expressions to be cached or retrieved. |
.cachedir |
Directory where cache files are stored. Default is a directory called |
.rerun |
Whether or not to clear the cache and re-run the provided expressions. Defaults to FALSE. |
tmp <- tempdir() # Takes 1 second to execute cache(a = { Sys.sleep(1) "Hello World" }, .cachedir = tmp) # Executes instantly cache(a = { Sys.sleep(1) "Hello World" }, .cachedir = tmp) # Result is available in the current environment print(a) # Re-run the expression cache(a = { Sys.sleep(1) "Hello World" }, .cachedir = tmp, .rerun = TRUE)
tmp <- tempdir() # Takes 1 second to execute cache(a = { Sys.sleep(1) "Hello World" }, .cachedir = tmp) # Executes instantly cache(a = { Sys.sleep(1) "Hello World" }, .cachedir = tmp) # Result is available in the current environment print(a) # Re-run the expression cache(a = { Sys.sleep(1) "Hello World" }, .cachedir = tmp, .rerun = TRUE)
Load cached objects from cache directory
cache_load(objnames = "*", .cachedir = here(".cache-R"))
cache_load(objnames = "*", .cachedir = here(".cache-R"))
objnames |
character list of object names to load. |
.cachedir |
path to cache directory. Defaults to the directory named |