save_run: Cache result

Description Usage Arguments Value Examples

View source: R/save-run.R

Description

Cache result

Usage

1
save_run(code, file, timing = TRUE)

Arguments

code

Code to run. Do not forget to wrap it with { }.

file

File path where the result is stored. Should have extension rds.

timing

Whether to print timing of running code? Default is TRUE.

Value

The evaluation of code the first time, the content of file otherwise.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Prepare some temporary file
tmp <- tempfile(fileext = ".rds")

# Run once because result does not exist yet
save_run({
  Sys.sleep(2)
  1
}, file = tmp)

# Skip run because result exists
save_run({
  Sys.sleep(2)
  1
}, file = tmp)

runonce documentation built on July 27, 2020, 5:07 p.m.