EVOLUTION-MANAGER
Edit File: body.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 Body of a Function</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 body {base}"><tr><td>body {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Access to and Manipulation of the Body of a Function</h2> <h3>Description</h3> <p>Get or set the body of a function. </p> <h3>Usage</h3> <pre> body(fun = sys.function(sys.parent())) body(fun, envir = environment(fun)) <- value </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>fun</code></td> <td> <p>a function object, or see ‘Details’.</p> </td></tr> <tr valign="top"><td><code>envir</code></td> <td> <p>environment in which the function should be defined.</p> </td></tr> <tr valign="top"><td><code>value</code></td> <td> <p>an object, usually a <a href="is.language.html">language object</a>: see section ‘Value’.</p> </td></tr> </table> <h3>Details</h3> <p>For the first form, <code>fun</code> can be a character string naming the function to be manipulated, which is searched for from the parent frame. If it is not specified, the function calling <code>body</code> is used. </p> <p>The bodies of all but the simplest are braced expressions, that is calls to <code>{</code>: see the ‘Examples’ section for how to create such a call. </p> <h3>Value</h3> <p><code>body</code> returns the body of the function specified. This is normally a <a href="is.language.html">language object</a>, most often a call to <code>{</code>, but it can also be an object (e.g., <code>pi</code>) to be the return value of the function. </p> <p>The replacement form sets the body of a function to the object on the right hand side, and (potentially) resets the environment of the function. If <code>value</code> is of class <code>"<a href="expression.html">expression</a>"</code> the first element is used as the body: any additional elements are ignored, with a warning. </p> <h3>See Also</h3> <p><code><a href="list.html">alist</a></code>, <code><a href="args.html">args</a></code>, <code><a href="function.html">function</a></code>. </p> <h3>Examples</h3> <pre> body(body) f <- function(x) x^5 body(f) <- quote(5^x) ## or equivalently body(f) <- expression(5^x) f(3) # = 125 body(f) ## creating a multi-expression body e <- expression(y <- x^2, return(y)) # or a list body(f) <- as.call(c(as.name("{"), e)) f f(8) ## Using substitute() may be simpler than 'as.call(c(as.name("{",..)))': stopifnot(identical(body(f), substitute({ y <- x^2; return(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>