This function can be useful during the development of computationally
intensive workflows, for example in vignettes or scripts. The
function uses a cache file in dir
which defaults to the current
working directory whose name is obtained by paste(prefix, name,
".RData", sep="")
.
When cache
is called and the cache file exists, it is loaded
and the object whose name is given on the left of <-
in
expr
is returned. In this case, expr
is not
evaluted. When cache
is called and the cache file does not exist,
expr
is evaluted, its value is saved into a cache file, and
then its value is returned.
The expr
argument must be of the form of someVar <-
{expressions}
. That is, the left hand side must be a single symbol
name and the next syntactic token must be <-
.
To flush the cache and force recomputation, simply remove the cache
files. You can use file.remove
to do this.