stopifnot                package:base                R Documentation

_E_n_s_u_r_e _t_h_e '_T_r_u_t_h' _o_f _R _E_x_p_r_e_s_s_i_o_n_s

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

     If any of the expressions in '...' are not 'all' 'TRUE', 'stop' is
     called, producing an error message indicating the _first_ element
     of '...' which was not true.

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

     stopifnot(...)

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

     ...: any number of ('logical') R expressions which should evaluate
          to 'TRUE'.

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

     'stopifnot(A, B)' is conceptually equivalent to '{ if(!all(A))
     stop(...) ; if(!all(B)) stop(...) }'.

_V_a_l_u_e:

     ('NULL' if all statements in '...' are 'TRUE'.)

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

     'stop', 'warning'.

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

     stopifnot(1 == 1, all.equal(pi, 3.14159265), 1 < 2) # all TRUE

     m <- matrix(c(1,3,3,1), 2,2)
     stopifnot(m == t(m), diag(m) == rep(1,2)) # all(.) |=>  TRUE

     op <- options(error = expression(NULL))# "disable stop(.)"  << Use with CARE! >>

     stopifnot(all.equal(pi, 3.141593),  2 < 2, all(1:10 < 12), "a" < "b")
     stopifnot(all.equal(pi, 3.1415927), 2 < 2, all(1:10 < 12), "a" < "b")

     options(op)# revert to previous error handler

