\Header{formals}{Access to and Manipulation of the Formal Arguments}
\alias{formals<\Rdash}{formals}
\keyword{programming}{formals}
\begin{Description}\relax
Get or set the formal arguments of a function.\end{Description}
\begin{Usage}
\begin{verbatim}
formals(fun = sys.function(sys.parent()))
formals(fun, envir = parent.frame()) <- value
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{fun}] a function object, or see Details.
\item[\code{envir}] environment in which the function should be defined.
\item[\code{value}] a list of \R{} expressions.
\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{formals} is used.\end{Details}
\begin{Value}
\code{formals} returns the formal argument list of the function
specified.

The assignment form sets the formals of a function to the list on the
right hand side.\end{Value}
\begin{SeeAlso}\relax
\code{\Link{args}} for a \dQuote{human-readable} version,
\code{\Link{alist}},
\code{\Link{body}},
\code{\Link{function}}.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
length(formals(lm))      # the number of formal arguments
names(formals(boxplot))  # formal arguments names

f <- function(x)a+b
formals(f) <- alist(a=,b=3) # function(a,b=3)a+b
f(2) # result = 5
\end{ExampleCode}
\end{Examples}

