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

     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(error = NULL)# revert to default error handler

