Bug 16266 - Consider providing stopif()
Summary: Consider providing stopif()
Status: NEW
Alias: None
Product: R
Classification: Unclassified
Component: Wishlist (show other bugs)
Version: R 3.1.2
Hardware: Other Other
: P5 enhancement
Assignee: R-core
Depends on:
Reported: 2015-03-18 10:44 UTC by Osmo Salomaa
Modified: 2016-01-11 09:25 UTC (History)
1 user (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Osmo Salomaa 2015-03-18 10:44:17 UTC
Currently R provides a stopifnot() function for making assertions. It would be useful to also have stopif(), which would stop if any of the arguments is any TRUE. stopif() would help in avoiding double-negatives, which make reading code difficult, e.g.

    stopifnot(!is.na(x)) vs. stopif(is.na(x))
Comment 1 Amur Ghose 2016-01-10 01:28:20 UTC
Hi, it seems like your problem is easy to fix by modifying the stopifnot code.

Relevant code here : https://svn.r-project.org/R/trunk/src/library/base/R/stop.R

Basically shows that stopifnot checks if each element is piecewise FALSE and has a ! on the conditional for checking. If we just remove this and modify the string that is displayed upon finding something FALSE to something that will be shown for getting true, we are done.
Comment 2 Osmo Salomaa 2016-01-11 09:25:09 UTC
(In reply to Amur Ghose from comment #1)
> Hi, it seems like your problem is easy to fix by modifying the stopifnot
> code.

Yes, I figured this was such obvious that I didn't mention it in the bug description. I have already had such a function modified from stopifnot for years in our company internal package of miscellaneous functions. I'd just like to see it in base R. There's no difficulty implementing it, it's just a question of whether the conservative maintainers see value to warrant the addition.