checkmate
checkmate copied to clipboard
optionally set `call. = FALSE`
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.
(this was partly inspired by @hadley's error message style guide)
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.
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()?