assertthat icon indicating copy to clipboard operation
assertthat copied to clipboard

Feature request: global option to disable assertions

Open ghost opened this issue 10 years ago • 2 comments

Thanks for this nice package. In a production environemnt I would like to switch off all (potentially expensive) assertions.

In compiled languages there is often a compiler switch to turn off assertions.

The closest in R is probably ?options with a new id isAssertionDisabled.

A simple solution is to add a single-line guard statement to assert_that:

assert_that <- function (..., env = parent.frame()) {
    if (isTRUE(getOption("isAssertionDisabled"))) return(TRUE)
    res <- see_if(..., env = env)
    if (res) 
        return(TRUE)
    stop(assertError(attr(res, "msg")))
}

ghost avatar Apr 03 '15 08:04 ghost

+1

kendonB avatar Jul 20 '16 22:07 kendonB

This is a cool idea. I actually think it could be implemented mimicking the way that futile.logger implements log thresholds

jameslamb avatar Jun 23 '18 15:06 jameslamb