assert_not() is the inverse of a single specification: it errors when x
would be accepted by spec, and returns x unchanged otherwise.
Usage
assert_not(
x,
spec,
...,
x_arg = caller_arg(x),
call = caller_env(),
x_class = object_type(x)
)Arguments
- x
The object to stabilize.
- spec
A single stabilizer function,
to_*function,specify_*()result, orassert_*function thatxmust not match.- ...
Reserved for future use; must be empty.
- x_arg
(
character(1)) The name of the object being stabilized to use in error messages. The automatic value will work in most cases, or pass it through from higher-level functions to make error messages clearer in unexported functions.- call
(environment)The execution environment to mention as the source of error messages.- x_class
(
character(1)) The class name of the object being stabilized to use in error messages. Use this if you remove a special class from the object before checking its coercion, but want the error message to match the original class.
Value
x, unchanged, if x does not match spec, or an error
condition with classes <stbl-error>, <stbl-condition>,
<rlang_error>, <error>, <condition>, and
<stbl-error-matched_spec> when x matches spec.
See also
Other stabilization functions:
assert_contains(),
assert_present(),
stabilize_all_of(),
stabilize_any_of(),
stabilize_arg(),
stabilize_chr(),
stabilize_chr_scalar(),
stabilize_date(),
stabilize_date_scalar(),
stabilize_dbl(),
stabilize_dbl_scalar(),
stabilize_df(),
stabilize_dttm(),
stabilize_dttm_scalar(),
stabilize_dur(),
stabilize_dur_scalar(),
stabilize_fct(),
stabilize_fct_scalar(),
stabilize_int(),
stabilize_int_scalar(),
stabilize_lgl(),
stabilize_lgl_scalar(),
stabilize_lst(),
stabilize_one_of(),
stabilize_time(),
stabilize_time_scalar(),
to_chr(),
to_chr_scalar(),
to_date(),
to_date_scalar(),
to_dbl(),
to_dbl_scalar(),
to_dttm(),
to_dttm_scalar(),
to_dur(),
to_dur_scalar(),
to_fct(),
to_fct_scalar(),
to_int(),
to_int_scalar(),
to_lgl(),
to_lgl_scalar(),
to_time(),
to_time_scalar()
Examples
assert_not("a", specify_int())
#> [1] "a"
assert_not(1.5, stabilize_int)
#> [1] 1.5
# Errors because "1" is int-ish, even though it isn't literally an integer
try(assert_not("1", specify_int()))
#> Error in eval(expr, envir) :
#> `"1"` must not match "specify_int()".
# Errors because stabilize_int() succeeds outright on 1L
try(assert_not(1L, stabilize_int))
#> Error in eval(expr, envir) :
#> `1L` must not match "stabilize_int".