Examples for 'base::force'


Force Evaluation of an Argument

Aliases: force

Keywords: data programming

### ** Examples

f <- function(y) function() y
lf <- vector("list", 5)
for (i in seq_along(lf)) lf[[i]] <- f(i)
lf[[1]]()  # returns 5
[1] 5
g <- function(y) { force(y); function() y }
lg <- vector("list", 5)
for (i in seq_along(lg)) lg[[i]] <- g(i)
lg[[1]]()  # returns 1
[1] 1
## This is identical to
g <- function(y) { y; function() y }

[Package base version 4.2.3 Index]