\HeaderA{body}{Access to and Manipulation of the Body of a Function}{body}
\aliasA{body<\Rdash}{body}{body<.Rdash.}
\keyword{programming}{body}
\begin{Description}\relax
Get or set the body of a function.
\end{Description}
\begin{Usage}
\begin{verbatim}
body(fun = sys.function(sys.parent()))
body(fun, envir = environment(fun)) <- value
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{fun}] a function object, or see \sQuote{Details}.
\item[\code{envir}] environment in which the function should be defined.
\item[\code{value}] an object, usually a language object: see section
\sQuote{Value}.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
For the first form, \code{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
\code{body} is used.

To set the value to a list call the replacement function with
\code{value} a length-one list containing the desired value.
\end{Details}
\begin{Value}
\code{body} returns the body of the function specified.  This is
normally a language object, most often a call to \code{\{}, but it can
also be an object (e.g. \code{pi}) to be the return value of the function.

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} is of class
\code{"\LinkA{expression}{expression}"} or a length-one list, the first
element is used as the body.  For expressions (but not lists) any
additional elements are ignored, with a warning.
\end{Value}
\begin{SeeAlso}\relax
\code{\LinkA{alist}{alist}},
\code{\LinkA{args}{args}},
\code{\LinkA{function}{function}}.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
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)
\end{ExampleCode}
\end{Examples}

