assertthat
assertthat copied to clipboard
Feature request: global option to disable assertions
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")))
}
+1
This is a cool idea. I actually think it could be implemented mimicking the way that futile.logger implements log thresholds