args {base} | R Documentation |
Argument List of a Function
Description
Displays the argument names and corresponding default values of a (non-primitive or primitive) function.
Usage
args(name)
Arguments
name |
a function (a primitive or a closure, i.e.,
“non-primitive”).
If |
Details
This function is mainly used interactively to print the argument list
of a function. For programming, consider using formals
instead.
Value
For a closure, a closure with identical formal argument list but an
empty (NULL
) body.
For a primitive (function), a closure with the documented usage and NULL
body. Note that some primitives do not make use of named arguments
and match by position rather than name. Some primitives, mainly those
considered to be language elements, do not have a well-defined
argument list; for those NULL
is returned.
NULL
in case of a non-function.
References
Becker RA, Chambers JM, Wilks AR (1988). The New S Language. Chapman and Hall/CRC, London.
See Also
formals
, help
;
str
also prints the argument list of a function.
Examples
## "regular" (non-primitive) functions "print their arguments"
## (by returning another function with NULL body which you also see):
args(ls)
args(graphics::plot.default)
utils::str(ls) # (just "prints": does not show a NULL)
## You can also pass a string naming a function.
args("scan")
## ...but :: package specification doesn't work in this case.
tryCatch(args("graphics::plot.default"), error = print)
## As explained above, args() gives a function with empty body:
list(is.f = is.function(args(scan)), body = body(args(scan)))
## Primitive functions mostly behave like non-primitive functions.
args(c)
args(`+`)
## primitive functions without well-defined argument list return NULL:
args(`if`)