assertthat icon indicating copy to clipboard operation
assertthat copied to clipboard

feature proposal: suggest_that() to give warnings instead of errors

Open danielinteractive opened this issue 4 years ago • 0 comments

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 in x are suggested by the function.
  • If the condition is not fulfilled, then a warning is issued.
    • In the example above for example: Warning: length(x) not greater than 10
  • 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 like assert_that())
    • suggestWarning() (similar like assertError())
    • 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 :-)

danielinteractive avatar Jul 06 '21 13:07 danielinteractive