body {base} | R Documentation |
Get or set the body of a function.
body(fun = sys.function(sys.parent())) body(fun, envir = parent.frame()) <- value
fun |
a function object, or see Details. |
envir |
environment in which the function should be defined. |
value |
an expression or a list of R expressions. |
For the first form, fun
can be a character string
naming the function to be manipulated, which is searched for from the
parent environment.
If it is not specified, the function calling body
is used.
body
returns the body of the function specified.
The assignment form sets the body of a function to the list on the
right hand side.
For ancient historical reasons, envir = NULL
uses the global
environment rather than the base environment.
Please use envir = globalenv()
instead if this is what you want,
as the special handling of NULL
may change in a future release.
body(body) f <- function(x) x^5 body(f) <- expression(5^x) ## or equivalently body(f) <- list(quote(5^x)) f(3) # = 125 body(f)