is_na: Checks the variable values

Description Usage Arguments Details Value Examples

View source: R/predicates.R

Description

This function returns TRUE if the variable values are correct and FALSE otherwise.

Usage

1
2
3
4
5
6
7
is_na(x)

is_in(x, values)

is_in_range(x, min = NULL, max = NULL)

has_char_length(x, n = NULL, n_min = NULL, n_max = NULL)

Arguments

x

(any) The object with elements to test

values

(any) The allowed (or not allowed) values.

min

(numeric, optional) The minimum allowed value for a range. If NULL the minimum value is not checked. Default: NULL.

max

(numeric, optional) The maximum allowed value for a range. If NULL the maximum value is not checked. Default: NULL.

n

(integer, optional) The allowed length. If NULL the exact character length is not checked. Default: NULL.

n_min

(integer, optional) The allowed minimum length. If NULL the minimum character length is not checked. Default: NULL.

n_max

(integer, optional) The allowed maximum length. If NULL the maximum character length is not checked. Default: NULL.

Details

The following values can be checked:

Value

TRUE if elements in x are in y, FALSE otherwise

Examples

 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
34
# TRUE
is_na(NA)
is_na(c(NA, NA))
# FALSE
is_na(NULL)
is_na(1)
is_na("foo")
is_na(c(1, NA))

# TRUE
is_in("a", letters)
is_in(c("a", "b", "c"), letters)
# FALSE
is_in(1, LETTERS)
is_in(1:2, LETTERS)

# TRUE
is_in_range(1, min = 0)
is_in_range(c(1.1, 2.2, 3.3), min = 0, max = 10)
# FALSE
is_in_range(0, min = 1)
is_in_range(c(1.1, 2.2, 3.3), min = 2, max = 3)

# TRUE
has_char_length("", 0)
has_char_length(c("some", "text"), 4)
has_char_length(c("some", "text"), n_min = 1)
has_char_length(c("some", "text"), n_max = 10)
has_char_length(c("some", "text"), n_min = 1, n_max = 10)
# FALSE
has_char_length("sometext", 4)
has_char_length(c("different", "text"), n_min = 5)
has_char_length(c("different", "text"), n_max = 5)
has_char_length(c("different", "text"), n_min = 5, n_max = 8)

ChadGoymer/msgr documentation built on April 10, 2021, 10:31 a.m.