Title: | Tidy assertions |
---|---|
Description: | A re-imagining of stopifnot() with rlang::abort(). Provides an api for simple input (and output) validation with consistent error messages. |
Authors: | Anthony North [aut, cre], Queensland Fire and Emergency Services [cph, fnd] |
Maintainer: | Anthony North <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.3.4 |
Built: | 2024-11-05 02:40:06 UTC |
Source: | https://github.com/qfes/tidyassert |
Raises an assertion error when any(expr)
is false.
assert( expr, error_message = NULL, error_class = NULL, call = rlang::caller_call(), env = rlang::caller_env(), print_expr = NULL, ... )
assert( expr, error_message = NULL, error_class = NULL, call = rlang::caller_call(), env = rlang::caller_env(), print_expr = NULL, ... )
expr |
< |
error_message |
< |
error_class |
< |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be |
env |
< |
print_expr |
< |
... |
< |
Raises an assertion error when !all(a == b)
.
assert_equal( a, b, error_message = "{.arg a} must equal {.arg b}", error_class = NULL )
assert_equal( a, b, error_message = "{.arg a} must equal {.arg b}", error_class = NULL )
a |
< |
b |
< |
error_message |
< |
error_class |
< |
Other logical-assertions:
assert_greater_equal()
,
assert_greater()
,
assert_less_equal()
,
assert_less()
,
assert_not_equal()
,
assert_range()
Raises an assertion error when !all(a > b)
assert_greater( a, b, error_message = "{.arg a} must be greater than {.arg b}", error_class = NULL )
assert_greater( a, b, error_message = "{.arg a} must be greater than {.arg b}", error_class = NULL )
a |
< |
b |
< |
error_message |
< |
error_class |
< |
Other logical-assertions:
assert_equal()
,
assert_greater_equal()
,
assert_less_equal()
,
assert_less()
,
assert_not_equal()
,
assert_range()
Raises an assertion error when !all(a >= b)
assert_greater_equal( a, b, error_message = "{.arg a} must be greater than or equal {.arg b}", error_class = NULL )
assert_greater_equal( a, b, error_message = "{.arg a} must be greater than or equal {.arg b}", error_class = NULL )
a |
< |
b |
< |
error_message |
< |
error_class |
< |
Other logical-assertions:
assert_equal()
,
assert_greater()
,
assert_less_equal()
,
assert_less()
,
assert_not_equal()
,
assert_range()
Raises an assertion error when !rlang::has_name(obj, names)
.
assert_has_names( obj, names, error_message = "{.arg obj} must have names {.arg names}", error_class = NULL )
assert_has_names( obj, names, error_message = "{.arg obj} must have names {.arg names}", error_class = NULL )
obj |
< |
names |
< |
error_message |
< |
error_class |
< |
Other attribute-assertions:
assert_is_named()
Raises an assertion error when !inherits(obj, class)
.
assert_inherits( obj, class, error_message = "{.arg obj} must inherit {.cls {class}}", error_class = NULL )
assert_inherits( obj, class, error_message = "{.arg obj} must inherit {.cls {class}}", error_class = NULL )
obj |
< |
class |
< |
error_message |
< |
error_class |
< |
Other type-assertions:
assert_is_character()
,
assert_is_double()
,
assert_is_integerish()
,
assert_is_integer()
,
assert_is_logical()
,
assert_is_numeric()
,
assert_is_raw()
,
assert_is_typeof()
Raises an assertion error when !rlang::is_bool(obj)
.
assert_is_bool( obj, error_message = "{.arg obj} must be a {.cls bool}", error_class = NULL )
assert_is_bool( obj, error_message = "{.arg obj} must be a {.cls bool}", error_class = NULL )
obj |
< |
error_message |
< |
error_class |
< |
Other scalar-assertions:
assert_is_scalar_character()
,
assert_is_scalar_double()
,
assert_is_scalar_integerish()
,
assert_is_scalar_integer()
,
assert_is_scalar_logical()
,
assert_is_scalar_numeric()
,
assert_is_scalar_raw()
,
assert_is_string()
Raises an assertion error when !rlang::is_character(obj)
.
assert_is_character( obj, error_message = "{.arg obj} must be a {.cls character} vector", error_class = NULL )
assert_is_character( obj, error_message = "{.arg obj} must be a {.cls character} vector", error_class = NULL )
obj |
< |
error_message |
< |
error_class |
< |
Other type-assertions:
assert_inherits()
,
assert_is_double()
,
assert_is_integerish()
,
assert_is_integer()
,
assert_is_logical()
,
assert_is_numeric()
,
assert_is_raw()
,
assert_is_typeof()
Raises an assertion error when !rlang::is_double(obj)
.
assert_is_double( obj, error_message = "{.arg obj} must be a {.cls double} vector", error_class = NULL )
assert_is_double( obj, error_message = "{.arg obj} must be a {.cls double} vector", error_class = NULL )
obj |
< |
error_message |
< |
error_class |
< |
Other type-assertions:
assert_inherits()
,
assert_is_character()
,
assert_is_integerish()
,
assert_is_integer()
,
assert_is_logical()
,
assert_is_numeric()
,
assert_is_raw()
,
assert_is_typeof()
Raises an assertion error when !rlang::is_integer(obj)
.
assert_is_integer( obj, error_message = "{.arg obj} must be an {.cls integer} vector", error_class = NULL )
assert_is_integer( obj, error_message = "{.arg obj} must be an {.cls integer} vector", error_class = NULL )
obj |
< |
error_message |
< |
error_class |
< |
Other type-assertions:
assert_inherits()
,
assert_is_character()
,
assert_is_double()
,
assert_is_integerish()
,
assert_is_logical()
,
assert_is_numeric()
,
assert_is_raw()
,
assert_is_typeof()
Raises an assertion error when !rlang::is_integerish(obj)
.
assert_is_integerish( obj, error_message = "{.arg obj} must be an {.cls integerish} vector", error_class = NULL )
assert_is_integerish( obj, error_message = "{.arg obj} must be an {.cls integerish} vector", error_class = NULL )
obj |
< |
error_message |
< |
error_class |
< |
Other type-assertions:
assert_inherits()
,
assert_is_character()
,
assert_is_double()
,
assert_is_integer()
,
assert_is_logical()
,
assert_is_numeric()
,
assert_is_raw()
,
assert_is_typeof()
Raises an assertion error when !rlang::is_logical(obj)
.
assert_is_logical( obj, error_message = "{.arg obj} must be a {.cls logical} vector", error_class = NULL )
assert_is_logical( obj, error_message = "{.arg obj} must be a {.cls logical} vector", error_class = NULL )
obj |
< |
error_message |
< |
error_class |
< |
Other type-assertions:
assert_inherits()
,
assert_is_character()
,
assert_is_double()
,
assert_is_integerish()
,
assert_is_integer()
,
assert_is_numeric()
,
assert_is_raw()
,
assert_is_typeof()
Raises an assertion error when !rlang::is_named(obj)
.
assert_is_named( obj, error_message = "{.arg obj} must be named", error_class = NULL )
assert_is_named( obj, error_message = "{.arg obj} must be named", error_class = NULL )
obj |
< |
error_message |
< |
error_class |
< |
Other attribute-assertions:
assert_has_names()
Raises an assertion error when !is.numeric(obj)
.
assert_is_numeric( obj, error_message = "{.arg obj} must be a {.cls numeric} vector", error_class = NULL )
assert_is_numeric( obj, error_message = "{.arg obj} must be a {.cls numeric} vector", error_class = NULL )
obj |
< |
error_message |
< |
error_class |
< |
Other type-assertions:
assert_inherits()
,
assert_is_character()
,
assert_is_double()
,
assert_is_integerish()
,
assert_is_integer()
,
assert_is_logical()
,
assert_is_raw()
,
assert_is_typeof()
Raises an assertion error when !rlang::is_raw(obj)
.
assert_is_raw( obj, error_message = "{.arg obj} must be a {.cls raw} vector", error_class = NULL )
assert_is_raw( obj, error_message = "{.arg obj} must be a {.cls raw} vector", error_class = NULL )
obj |
< |
error_message |
< |
error_class |
< |
Other type-assertions:
assert_inherits()
,
assert_is_character()
,
assert_is_double()
,
assert_is_integerish()
,
assert_is_integer()
,
assert_is_logical()
,
assert_is_numeric()
,
assert_is_typeof()
Raises an assertion error when !rlang::is_scalar_character(obj)
.
assert_is_scalar_character( obj, error_message = "{.arg obj} must be a scalar {.cls character}", error_class = NULL )
assert_is_scalar_character( obj, error_message = "{.arg obj} must be a scalar {.cls character}", error_class = NULL )
obj |
< |
error_message |
< |
error_class |
< |
Other scalar-assertions:
assert_is_bool()
,
assert_is_scalar_double()
,
assert_is_scalar_integerish()
,
assert_is_scalar_integer()
,
assert_is_scalar_logical()
,
assert_is_scalar_numeric()
,
assert_is_scalar_raw()
,
assert_is_string()
Raises an assertion error when !rlang::is_scalar_double(obj)
.
assert_is_scalar_double( obj, error_message = "{.arg obj} must be a scalar {.cls double}", error_class = NULL )
assert_is_scalar_double( obj, error_message = "{.arg obj} must be a scalar {.cls double}", error_class = NULL )
obj |
< |
error_message |
< |
error_class |
< |
Other scalar-assertions:
assert_is_bool()
,
assert_is_scalar_character()
,
assert_is_scalar_integerish()
,
assert_is_scalar_integer()
,
assert_is_scalar_logical()
,
assert_is_scalar_numeric()
,
assert_is_scalar_raw()
,
assert_is_string()
Raises an assertion error when !rlang::is_scalar_integer(obj)
.
assert_is_scalar_integer( obj, error_message = "{.arg obj} must be a scalar {.cls integer}", error_class = NULL )
assert_is_scalar_integer( obj, error_message = "{.arg obj} must be a scalar {.cls integer}", error_class = NULL )
obj |
< |
error_message |
< |
error_class |
< |
Other scalar-assertions:
assert_is_bool()
,
assert_is_scalar_character()
,
assert_is_scalar_double()
,
assert_is_scalar_integerish()
,
assert_is_scalar_logical()
,
assert_is_scalar_numeric()
,
assert_is_scalar_raw()
,
assert_is_string()
Raises an assertion error when !rlang::is_scalar_integerish(obj)
.
assert_is_scalar_integerish( obj, error_message = "{.arg obj} must be a scalar {.cls integerish}", error_class = NULL )
assert_is_scalar_integerish( obj, error_message = "{.arg obj} must be a scalar {.cls integerish}", error_class = NULL )
obj |
< |
error_message |
< |
error_class |
< |
Other scalar-assertions:
assert_is_bool()
,
assert_is_scalar_character()
,
assert_is_scalar_double()
,
assert_is_scalar_integer()
,
assert_is_scalar_logical()
,
assert_is_scalar_numeric()
,
assert_is_scalar_raw()
,
assert_is_string()
Raises an assertion error when !rlang::is_scalar_logical(obj)
.
assert_is_scalar_logical( obj, error_message = "{.arg obj} must be a scalar {.cls logical}", error_class = NULL )
assert_is_scalar_logical( obj, error_message = "{.arg obj} must be a scalar {.cls logical}", error_class = NULL )
obj |
< |
error_message |
< |
error_class |
< |
Other scalar-assertions:
assert_is_bool()
,
assert_is_scalar_character()
,
assert_is_scalar_double()
,
assert_is_scalar_integerish()
,
assert_is_scalar_integer()
,
assert_is_scalar_numeric()
,
assert_is_scalar_raw()
,
assert_is_string()
Raises an assertion error when !is.numeric(obj) || length(obj) != 1L
.
assert_is_scalar_numeric( obj, error_message = "{.arg obj} must be a scalar {.cls numeric}", error_class = NULL )
assert_is_scalar_numeric( obj, error_message = "{.arg obj} must be a scalar {.cls numeric}", error_class = NULL )
obj |
< |
error_message |
< |
error_class |
< |
Other scalar-assertions:
assert_is_bool()
,
assert_is_scalar_character()
,
assert_is_scalar_double()
,
assert_is_scalar_integerish()
,
assert_is_scalar_integer()
,
assert_is_scalar_logical()
,
assert_is_scalar_raw()
,
assert_is_string()
Raises an assertion error when !rlang::is_scalar_raw(obj)
.
assert_is_scalar_raw( obj, error_message = "{.arg obj} must be a scalar {.cls raw}", error_class = NULL )
assert_is_scalar_raw( obj, error_message = "{.arg obj} must be a scalar {.cls raw}", error_class = NULL )
obj |
< |
error_message |
< |
error_class |
< |
Other scalar-assertions:
assert_is_bool()
,
assert_is_scalar_character()
,
assert_is_scalar_double()
,
assert_is_scalar_integerish()
,
assert_is_scalar_integer()
,
assert_is_scalar_logical()
,
assert_is_scalar_numeric()
,
assert_is_string()
Raises an assertion error when !rlang::is_string(obj)
.
assert_is_string( obj, error_message = "{.arg obj} must be a {.cls string}", error_class = NULL )
assert_is_string( obj, error_message = "{.arg obj} must be a {.cls string}", error_class = NULL )
obj |
< |
error_message |
< |
error_class |
< |
Other scalar-assertions:
assert_is_bool()
,
assert_is_scalar_character()
,
assert_is_scalar_double()
,
assert_is_scalar_integerish()
,
assert_is_scalar_integer()
,
assert_is_scalar_logical()
,
assert_is_scalar_numeric()
,
assert_is_scalar_raw()
Raises an assertion error when typeof(obj) != type
.
assert_is_typeof( obj, type, error_message = "{.arg obj} must be of type {.cls {type}}", error_class = NULL )
assert_is_typeof( obj, type, error_message = "{.arg obj} must be of type {.cls {type}}", error_class = NULL )
obj |
< |
type |
< |
error_message |
< |
error_class |
< |
Other type-assertions:
assert_inherits()
,
assert_is_character()
,
assert_is_double()
,
assert_is_integerish()
,
assert_is_integer()
,
assert_is_logical()
,
assert_is_numeric()
,
assert_is_raw()
Raises an assertion error when !all(a < b)
assert_less( a, b, error_message = "{.arg a} must be less than {.arg b}", error_class = NULL )
assert_less( a, b, error_message = "{.arg a} must be less than {.arg b}", error_class = NULL )
a |
< |
b |
< |
error_message |
< |
error_class |
< |
Other logical-assertions:
assert_equal()
,
assert_greater_equal()
,
assert_greater()
,
assert_less_equal()
,
assert_not_equal()
,
assert_range()
Raises an assertion error when !all(a <= b)
assert_less_equal( a, b, error_message = "{.arg a} must be less than or equal {.arg b}", error_class = NULL )
assert_less_equal( a, b, error_message = "{.arg a} must be less than or equal {.arg b}", error_class = NULL )
a |
< |
b |
< |
error_message |
< |
error_class |
< |
Other logical-assertions:
assert_equal()
,
assert_greater_equal()
,
assert_greater()
,
assert_less()
,
assert_not_equal()
,
assert_range()
Raises an assertion error when !all(a != b)
assert_not_equal( a, b, error_message = "{.arg a} must not equal {.arg b}", error_class = NULL )
assert_not_equal( a, b, error_message = "{.arg a} must not equal {.arg b}", error_class = NULL )
a |
< |
b |
< |
error_message |
< |
error_class |
< |
Other logical-assertions:
assert_equal()
,
assert_greater_equal()
,
assert_greater()
,
assert_less_equal()
,
assert_less()
,
assert_range()
Raises an assertion error when anyNA(obj)
assert_not_na( obj, error_message = "{.arg obj} must be not contain {.code NA}", error_class = NULL )
assert_not_na( obj, error_message = "{.arg obj} must be not contain {.code NA}", error_class = NULL )
obj |
< |
error_message |
< |
error_class |
< |
Other assertions:
assert_not_null()
Raises an assertion error when is.null(obj)
assert_not_null( obj, error_message = "{.arg obj} must be not {.code NULL}", error_class = NULL )
assert_not_null( obj, error_message = "{.arg obj} must be not {.code NULL}", error_class = NULL )
obj |
< |
error_message |
< |
error_class |
< |
Other assertions:
assert_not_na()
Raises an assertion error when !all(a >= min & a <= max)
assert_range( obj, min, max, error_message = "{.arg obj} must be within [{.arg min}, {.arg max}]", error_class = NULL )
assert_range( obj, min, max, error_message = "{.arg obj} must be within [{.arg min}, {.arg max}]", error_class = NULL )
obj |
< |
min |
< |
max |
< |
error_message |
< |
error_class |
< |
Other logical-assertions:
assert_equal()
,
assert_greater_equal()
,
assert_greater()
,
assert_less_equal()
,
assert_less()
,
assert_not_equal()
Raises an assertion warning when any(expr)
is false.
Raises an assertion warning when all(expr)
is true.
warn_if_not( expr, warn_message = NULL, warn_class = NULL, call = rlang::caller_call(), env = rlang::caller_env(), print_expr = NULL, ... ) warn_if( expr, warn_message = NULL, warn_class = NULL, call = rlang::caller_call(), env = rlang::caller_env(2L), print_expr = NULL, ... )
warn_if_not( expr, warn_message = NULL, warn_class = NULL, call = rlang::caller_call(), env = rlang::caller_env(), print_expr = NULL, ... ) warn_if( expr, warn_message = NULL, warn_class = NULL, call = rlang::caller_call(), env = rlang::caller_env(2L), print_expr = NULL, ... )
expr |
< |
warn_message |
< |
warn_class |
< |
call |
The execution environment of a currently running
function, e.g. You only need to supply Can also be |
env |
< |
print_expr |
< |
... |
< |