check_list() and check_is_list() functions validate if the
given object is a list and not a dataframe or tibble. check_list()
raises an error if the object is not a list, while check_is_list()
returns TRUE if the object is a list, and FALSE otherwise.
Value
check_list(): Returns the input objectlstif it is a valid list, or raises an error if the object is not a list.check_is_list(): Logical value,TRUEif the object is a list,FALSEotherwise.
Examples
# Examples for check_list()
# -------------------------
check_list(list(1, 2, 3))
#> [[1]]
#> [1] 1
#>
#> [[2]]
#> [1] 2
#>
#> [[3]]
#> [1] 3
#>
try(check_list(data.frame(a = 1:3)))
#> Error in check_list(data.frame(a = 1:3)) :
#> Expected 'lst' to be a list but got data.frame
try(check_list(tibble::tibble(a = 1:3)))
#> Error in check_list(tibble::tibble(a = 1:3)) :
#> Expected 'lst' to be a list but got tbl_df tbl data.frame
check_list(list("a", "b", "c"))
#> [[1]]
#> [1] "a"
#>
#> [[2]]
#> [1] "b"
#>
#> [[3]]
#> [1] "c"
#>
try(check_list(3))
#> Error in check_list(3) : Expected 'lst' to be a list but got numeric
# Examples for check_is_list()
# ----------------------------
check_is_list(list(1, 2, 3))
#> [1] TRUE
check_is_list(data.frame(a = 1:3))
#> [1] FALSE
check_is_list(tibble::tibble(a = 1:3))
#> [1] FALSE
check_is_list(list("a", "b", "c"))
#> [1] TRUE
check_is_list(3)
#> [1] FALSE