Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WISH: Near-zero overhead assertions #32

Open
HenrikBengtsson opened this issue Apr 12, 2018 · 2 comments
Open

WISH: Near-zero overhead assertions #32

HenrikBengtsson opened this issue Apr 12, 2018 · 2 comments
Labels
feature a feature request or enhancement
Milestone

Comments

@HenrikBengtsson
Copy link

(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
Copy link
Member

mllg commented Apr 12, 2018

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

Can you point me to a benchmark or commit?

@HenrikBengtsson
Copy link
Author

@gaborcsardi gaborcsardi added this to the V2 milestone Apr 23, 2018
@gaborcsardi gaborcsardi mentioned this issue Apr 28, 2018
12 tasks
@gaborcsardi gaborcsardi added the feature a feature request or enhancement label Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants