load_or_create: Load a file from a cache directory, or create and save it

View source: R/helper-load_or_create.R

load_or_createR Documentation

Load a file from a cache directory, or create and save it

Description

Load a file from a cache directory, or create and save it

Usage

load_or_create(f, name, recreate = FALSE, cache_dir = "cache")

Arguments

f

function to call when the file does not exist.

name

name of cache file (including .rds).

recreate

if TRUE, recreate the file even if it exists.

cache_dir

directory that contains cache files. It is created if it does not exist.

Value

object created by function f, or stored in cache file

Examples

## Not run: 
 load_or_create(function() {
   rnorm(10000)
 }, "rnorm-results.rds", recreate=FALSE, cache_dir="cache")

## End(Not run)

fbreitwieser/pavian documentation built on Sept. 23, 2024, 11:03 p.m.