stash: Stash an object

Description Usage Arguments Value Examples

View source: R/stash.R

Description

Stash an object after the first time is is created and re-load it the next time. If the code that generates the object is changed or any of its dependencies change, the code is re-evaluated and the new object is stashed.

Usage

1
stash(var, code, depends_on = NULL, functional = FALSE, verbose = TRUE)

Arguments

var

A variable to stash (as a string).

code

The code to generate the object to be stashed.

depends_on

A vector of other objects that this one depends on. Changes to these objects will cause the re-running of the code, next time.

functional

If TRUE, return the object rather than setting in the global environment (default FALSE).

verbose

Whether to print action statements (default TRUE).

Value

Returns NULL (invisibly).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# A value that is used to create `rnd_vals`.
x <<- 1e6 # The `<<-` is not normally required, just for this example.

# Stash the results of the comuption of `rnd_vals`.
stash("rnd_vals", depends_on = "x", {
  # Some long running computation.
  rnd_vals <- rnorm(x)
})

# Remove directory for this example - do not do in real use.
unlink(".mustashe", recursive = TRUE)

mustashe documentation built on May 17, 2021, 1:09 a.m.