nargs                  package:base                  R Documentation

_T_h_e _N_u_m_b_e_r _o_f _A_r_g_u_m_e_n_t_s _t_o _a _F_u_n_c_t_i_o_n

_D_e_s_c_r_i_p_t_i_o_n:

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

_U_s_a_g_e:

     nargs()

_D_e_t_a_i_l_s:

     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.

_R_e_f_e_r_e_n_c_e_s:

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

_S_e_e _A_l_s_o:

     'args', 'formals' and 'sys.call'.

_E_x_a_m_p_l_e_s:

     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")
        nargs()
     }
     foo()    # 0
     foo(,,3) # 3
     foo(z=3) # 1, even though this is the same call

     nargs()# not really meaningful

