Forces the evaluation of all arguments in the calling environment of this function.
Details
Use force_all() as syntactic sugar to force evaluation of
all arguments to a function and thereby circumvent lazy evaluation.
If called from within a function with ... as formal argument,
use force_all(...) to force evaluation of arguments captured
by ....
Examples
affine <- function(a, b) {
function(x) a * x + b
}
a <- 1
b <- 1
affine_11 <- affine(a, b)
a <- 2
b <- 2
affine_11(1) # Gives 4 and not 2 due to lazy evaluation
#> [1] 4
affine_forced <- function(a, b) {
force_all()
function(x) a * x + b
}
a <- 1
b <- 1
affine_11 <- affine_forced(a, b)
a <- 2
b <- 2
affine_11(1) # Gives 2
#> [1] 2