on_failure.RdCustom failure messages for assertions.
on_failure(x)
on_failure(x) <- valueis_odd <- function(x) {
assert_that(is.numeric(x), length(x) == 1)
x %% 2 == 1
}
see_if(is_odd(2))
#> [1] FALSE
#> attr(,"msg")
#> [1] "is_odd(x = 2) is not TRUE"
on_failure(is_odd) <- function(call, env) {
paste0(deparse(call$x), " is even")
}
see_if(is_odd(2))
#> [1] FALSE
#> attr(,"msg")
#> [1] "2 is even"