checkmate icon indicating copy to clipboard operation
checkmate copied to clipboard

optionally set `call. = FALSE`

Open maxheld83 opened this issue 7 years ago • 3 comments

the assert_-family of functions currently report the name of the function where the error occurred, like so:

assert_character(1)
## Error in assert_character(1) : 
##   Assertion on '1' failed: Must be of type 'character', not 'double'.

I'm guessing that's because somewhere in checkmate there's a stop(call. = TRUE) or something similar.

For user-facing error messages, this may sometimes just add confusing clutter, and, in any case, there's always traceback().

So I was wondering whether an additional argument to all assert_-functions call. = TRUE (defaulting thus) might be worthwhile.

maxheld83 avatar Feb 02 '18 18:02 maxheld83

(this was partly inspired by @hadley's error message style guide)

maxheld83 avatar Feb 02 '18 18:02 maxheld83

Unsure about where to put the option (i.e., you can only set it globally for all packages, not for a specific one). Will look into it.

mllg avatar Feb 12 '18 13:02 mllg

This would be really appreciated. For now the error messages from assertions inside the active bindings of R6 classes are unnecessarily cluttered, e.g.

active_binding = function(value)
{
        if (missing(value)) {
            return (private$.active_binding)
        } else {
            assert_string(active_binding, .var.name = "active_binding")
            private$.active_binding <- value
        }
}

leads to

Error in (function (value)  : 
  Assertion on 'active_binding' failed: Must have length 1.

Perhaps as a common argument for all assert_* functions or a package option, e.g. as using option(checkmate.error.call = FALSE) and getOption("checkmate.error.call") inside makeAssertion()?

JakubBujnowicz avatar Jan 19 '22 10:01 JakubBujnowicz