EVOLUTION-MANAGER
Edit File: function.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: Function Definition</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 function {base}"><tr><td>function {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Function Definition</h2> <h3>Description</h3> <p>These functions provide the base mechanisms for defining new functions in the <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> language. </p> <h3>Usage</h3> <pre> function( arglist ) expr return(value) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>arglist</code></td> <td> <p>Empty or one or more name or name=expression terms.</p> </td></tr> <tr valign="top"><td><code>expr</code></td> <td> <p>An expression.</p> </td></tr> <tr valign="top"><td><code>value</code></td> <td> <p>An expression.</p> </td></tr> </table> <h3>Details</h3> <p>The names in an argument list can be back-quoted non-standard names (see ‘<a href="Quotes.html">backquote</a>’). </p> <p>If <code>value</code> is missing, <code>NULL</code> is returned. If it is a single expression, the value of the evaluated expression is returned. (The expression is evaluated as soon as <code>return</code> is called, in the evaluation frame of the function and before any <code><a href="on.exit.html">on.exit</a></code> expression is evaluated.) </p> <p>If the end of a function is reached without calling <code>return</code>, the value of the last evaluated expression is returned. </p> <h3>Technical details</h3> <p>This type of function is not the only type in <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span>: they are called <em>closures</em> (a name with origins in LISP) to distinguish them from <a href="Primitive.html">primitive</a> functions. </p> <p>A closure has three components, its <code><a href="formals.html">formals</a></code> (its argument list), its <code><a href="body.html">body</a></code> (<code>expr</code> in the ‘Usage’ section) and its <code><a href="environment.html">environment</a></code> which provides the enclosure of the evaluation frame when the closure is used. </p> <p>There is an optional further component if the closure has been byte-compiled. This is not normally user-visible, but is indicated when functions are printed. </p> <h3>References</h3> <p>Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) <em>The New S Language</em>. Wadsworth & Brooks/Cole. </p> <h3>See Also</h3> <p><code><a href="args.html">args</a></code>. </p> <p><code><a href="formals.html">formals</a></code>, <code><a href="body.html">body</a></code> and <code><a href="environment.html">environment</a></code> for accessing the component parts of a function. </p> <p><code><a href="debug.html">debug</a></code> for debugging; using <code><a href="invisible.html">invisible</a></code> inside <code>return(.)</code> for returning <em>invisibly</em>. </p> <h3>Examples</h3> <pre> norm <- function(x) sqrt(x%*%x) norm(1:4) ## An anonymous function: (function(x, y){ z <- x^2 + y^2; x+y+z })(0:7, 1) </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>