A list_of object is a list where each element has the same type.
Modifying the list with $, [, and [[ preserves the constraint
by coercing all input items.
list_of(..., .ptype = NULL) as_list_of(x, ...) validate_list_of(x) is_list_of(x) # S3 method for vctrs_list_of vec_ptype2(x, y, ..., x_arg = "", y_arg = "") # S3 method for vctrs_list_of vec_cast(x, to, ...)
| ... | Vectors to coerce. |
|---|---|
| .ptype | If Alternatively, you can supply |
| x | For |
| y, to | Arguments to |
| x_arg | Argument names for |
| y_arg | Argument names for |
Unlike regular lists, setting a list element to NULL using [[
does not remove it.
x <- list_of(1:3, 5:6, 10:15) if (requireNamespace("tibble", quietly = TRUE)) { tibble::tibble(x = x) }#> # A tibble: 3 x 1 #> x #> <list<int>> #> 1 [3] #> 2 [2] #> 3 [6]#> <list_of<double>[4]> #> [[1]] #> [1] 1 #> #> [[2]] #> [1] 2 #> #> [[3]] #> [1] 0 #> #> [[4]] #> [1] 1 #>