obj_is_list()tests ifxis considered a list in the vctrs sense. It returnsTRUEif:xis a bare list with no class.xis a list explicitly inheriting from"list".
list_all_vectors()takes a list and returnsTRUEif all elements of that list are vectors.list_all_size()takes a list and returnsTRUEif all elements of that list have the samesize.obj_check_list(),list_check_all_vectors(), andlist_check_all_size()use the above functions, but throw a standardized and informative error if they returnFALSE.
Usage
obj_is_list(x)
obj_check_list(x, ..., arg = caller_arg(x), call = caller_env())
list_all_vectors(x)
list_check_all_vectors(x, ..., arg = caller_arg(x), call = caller_env())
list_all_size(x, size)
list_check_all_size(x, size, ..., arg = caller_arg(x), call = caller_env())Arguments
- x
For
vec_*()functions, an object. Forlist_*()functions, a list.- ...
These dots are for future extensions and must be empty.
- arg
An argument name as a string. This argument will be mentioned in error messages as the input that is at the origin of a problem.
- call
The execution environment of a currently running function, e.g.
caller_env(). The function will be mentioned in error messages as the source of the error. See thecallargument ofabort()for more information.- size
The size to check each element for.
Examples
obj_is_list(list())
#> [1] TRUE
obj_is_list(list_of(1))
#> [1] TRUE
obj_is_list(data.frame())
#> [1] FALSE
list_all_vectors(list(1, mtcars))
#> [1] TRUE
list_all_vectors(list(1, environment()))
#> [1] FALSE
list_all_size(list(1:2, 2:3), 2)
#> [1] TRUE
list_all_size(list(1:2, 2:4), 2)
#> [1] FALSE
# `list_`-prefixed functions assume a list:
try(list_all_vectors(environment()))
#> Error in list_all_vectors(environment()) :
#> `x` must be a list, not an environment.
