Forces the evaluation of a function argument.
强制评价函数的参数。
用法----------Usage----------
force(x)
参数----------Arguments----------
参数:x
a formal argument of the enclosing function.
一个封闭的功能的正式说法。
Details
详情----------Details----------
force forces the evaluation of a formal argument. This can be useful if the argument will be captured in a closure by the lexical scoping rules and will later be altered by an explicit assignment or an implicit assignment in a loop or an apply function.
force迫使评价一个正式的说法。这可能是有用的,如果该参数将被捕获在一个封闭的词法作用域规则,稍后将在一个循环或应用函数的隐式分配一个明确的转让或改变。
注意----------Note----------
This is semantic sugar: just evaluating the symbol will do the same thing (see the examples).
这是语义糖:只是评价的象征,将做同样的事情(见例子)。
force does not force the evaluation of other promises. (It works by forcing the promise that is created when the actual arguments of a call are matched to the formal arguments of a closure, the mechanism which implements lazy evaluation.)
force不强制评估的其他承诺。 (它的工作原理。迫使创建时调用的实际参数是一个封闭的形式参数匹配的承诺,实现懒惰的评价机制)
举例----------Examples----------
f <- function(y) function() y
lf <- vector("list", 5)
for (i in seq_along(lf)) lf[[i]] <- f(i)
lf[[1]]() # returns 5[返回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]
## This is identical to[#这是相同的]
g <- function(y) { y; function() y }