R/haltifnot.R
haltifnot.Rd
If any of the expressions in ‘...’ are not all TRUE, stop is called, producing an error message defined by the msg parameter.
haltifnot(..., msg = "Error undefined. Please contact the developer")
NULL
if all statements in ...
are TRUE
The function is adapted from the stopifnot
function, with the
difference that the error message can be defined the programmer. With
haltifnot
error message can be more informative, which is desired for
diagnostic and user-interation purposes.
haltifnot(1==1, all.equal(pi, 3.14159265), 1<2) ## all TRUE
m <- matrix(c(1,3,3,1), 2,2)
haltifnot(m == t(m), diag(m) == rep(1,2)) ## all TRUE
op <- options(error = expression(NULL))
# "disable stop(.)" << Use with CARE! >>
haltifnot(all.equal(pi, 3.141593), 2 < 2, all(1:10 < 12), "a" < "b",
msg="not all conditions are TRUE. Please contact the devleoper")
#> Error: not all conditions are TRUE. Please contact the devleoper
options(op)# revert to previous error handler