Check that a vector contains only certain values.

chk_equals(x, val)

chk_values(x, ..., miss = getOption("testdat.miss"))

chk_range(x, min, max, ...)

chk_blank(x)

Arguments

x

A vector to check.

val

A scalar value for the equality check.

...

Vectors of valid values.

miss

A vector of values to be treated as missing. The testdat.miss or testdat.miss_text option is used by default.

min

Minimum value for range check.

max

Maximum value for range check.

Value

A logical vector flagging records that have passed or failed the check.

Examples


x <- c(NA, 0, 1, 0.5, 0, NA, 99)
chk_blank(x) # Blank
#> [1]  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE
chk_equals(x, 0) # Either blank or 0
#> [1]  TRUE  TRUE FALSE FALSE  TRUE  TRUE FALSE
chk_values(x, 0, 1) # Either blank, 0, 1, or 99
#> [1]  TRUE  TRUE  TRUE FALSE  TRUE  TRUE FALSE
chk_range(x, 0, 1) # Either blank or in [0,1]
#> [1]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE
chk_range(x, 0, 1, 99) # Either blank, in [0,1], or equal to 99
#> [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE