Calculates the number of positional arguments used in a call.

nposargs(x, a = FALSE)

## Arguments

x a call object, usually obtained from sys.call(). if a is TRUE make a correction to distinguish x[] from x[i], see details.

## Details

nposargs is mainly for use in the body of function definitions, paricularly for functions or methods that wish to mimic the behaviour of "[".

nposargs gives the number of positional arguments used in a call. It also takes into account empty arguments like those used in expressions like x[1, ].

Optionally, it makes a particular correction that is peculiar for "[" - if there are no named arguments in the call and the count of the arguments is 2 and a=TRUE, it decreases the count by one, i.e. returns 1. This is to distinguish between a x[] and x[i] which both would give 2 otherwise. I have forgotten the details but, roughly speaking, x[i] becomes "["(x,i) while x[] becomes "["(x,), i.e. R puts the comma after x in any case.

## Value

the number of positional arguments in the call

## Note

I wrote this function (a long time ago) for use in methods for "[".

a above is typically obtained by a call missing(i) somewhere at the beginning of the function. In my application I put the results of several such calls in a vector, hence the check for a rather than a, For "[", we may set a = c(missing(i), missing(j), missing(k)).

## Examples

f <- function(x,y,z,...){
call <- sys.call()
nposargs(call)
}
f(a,b,c)  # 3#>  3f(a, , )  # 3#>  3f(a,  )   # 2#>  2f(a)      # 1#>  1f(,  )    # 2#>  2f(, a,  ) # 3#>  3f()       # 0#>  0