Description Usage Arguments Details Value See Also Examples
This function returns TRUE
if the variable structure is correct and FALSE
otherwise.
1 2 3 |
x |
(any) The object to test |
names |
(character, optional) The names to check for. If |
n |
(integer, optional) The allowed length. If |
n_min |
(integer, optional) The allowed minimum length. If |
n_max |
(integer, optional) The allowed maximum length. If |
The following structures can be checked:
has_names()
: 'x' must have names and optionally have the specified
names
. A logical vector is returned checking each name.
has_length()
: 'x' must have valid length. You can specify the exact
length using n
or the minimum and/or maximum length using n_min
and
n_max
respectively.
TRUE if x has names, FALSE otherwise
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.