Checks if non-missing integer scalar or double equivalent using
vld_number(x) && (is.integer(x) || vld_true(all.equal(x, trunc(x))))
Pass: 1
, 2L
, 1e10
, -Inf
Fail: "a"
, 1:3
, NA_integer_
, log(10)
Value
The chk_
function throws an informative error if the test fails or
returns the original object if successful so it can used in pipes.
The vld_
function returns a flag indicating whether the test was met.
See also
Other chk_scalars:
chk_date()
,
chk_date_time()
,
chk_number()
,
chk_scalar()
,
chk_string()
,
chk_tz()
Examples
# chk_whole_number
chk_whole_number(2)
try(chk_whole_number(1.1))
#> Error in eval(expr, envir) :
#> `1.1` must be a whole number (non-missing integer scalar or double equivalent).
# vld_whole_number
vld_whole_number(2)
#> [1] TRUE