Rev 52927 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/base/man/formals.Rd% Part of the R package, http://www.R-project.org% Copyright 1995-2011 R Core Development Team% Distributed under GPL 2 or later\name{formals}\alias{formals}\alias{formals<-}\title{Access to and Manipulation of the Formal Arguments}\description{Get or set the formal arguments of a function.}\usage{formals(fun = sys.function(sys.parent()))formals(fun, envir = environment(fun)) <- value}\arguments{\item{fun}{a function object, or see \sQuote{Details}.}\item{envir}{environment in which the function should be defined.}\item{value}{a list (or pairlist) of \R expressions.}}\details{For the first form, \code{fun} can also be a character string namingthe function to be manipulated, which is searched for from the parentframe. If it is not specified, the function calling \code{formals} isused.Only \emph{closures} have formals, not primitive functions.}\value{\code{formals} returns the formal argument list of the functionspecified, as a \code{\link{pairlist}}, or \code{NULL} for anon-function or primitive.The replacement form sets the formals of a function to thelist/pairlist on the right hand side, and (potentially) resets theenvironment of the function.}\seealso{\code{\link{args}} for a human-readable version,\code{\link{alist}},\code{\link{body}},\code{\link{function}}.}\examples{require(stats); require(graphics)length(formals(lm)) # the number of formal argumentsnames(formals(boxplot)) # formal arguments namesf <- function(x) a+bformals(f) <- alist(a=,b=3) # function(a,b=3)a+bf(2) # result = 5}\keyword{programming}