r-lib / debugme

Easy and efficient debugging for R packages
https://r-lib.github.io/debugme/
Other
148 stars 10 forks source link

WISH: Near-zero overhead assertions #32

Open HenrikBengtsson opened 6 years ago

HenrikBengtsson commented 6 years ago

(continuation of my Tweet https://twitter.com/henrikbengtsson/status/984323561656483841)

Analogously to how you can produce debug messages using:

    "!DEBUG Hello world: x = `x`"

I'd like to run assertion statements that have near-zero overhead, e.g.

    "!ASSERT 'x' is integer `stopifnot(is.integer(x))`"

This will allow package developers to add lots of internal assertions validating not only the contract of returned values, but also intermediate values.

The above could be achieved by

    "!DEBUG `stopifnot(is.integer(x))`"

but the downside is that this will also trigger lots of DEBUG-produced output if such exists. Not only may such output clutter troubleshooting but it may also have side effects conflicting with any troubleshooting efforts, e.g. in a DEBUG statement may touch a promise (think "delayed assignment") causing different results than when disabled.

Any assert framework should be supported, so it should not be hard coded to stopifnot() [which comes with even more overhead in R (>= 3.5.0)], assertthat, checkmate, ...

mllg commented 6 years ago

stopifnot() [which comes with even more overhead in R (>= 3.5.0)]

Can you point me to a benchmark or commit?

HenrikBengtsson commented 6 years ago

See https://github.com/HenrikBengtsson/Wishlist-for-R/issues/70