nargs: The Number of Arguments to a Function

Description Usage Details References See Also Examples

Description

When used inside a function body, nargs returns the number of arguments supplied to that function, including positional arguments left blank.

Usage

1

Details

The count includes empty (missing) arguments, so that foo(x,,z) will be considered to have three arguments (see ‘Examples’). This can occur in rather indirect ways, so for example x[] might dispatch a call to `[.some_method`(x, ) which is considered to have two arguments.

This is a primitive function.

References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.

See Also

args, formals and sys.call.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
tst <- function(a, b = 3, ...) {nargs()}
tst() # 0
tst(clicketyclack) # 1 (even non-existing)
tst(c1, a2, rr3) # 3

foo <- function(x, y, z, w) {
   cat("call was ", deparse(match.call()), "\n", sep = "")
   nargs()
}
foo()      # 0
foo(, , 3) # 3
foo(z = 3) # 1, even though this is the same call

nargs()  # not really meaningful

robertzk/monadicbase documentation built on May 27, 2019, 10:35 a.m.