cache: Cache or Retrieve Computation Results

Description Usage Arguments Examples

View source: R/cache.R

Description

Cache or retrieve an evaluated expression. Results are always made available in the current environment.

Usage

1
cache(..., .cachedir = here(".cache-R"), .rerun = FALSE)

Arguments

...

Named expressions to be cached or retrieved.

.cachedir

Directory where cache files are stored. Default is a directory called .cache-R located at the project root.

.rerun

Whether or not to clear the cache and re-run the provided expressions. Defaults to FALSE.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
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)

cache documentation built on July 9, 2021, 9:07 a.m.