# Extending assertive with an is function that returns a single value
is_identical_to_pi <- function(x, .xname = get_name_in_parent())
{
if(!identical(x, pi))
{
return(false("%s is not identical to pi", .xname))
}
TRUE
}
assert_is_identical_to_pi <- function(x, .xname = get_name_in_parent())
{
assert_engine(
x,
is_identical_to_pi,
.xname = get_name_in_parent(x)
)
}
is_identical_to_pi(pi)
is_identical_to_pi(3)
assert_is_identical_to_pi(pi)
dont_stop(assert_is_identical_to_pi(3))
# Extending assertive with an is function that returns a vector
is_less_than_pi <- function(x)
{
is_in_right_open_range(x, upper = pi)
}
assert_all_are_less_than_pi <- function(x)
{
msg <- gettextf("%s are not all less than pi.", get_name_in_parent(x))
assert_engine(
x,
is_less_than_pi,
msg
)
}
assert_any_are_less_than_pi <- function(x)
{
msg <- gettextf("%s are all greater than or equal to pi.", get_name_in_parent(x))
assert_engine(
x,
is_less_than_pi,
msg,
what = "any"
)
}
x <- c(3, pi, 4, NA)
is_less_than_pi(x)
assert_any_are_less_than_pi(x)
dont_stop(assert_all_are_less_than_pi(x))
Run the code above in your browser using DataLab