formals

0th

Percentile

Access to and Manipulation of the Formal Arguments

Get or set the formal arguments of a function.

Keywords
programming
Usage
formals(fun = sys.function(sys.parent())) formals(fun, envir = environment(fun)) <- value
Arguments
fun
a function object, or see ‘Details’.
envir
environment in which the function should be defined.
value
a list (or pairlist) of R expressions.
Details

For the first form, fun can also be a character string naming the function to be manipulated, which is searched for from the parent frame. If it is not specified, the function calling formals is used.

Only closures have formals, not primitive functions.

Value

formals returns the formal argument list of the function specified, as a pairlist, or NULL for a non-function or primitive.The replacement form sets the formals of a function to the list/pairlist on the right hand side, and (potentially) resets the environment of the function.

See Also

args for a human-readable version, alist, body, function.

Aliases
  • formals
  • formals<-
Examples
library(base) require(stats); require(graphics) 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
Documentation reproduced from package base, version 3.0.3, License: Part of R 3.0.3

Community examples

Looks like there are no examples yet.