haltifnot: Ensure the Truth of R Expressions and Print Defined Error...

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/haltifnot.R

Description

If any of the expressions in ‘...’ are not all TRUE, stop is called, producing an error message defined by the msg parameter.

Usage

1
haltifnot(..., msg = "Error undefined. Please contact the developer")

Arguments

...

any number of ‘logical’ R expressions, which should evaluate to TRUE

msg

Error message.

Details

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.

Value

NULL if all statements in ... are TRUE

Author(s)

Jitao David Zhang <jitao_david.zhang@roche.com>

See Also

stop, warning and stopifnot

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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")
options(op)# revert to previous error handler

ribiosUtils documentation built on March 13, 2020, 2:54 a.m.