missing                 package:base                 R Documentation

_D_o_e_s _a _F_o_r_m_a_l _A_r_g_u_m_e_n_t _h_a_v_e _a _V_a_l_u_e?

_D_e_s_c_r_i_p_t_i_o_n:

     'missing' can be used to test whether a value was specified as an
     argument to a function.

_U_s_a_g_e:

     missing(x)

_A_r_g_u_m_e_n_t_s:

       x: a formal argument.

_D_e_t_a_i_l_s:

     'missing(x)' is only reliable if 'x' has not been altered since
     entering the function: in particular it will _always_ be false
     after 'x <- match.arg(x)'. 

     The example shows how a plotting function can be written to work
     with either a pair of vectors giving x and y coordinates of points
     to be plotted or a single vector giving y values to be plotted
     against their indexes.

     Currently 'missing' can only be used in the immediate body of the
     function that defines the argument, not in the body of a nested
     function or a 'local' call.  This may change in the future.

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

     Chambers, J. M. (1998) _Programming with Data. A Guide to the S
     Language_. Springer.

_S_e_e _A_l_s_o:

     'substitute' for argument expression; 'NA' for "missing values" in
     data.

_E_x_a_m_p_l_e_s:

     myplot <- function(x,y) {
                     if(missing(y)) {
                             y <- x
                             x <- 1:length(y)
                     }
                     plot(x,y)
             }

