I\'m defining functions in a loop and trying to force evaluation of a loop variable without having to carry around a private environment.
Example: a set of functions
Here are two ways. They are the same except for the ## line in each:
formals<-
handlers <- list()
f <- function() message(i)
for (i in 1:6) {
formals(f) <- list(i = i) ##
handlers[[paste0('h', i)]] <- f
}
trace
handlers <- list()
f <- function() message(i)
for (i in 1:6) {
trace(f, bquote(i <- .(i)), print = FALSE) ##
handlers[[paste0('h', i)]] <- f
}