list_of {vctrs} | R Documentation |
list_of
S3 class for homogenous lists
Description
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.
Usage
list_of(..., .ptype = NULL)
as_list_of(x, ...)
is_list_of(x)
## S3 method for class 'vctrs_list_of'
vec_ptype2(x, y, ..., x_arg = "", y_arg = "")
## S3 method for class 'vctrs_list_of'
vec_cast(x, to, ...)
Arguments
... |
Vectors to coerce. |
.ptype |
If Alternatively, you can supply |
x |
For |
y , to |
Arguments to |
x_arg , y_arg |
Argument names for |
Details
Unlike regular lists, setting a list element to NULL
using [[
does not remove it.
Examples
x <- list_of(1:3, 5:6, 10:15)
if (requireNamespace("tibble", quietly = TRUE)) {
tibble::tibble(x = x)
}
vec_c(list_of(1, 2), list_of(FALSE, TRUE))