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.

_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

