Description Usage Arguments Details Value Author(s) See Also Examples
This function accepts a piece of R code and performs state (input variable value) dependent cached evaluation of it.
1 2 3 4 5 6 7 | evalWithCache(code, env = parent.frame(),
cache = cachingEngine(write_on_cache = TRUE), codeInfo = NULL,
inputVars = NULL, outputVars = NULL, eval_fun = cache$eval_fun,
return_handler = cache$return_handler, force = FALSE, cacheRand = FALSE,
verbose = FALSE, gexts = "png", gdev = sapply(gexts, function(nm)
get(nm, mode = "function")), last = TRUE, stopMissingInput = FALSE,
singleEntFun = sameOutVar, unCacheable = mustForce, ...)
|
code |
The code to evaluate |
env |
The environment in which to evaluate the code or load the cached outputs |
cache |
The CachingEngine to use when evaluating the code. Defaults to an engine which writes caches out immediately, mimicing caching behavior of other systems. See note. |
codeInfo |
A ScriptNodeInfo object, defaults to the result of
calling |
inputVars |
A vector of variable names which are inputs to the code block. Overrides automatically detected inputs |
outputVars |
A vector of variable name which are outputs generated by the code block. Overrides automatically detected outputs |
eval_fun |
A function to perform evaluation of the
code. Defaults to the code evaluator associated with
|
return_handler |
A function to be called on the value returned
by evaluating the code (or loading from cache). Defaults to
return handler associated with |
force |
A logical indicating whether to force a cache
refresh. If |
cacheRand |
A logical indicating whether to create/use caches for expressions with a detected random component. Defaults to FALSE |
verbose |
Should extra informative messages be
emitted. Defaults to |
gexts |
A vector of graphics file extensions for caching graphics |
gdev |
A vector of graphics devices to use to generate the
files indicated by |
last |
logical. Is this the last expression in the codeblock being evaluated. Passed to return handler. Generally this should not be manually set. |
stopMissingInput |
Should an error be thrown when an input
variable is not present in the evaluation scope. If
|
singleEntFun |
A function, or NULL. If a function, it is
called on |
unCacheable |
A function which accepts a ScriptNodeInfo object
and returns a logical value indicating whether the computation
is cacheable. Defaults to |
... |
Passed to |
This function performs state-aware cached evaluation of R code. This means that a cache is considered to apply if and only if both the code (after parsing) and the values of any variables used as inputs to the code are identical to those present when the cache was created.
Cached evaluation is done via a caching engine (CachingEngine object), which has a set of caches it already knows about, the ability to create new caches, and a set of behaviors for when - if ever - a cache should be written to disk, an evaluator function which evaluates the code, and a return handler which processes the object returned from the evaluator or loaded from a matching cache.
The evaluator function is charged with evaluating code and capturing any side-effects of the code that the user wishes to cache and recreate, encoding them in the object it returns. The return handler is tasked with processing that return value, recreating any side effects (including plots, messages printed to the console, etc) and then returning the raw result of the evaluation.
The value generated by cache$return_handler
when
called on the value returned by evaluating code
using
cache$eval_fun
.
In other words, the value
1 2 | cache$return_handler(cache$eval_fun(code, env, ...))
|
is returned, though if a valid cache is found,
cache$eval_fun
is not called and the cached return value (of the
evaluator function at the time of caching) is
passed to cache$return_handler
.
The return value of cache$return_handler
is returned
invisibly. The cache$return_handler
function itself is
responsible for the duplication of any side effects, including any
printing of errors, warnings, or messages as well as any necessary
regeneration of graphical output.
Gabriel Becker
1 2 3 4 | ## Not run:
res = evalWithCache("x = 5; y = x+7;y")
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.