on_failure: Custom failure messages for assertions.

Description Usage Arguments Examples

Description

Custom failure messages for assertions.

Usage

1
2
3
on_failure(x)

on_failure(x) <- value

Arguments

x

a assertion function that returns TRUE if the assertion is met, FALSE otherwise.

value

a function with parameters call and env that returns a custom error message as a string.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
is_odd <- function(x) {
  assert_that(is.numeric(x), length(x) == 1)
  x %% 2 == 1
}
see_if(is_odd(2))

on_failure(is_odd) <- function(call, env) {
  paste0(deparse(call$x), " is even")
}
see_if(is_odd(2))

Example output

[1] FALSE
attr(,"msg")
[1] "is_odd(x = 2) is not TRUE"
[1] FALSE
attr(,"msg")
[1] "2 is even"

assertthat documentation built on May 1, 2019, 10:25 p.m.