EVOLUTION-MANAGER
Edit File: formals.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: Access to and Manipulation of the Formal Arguments</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 formals {base}"><tr><td>formals {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Access to and Manipulation of the Formal Arguments</h2> <h3>Description</h3> <p>Get or set the formal arguments of a <code><a href="function.html">function</a></code>. </p> <h3>Usage</h3> <pre> formals(fun = sys.function(sys.parent()), envir = parent.frame()) formals(fun, envir = environment(fun)) <- value </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>fun</code></td> <td> <p>a <code><a href="function.html">function</a></code>, or see ‘Details’.</p> </td></tr> <tr valign="top"><td><code>envir</code></td> <td> <p><code><a href="environment.html">environment</a></code> in which the function should be defined (or found via <code><a href="get.html">get</a>()</code> in the first case and when <code>fun</code> a character string).</p> </td></tr> <tr valign="top"><td><code>value</code></td> <td> <p>a <code><a href="list.html">list</a></code> (or <code><a href="list.html">pairlist</a></code>) of <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> expressions.</p> </td></tr> </table> <h3>Details</h3> <p>For the first form, <code>fun</code> can also be a character string naming the function to be manipulated, which is searched for in <code>envir</code>, by default from the parent frame. If it is not specified, the function calling <code>formals</code> is used. </p> <p>Only <em>closures</em> have formals, not primitive functions. </p> <h3>Value</h3> <p><code>formals</code> returns the formal argument list of the function specified, as a <code><a href="list.html">pairlist</a></code>, or <code>NULL</code> for a non-function or primitive. </p> <p>The replacement form sets the formals of a function to the list/pairlist on the right hand side, and (potentially) resets the environment of the function. </p> <h3>See Also</h3> <p><code><a href="../../methods/html/methodUtilities.html">formalArgs</a></code> (from <span class="pkg">methods</span>), a shortcut for <code>names(formals(.))</code>. <code><a href="args.html">args</a></code> for a human-readable version, <code><a href="list.html">alist</a></code>, <code><a href="body.html">body</a></code>, <code><a href="function.html">function</a></code>. </p> <h3>Examples</h3> <pre> require(stats) formals(lm) ## If you just want the names of the arguments, use formalArgs instead. names(formals(lm)) methods:: formalArgs(lm) # same ## formals returns a pairlist. Arguments with no default have type symbol (aka name). str(formals(lm)) ## formals returns NULL for primitive functions. Use it in combination with ## args for this case. is.primitive(`+`) formals(`+`) formals(args(`+`)) ## You can overwrite the formal arguments of a function (though this is ## advanced, dangerous coding). f <- function(x) a + b formals(f) <- alist(a = , b = 3) f # function(a, b = 3) a + b f(2) # result = 5 </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>