has_names: Checks the variable structure

Description Usage Arguments Details Value See Also Examples

View source: R/predicates.R

Description

This function returns TRUE if the variable structure is correct and FALSE otherwise.

Usage

1
2
3
has_names(x, names = NULL)

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

Arguments

x

(any) The object to test

names

(character, optional) The names to check for. If NULL the names are not checked. Default: NULL.

n

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

n_min

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

n_max

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

Details

The following structures can be checked:

Value

TRUE if x has names, FALSE otherwise

See Also

rlang::is_empty()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# TRUE
has_names(list(a = 1, b = 2))
has_names(list(a = 1, b = 2), "a")
has_names(list(a = 1, b = 2), c("a", "b"))
# FALSE
has_names(list(a = 1, b = 2), "c")
has_names(list(a = 1, b = 2), c("b", "c"))

# TRUE
has_length(1, 1)
has_length(c("bob", "jane"), 2)
has_length(list(x = 1, y = 2, z = 3), 3)
has_length(1:3, n_min = 2)
has_length(1:3, n_max = 10)
# FALSE
has_length(1:3, 1)
has_length(c("bob", "jane"), 3)
has_length(list(x = 1, y = 2, z = 3), 5)
has_length("A", n_min = 2)
has_length(LETTERS, n_max = 10)

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