Replacing force() with eval(as.symbol()) will do the trick:
## Modified from an example in ?force (ht @flodel) g <- function(x,y) { lapply(ls(), function(X) eval(as.symbol(X))) function() x+y } lg <- vector("list", 4) for (i in 1:2) for (j in 1:2) lg[[i+j-1]] <- g(i,j) lg[[1]]() # [1] 2
This works because, as noted in ?force :
[force] - semantic sugar: just character evaluation will do the same
source share