Access to and Manipulation of the Formal Arguments

DESCRIPTION:

Get or set the formal arguments of a function.

USAGE:

formals(fun)
formals(fun) <- value

REQUIRED ARGUMENTS:

fun
a function object.

OPTIONAL ARGUMENTS:

value
a list of expressions with named elements. The element names will be the argument names and the values will be the default argument values.

VALUE:

a list where element names are the argument names and their values are the default argument values.

SIDE EFFECTS:

The assignment function sets the formal arguments of the function to the list on the right hand side. No consistency with current argument names or number is enforced or checked for. All existing arguments are replaced by the new list of arguments.

DETAILS:

When calling the function formals(), the fun argument can be a character string giving the name of a function.

These functions emulate R functions of the same name, but are somewhat different. The S-PLUS version of formals() does not have a default value for the fun argument. The S-PLUS version of formals()<- does not have the envir argument that the R includes.

SEE ALSO:

, .

EXAMPLES:

# Getting names of formal arguments
names(formals(persp))

# Setting formal arguments
func <- function(x) a + b
formals(func) <- list(a = NULL, b = 3)
func(10)