Description Usage Arguments Details Note Examples
Caches a function's outputs to avoid repeated computation.
By default, the cache is saved to the working directory,
within the sub-directory /.cache
.
In-memory caches are also supported,
by passing an memory-cache object (as created by cache_memory()
)
to the argument .cache_memory
.
1 2 |
body |
(R code) The body of the function to memoise,
typically wrapped in curly braces ( |
.cache |
(Logical scalar)
Whether or not to use cache on the current call.
If |
.cache_ignore |
(Character scalar) By default, all function arguments beginning with '.cache' are ignored for caching purposes; these variables are assumed not to affect function outputs. Additional arguments to ignore can be specified with this parameter. |
.cache_memory |
(Logical scalar)
Either |
.cache_dir |
(Character scalar)
Directory in which to save cached files.
If |
.cache_force |
(Logical scalar)
If |
Unlike most existing memoisation packages,
cache
is well-suited for memoising functions within R packages.
Its default arguments are chosen so that, in most cases,
a function can be cached simply by wrapping its body in a call to
cache()
.
cache()
should be used as a wrapper for the function's body.
The code within the body will be memoised.
It is possible to add additional code before the call to cache()
;
such code is typically used to preprocess the function arguments
to make memoisation more efficient.
For example, if one of the inputs is a vector representing an unordered set,
it might be sensible to sort this vector before making the call to cache()
.
Caching in the cache
package does not check for changes
in the code of the memoised function.
It is the user's responsibility to clear the cache after
updating the source code.
1 2 3 4 5 6 7 8 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.