r - Generate a list of functions from a closure -
power <- function(exp) { function(x) { x ^ exp } } funlist <- lapply(2:3, power)
now expect first element of 'funlist' square function , second cube function. seems repeats 'cubing'.
> funlist[[1]](5) [1] 125 > funlist[[2]](5) [1] 125
is there way generate list of functions closure in way? or general best practices surrounding problem may want approach in way?
the reason changed behavior in 3.2.0 announcement in news() file:
higher order functions such apply functions , reduce() force arguments functions apply in order eliminate undesirable interactions between lazy evaluation , variable capture in closures. resolves pr#16093.
Comments
Post a Comment