Description Usage Arguments Value See Also Examples
Tests if all elements of a list are a specific type. is_list_of
accepts any
test function. is_list_of_lists()
tests if all elements are lists.
is_list_of_characters()
tests if all elements are character vectors.
1 2 3 4 5 | is_list_of(input, test)
is_list_of_lists(input)
is_list_of_characters(input)
|
input |
List to test |
test |
Test function to apply to each element of |
A logical value. If input
is not a list, FALSE
and a warning.
is.list()
to test if an input is a list
purrr::flatten()
or rlang::flatten()
to remove a level of hierarchy
from a list
rlang::squash()
to remove all levels of hierarchy from a list
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 | list_of_lists <- list(as.list(letters[1:4]), as.list(1:4))
list_of_characters <- list(letters[1:4], LETTERS[1:4])
list_of_integers <- list(1:4, 5:8)
# Test if all elements of a list are lists
is_list_of_lists(list_of_lists)
is_list_of_lists(list_of_characters)
is_list_of_lists(list_of_integers)
# Test if all elements of a list are character vectors
is_list_of_characters(list_of_lists)
is_list_of_characters(list_of_characters)
is_list_of_characters(list_of_integers)
# Use any test function to test all elements of a list...
# ... with a function name
is_list_of(list_of_integers, is.integer)
# ... an anonymous function
is_list_of(list_of_integers, function(x) all(x %% 1 == 0))
# ... or a purrr-style lambda
is_list_of(list_of_integers, ~ all(. %% 1 == 0))
# All functions give a warning and return FALSE if their input is not a list
is_list_of_lists(1:4)
is_list_of_characters(1:4)
is_list_of(1:4, is.integer)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.