introspectors: Introspectors

Description Usage Arguments Details Value Checking NULL values Examples

Description

Check types and lengths of R objects. Decide whether NA values should be valid inputs or not.

Usage

 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)

Arguments

x

[any]

Object to be tested.

targetLength

[NULL | integer(1) | double(1)]

Expected length of x. If NULL, no length is enforced. This parameter is automatically coerced to an integer.

acceptNA

[logical(1)]

Can x contain NA values? Note that it makes no sense to check for NA values in a raw vector.

By default, NA are valid values, except when a scalar value is expected.

Details

Atomic types are abbreviated for brevity:

What R sometimes call a numeric is just a double: a double-precision vector.

Value

A logical(1).

Checking NULL values

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.

Examples

 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

jeanmathieupotvin/nanocli documentation built on Feb. 2, 2022, 11:30 p.m.