EVOLUTION-MANAGER
Edit File: force.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Force Evaluation of an Argument</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for force {base}"><tr><td>force {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Force Evaluation of an Argument</h2> <h3>Description</h3> <p>Forces the evaluation of a function argument. </p> <h3>Usage</h3> <pre> force(x) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>a formal argument of the enclosing function.</p> </td></tr> </table> <h3>Details</h3> <p><code>force</code> 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. </p> <h3>Note</h3> <p>This is semantic sugar: just evaluating the symbol will do the same thing (see the examples). </p> <p><code>force</code> does not force the evaluation of other <a href="delayedAssign.html">promises</a>. (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 <em>lazy evaluation</em>.) </p> <h3>Examples</h3> <pre> f <- function(y) function() y lf <- vector("list", 5) for (i in seq_along(lf)) lf[[i]] <- f(i) lf[[1]]() # returns 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 ## This is identical to g <- function(y) { y; function() y } </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>