Description Usage Arguments Value Examples
Access a list of values separately but calculate them together. This function generalizes grad_share for any number of functions.
1 2 |
func |
Function that returns a list of values |
evalForNewX |
Should the function reevaluate for any new x? Recommended. |
recalculate_indices |
Indices for which the values should be recalculated. Ignored if evalForNewX is true. Use this if you don't want to pass x to dependent functions, or if you know other indices won't need to be recalculated. |
check_all |
Should it check that the accessed values were calculated at the current input? Ignored if evalForNewX is true. Will give a warning but still return the stored value. |
An environment where the function values are calculated.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | tfunc <- function(x) {list(x+1, x+2, x+3, x+4, x+5)}
f <- fngr(tfunc)
f(1)(0)
f(3)(0)
f(3)(1)
f(1)(23.4)
f(4)()
# Use same function but only recalculate when first value is called
g <- fngr(tfunc, evalForNewX = FALSE, recalculate_indices = c(1))
g1 <- g(1)
g3 <- g(3)
g1(1)
g3(1)
g3(11) # This won't be give expected value
g1(11) # This updates all values
g3(11) # This is right
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.