run.cache: Run function and save cache

Description Usage Arguments Value Examples

Description

This method saves the function that's being called

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# [optional] save cache in a temporary directory
# otherwise it writes to the current directory
# to folder named run-cache
base.dir(tempdir())
#
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)

loose.rock documentation built on April 30, 2021, 1:06 a.m.