I would like to delay the evaluation of a function argument in R. Example:
my_func <- function(FUN){print(FUN); print(FUN)}
my_func(runif(1))
#> [1] 0.2833882
#> [1] 0.2833882
Created on 2019-07-21 by the reprex package (v0.2.1)
This works as documented because runif(1)
is only evaluated once and its results printed twice.
Instead, I don't want runif(1)
to be evaluated until it is within each print() statement. This would generate two different random numbers.
In other words, I don't want FUN to "resolve" --- if that is the right word --- to runif(1)
until we are within a print()
statement.