Cache the results of a function so that when you call it again with the same arguments it returns the pre-computed value.
If a function is called multiple times with the same input, you can
often speed things up by keeping a cache of known answers that it can
retrieve. This is called memoisation http://en.wikipedia.org/wiki/Memoization.
memoise package provides a simple syntax
mf <- memoise(f)
mf(), a memoised wrapper around
f(). You can clear
, and you can test whether a function is memoised with
is.memoised(mf) # TRUE is.memoised(f) # FALSE
memoise()now signals an error if an already memoised function is used as input (#4, @richierocks).
has_cache()function added which returns a boolean depending on if the given call is cached or not (#10, @dkesh).
memoiseis called. (Otherwise, the old behavior is invoked, with a warning.) (#14, @krlmlr)
is.memoisednow checks if the argument is a function.