Description Usage Arguments Details Value Checking NA values Checking NULL values Note Examples
Check types and lengths of R objects.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | is_nul(x)
is_lgl(x, n = NULL, .na = TRUE)
is_int(x, n = NULL, .na = TRUE)
is_dbl(x, n = NULL, .na = TRUE)
is_num(x, n = NULL, .na = TRUE)
is_cpx(x, n = NULL, .na = TRUE)
is_chr(x, n = NULL, .na = TRUE)
is_ato(x, n = NULL, .na = TRUE)
is_lst(x, n = NULL, .na = TRUE)
is_scalar_lgl(x, .na = FALSE)
is_scalar_int(x, .na = FALSE)
is_scalar_dbl(x, .na = FALSE)
is_scalar_num(x, .na = FALSE)
is_scalar_cpx(x, .na = FALSE)
is_scalar_chr(x, .na = FALSE)
is_scalar_ato(x, .na = FALSE)
is_scalar_lst(x, .na = FALSE)
|
x |
Object to be tested. |
n |
The desired length of |
.na |
Can |
Types are abbreviated for convenience and consistency:
nul
stands for "NULL"
,
lgl
stands for "logical"
,
int
stands for "integer"
,
num
stands for "numeric"
,
dbl
stands for "double"
,
cpx
stands for "complex"
,
chr
stands for "character"
,
ato
stands for "atomic"
, and
lst
stands for "list"
.
An atomic vector is either a NULL
or any
of these base types: "logical"
, "integer"
, "double"
, "complex"
,
"character"
, and "raw"
. Raw vectors are out of scope.
What R sometimes call a numeric is just a
double (or a "real"
) value: a double-precision vector.
Package dotprofile sticks to the conventional "double"
name.
Therefore, functions is_num()
and is_scalar_num()
are respectively
identical to functions is_dbl()
and is_scalar_dbl()
.
A logical(1)
.
By default, NA values are
valid values, except when a scalar value is expected. In that case,
they are invalid. This assumption can easily be changed via argument
.na
.
When checking for NA values in a list,
is_lst()
and is_scalar_lst()
do not recurse into their
recursive elements.
It makes no sense to check for a NULL
's
length, because it is always equal to 0. Therefore, is_nul()
is just
an alias to function is.null(), and is provided for
convenience.
Keep in mind that is_ato(NULL)
yields TRUE
because NULL
is a
degenerate atomic type. However, is_ato(NULL, 1L)
always yields
FALSE
, because of NULL
's implicit length.
Introspector functions of dotprofile are equivalent to what rlang typically offers, both in terms of performance and convenience. However, managing R dependencies can be a big mess in production, so dotprofile tries hard to avoid relying on other packages when it is not absolutely required.
1 2 3 4 5 6 7 8 9 10 11 12 13 | ## Check if a vector contains 3 double values.
is_dbl(c(1.0, 1.1, 1.2), 3L)
## Beware of R implicit conversions. This yields FALSE.
is_int(c(1L, 2, 3L))
## By default, NAs are accepted in vectors.
is_int(c(1L, NA_integer_)) # TRUE
is_int(c(1L, NA_integer_), FALSE) # FALSE
## By default, scalar values cannot be NA.
is_scalar_int(NA_integer_) # FALSE
is_scalar_int(NA_integer_, TRUE) # TRUE
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.