assert 1.32 KB
assert                package:gtools                R Documentation

_G_e_n_e_r_a_t_e _a_n _e_r_r_o_r _i_f _a_n _e_x_p_r_e_s_s_i_o_n _i_s _n_o_t _t_r_u_e.

_D_e_s_c_r_i_p_t_i_o_n:

     Generate an error if an expression is not true.

_U_s_a_g_e:

     assert(FLAG)

_A_r_g_u_m_e_n_t_s:

    FLAG: Expression that should evaluate to a boolean vector

_D_e_t_a_i_l_s:

     Assert generate an error if its aregument does not evaluate to 
     boolean (vector) containing only 'TRUE' values.  This is useful
     for defensinve programming as it provides a mechanism for checking
     that certain facts, the 'assertions', do in fact hold.  Checking
     of  'assertions' is an important tool in the development of robust
     program code.

_V_a_l_u_e:

     None.  Evaluated only for its side effect.

_A_u_t_h_o_r(_s):

     Gregory R. Warnes warnes@bst.rochester.edu

_S_e_e _A_l_s_o:

     'stop', 'warning'

_E_x_a_m_p_l_e_s:

     ## Trivial example
     posSqrt <- function(x)
       {
         assert(x>=0)
         sqrt(x)
       }

     posSqrt(1:10) # works fine, no messages
     ## Not run: 
     posSqrt(-5:5) # generates an error, since the asssertion is not met
     ## End(Not run)