\HeaderA{formals}{Access to and Manipulation of the Formal Arguments}{formals}
\aliasA{formals<\Rdash}{formals}{formals<.Rdash.}
\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 (or pairlist) of \R{} expressions.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
For the first form, \code{fun} can also 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, as a \code{\LinkA{pairlist}{pairlist}}.

The replacment form sets the formals of a function to the
list/pairlist on the right hand side.
\end{Value}
\begin{SeeAlso}\relax
\code{\LinkA{args}{args}} for a \dQuote{human-readable} version,
\code{\LinkA{alist}{alist}},
\code{\LinkA{body}{body}},
\code{\LinkA{function}{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}

