assertthat
assertthat copied to clipboard
feature proposal: suggest_that() to give warnings instead of errors
Feature proposal: Adding a warning feature to the assertthat package.
See also: https://github.com/hadley/assertthat/issues/37
Naming ideas:
-
recommend_that()Rationale: If the recommendation is not followed, then a warning is given. -
suggest_that()Rationale: If the suggestion is not followed, we warn the user. This is shorter to type and say, so seems better.
Usage:
- Analogous to
assert_that().- So for example:
suggest_that(length(x) > 10)if more than 10 elements inxare suggested by the function.
- So for example:
- If the condition is not fulfilled, then a warning is issued.
- In the example above for example:
Warning: length(x) not greater than 10
- In the example above for example:
- The warning message text is the same as the
assert_that()one.- Consider automatically replacing "must" by "should" etc.
- But ideally the messages would not have such verbs in them, but are just factual ("x is not abc" instead of "x must be abc")
Implementation:
- starting point: https://github.com/hadley/assertthat/blob/master/R/assert-that.r and https://github.com/hadley/assertthat/blob/master/R/validate-that.R
- required functions:
-
suggest_that()(similar likeassert_that()) -
suggestWarning()(similar likeassertError()) -
error_to_warning_msg()(only if we want to replace verbs in the message as mentioned above)
-
- tests: similar like https://github.com/hadley/assertthat/blob/master/tests/testthat/test-assert-that.R
Any feedback on this? Does it make sense? I would be happy to provide a PR :-)