fngr {splitfngr} | R Documentation |
Access a list of values separately but calculate them together. This function generalizes grad_share for any number of functions.
Description
Access a list of values separately but calculate them together. This function generalizes grad_share for any number of functions.
Usage
fngr(func, evalForNewX = TRUE, recalculate_indices = c(),
check_all = FALSE)
Arguments
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. |
Value
An environment where the function values are calculated.
Examples
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
[Package splitfngr version 0.1.2 Index]