Description Usage Arguments Details Value Checking NULL values Examples
Check types and lengths of R objects. Decide whether NA values should be valid inputs or not.
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 | isNull(x)
isLgl(x, targetLength = NULL, acceptNA = TRUE)
isInt(x, targetLength = NULL, acceptNA = TRUE)
isDbl(x, targetLength = NULL, acceptNA = TRUE)
isCpx(x, targetLength = NULL, acceptNA = TRUE)
isChr(x, targetLength = NULL, acceptNA = TRUE)
isRaw(x, targetLength = NULL)
isAtomic(x, targetLength = NULL, acceptNA = TRUE)
isScalarLgl(x, acceptNA = FALSE)
isScalarInt(x, acceptNA = FALSE)
isScalarDbl(x, acceptNA = FALSE)
isScalarCpx(x, acceptNA = FALSE)
isScalarChr(x, acceptNA = FALSE)
isScalarRaw(x)
isScalarAtomic(x, acceptNA = FALSE)
|
x |
Object to be tested. |
targetLength |
Expected length of |
acceptNA |
Can By default, NA are valid values, except when a scalar value is expected. |
Atomic types are abbreviated for brevity:
lgl
stands for "logical"
,
int
stands for "integer"
,
dbl
stands for "double"
,
cpx
stands for "complex"
,
chr
stands for "character"
, and
raw
stands for "raw"
.
What R sometimes call a numeric is just a double: a double-precision vector.
A logical(1)
.
A NULL
's length is always equal to 0. Therefore, isNull()
is just
an alias to function is.null(), and is provided for
convenience. Note that isAtomic(NULL)
yields TRUE
because NULL
is
a degenerate atomic type.
1 2 3 4 5 6 7 8 9 10 11 12 13 | ## Check if a vector contains 3 double values.
isDbl(c(1.0, 1.1, 1.2), 3L)
## Beware of R's implicit conversions. This yields FALSE.
isInt(c(1L, 2, 3L))
## By default, NAs are accepted in vectors.
isInt(c(1L, NA_integer_)) # TRUE
isInt(c(1L, NA_integer_), FALSE) # FALSE
## By default, scalar values cannot be NA.
isScalarInt(NA_integer_) # FALSE
isScalarInt(NA_integer_, TRUE) # TRUE
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.