Cache the result of code
in an RDS file.
Arguments
- code
Code to run. Do not forget to wrap it with
{ }
. Also, beware that it is your job to make sure your code and data has not changed. If this is the case, you need to remove thefile
storing the outdated result.- file
File path where the result is stored. Should have extension
rds
.- timing
Whether to print timing of running code? Default is
TRUE
.
Examples
# Prepare some temporary file
tmp <- tempfile(fileext = ".rds")
# Run once because result does not exist yet
save_run({
Sys.sleep(2)
1
}, file = tmp)
#> user system elapsed
#> 0.00 0.00 2.04
#> [1] 1
# Skip run because the result already exists
# (but still output how long it took the first time)
save_run({
Sys.sleep(2)
1
}, file = tmp)
#> user system elapsed
#> 0.00 0.00 2.04
#> [1] 1