EVOLUTION-MANAGER
Edit File: as_closure.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: Transform to a closure</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 as_closure {rlang}"><tr><td>as_closure {rlang}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Transform to a closure</h2> <h3>Description</h3> <p><code>as_closure()</code> is like <code><a href="as_function.html">as_function()</a></code> but also wraps primitive functions inside closures. Some special control flow primitives like <code>if</code>, <code>for</code>, or <code>break</code> can't be wrapped and will cause an error. </p> <h3>Usage</h3> <pre> as_closure(x, env = caller_env()) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>A function or formula. </p> <p>If a <strong>function</strong>, it is used as is. </p> <p>If a <strong>formula</strong>, e.g. <code>~ .x + 2</code>, it is converted to a function with up to two arguments: <code>.x</code> (single argument) or <code>.x</code> and <code>.y</code> (two arguments). The <code>.</code> placeholder can be used instead of <code>.x</code>. This allows you to create very compact anonymous functions (lambdas) with up to two inputs. Functions created from formulas have a special class. Use <code>is_lambda()</code> to test for it. </p> <p>If a <strong>string</strong>, the function is looked up in <code>env</code>. Note that this interface is strictly for user convenience because of the scoping issues involved. Package developers should avoid supplying functions by name and instead supply them by value.</p> </td></tr> <tr valign="top"><td><code>env</code></td> <td> <p>Environment in which to fetch the function in case <code>x</code> is a string.</p> </td></tr> </table> <h3>Examples</h3> <pre> # Primitive functions are regularised as closures as_closure(list) as_closure("list") # Operators have `.x` and `.y` as arguments, just like lambda # functions created with the formula syntax: as_closure(`+`) as_closure(`~`) </pre> <hr /><div style="text-align: center;">[Package <em>rlang</em> version 1.0.6 <a href="00Index.html">Index</a>]</div> </body></html>