run.cache: Run function and save cache

run.cacheR Documentation

Run function and save cache

Description

This method saves the function that's being called

Usage

run.cache(
  fun,
  ...,
  seed = NULL,
  base.dir = NULL,
  cache.prefix = "generic_cache",
  cache.digest = list(),
  show.message = NULL,
  force.recalc = FALSE,
  add.to.hash = NULL
)

Arguments

fun

function call name

...

parameters for function call

seed

when function call is random, this allows to set seed beforehand

base.dir

directory where data is stored

cache.prefix

prefix for file name to be generated from parameters (...)

cache.digest

cache of the digest for one or more of the parameters

show.message

show message that data is being retrieved from cache

force.recalc

force the recalculation of the values

add.to.hash

something to add to the filename generation

Value

the result of fun(...)

Examples

# [optional] save cache in a temporary directory
#
run.cache(c, 1, 2, 3, 4)
#
# next three should use the same cache
#  note, the middle call should be a little faster as digest is not
#  calculated
#   for the first argument
run.cache(c, 1, 2, 3, 4)
run.cache(c, 1, 2, 3, 4, cache.digest = list(digest.cache(1)))
run.cache(c, a=1, 2, c= 3, 4)
## Not run: 
# Using a local folder
# run.cache(c, 1, 2, 3, 4, base.dir = "runcache")

## End(Not run)

averissimo/loose.rock documentation built on Dec. 8, 2022, 11:53 p.m.