Skip to contents

Check list of lists

Is a given object a list of list elements? This can be checked in three ways as follows:

### L1 is a list of lists
L1 <- list(list(1), list(2), list(3))
check_list_of_lists(L1)
#> [1] TRUE
test_list_of_lists(L1)
#> [1] TRUE
assert_list_of_lists(L1)

### L2 is not a list of lists
L2 <- list(list(1), list(2), 3)
check_list_of_lists(L2)
#> [1] "Check for element 3 failed: Must be of type 'list', not 'double'"
test_list_of_lists(L2)
#> [1] FALSE
assert_list_of_lists(L2)
#> Error in eval(expr, envir, enclos): Assertion on 'L2' failed: Check for element 3 failed: Must be of type 'list', not 'double'.