df_list()
constructs the data structure underlying a data
frame, a named list of equal-length vectors. It is often used in
combination with new_data_frame()
to safely and consistently create
a helper function for data frame subclasses.
Usage
df_list(
...,
.size = NULL,
.name_repair = c("check_unique", "unique", "universal", "minimal")
)
Arguments
- ...
Vectors of equal-length. When inputs are named, those names are used for names of the resulting list.
- .size
The common size of vectors supplied in
...
. IfNULL
, this will be computed as the common size of the inputs.- .name_repair
One of
"check_unique"
,"unique"
,"universal"
or"minimal"
. Seevec_as_names()
for the meaning of these options.
Properties
Inputs are recycled to a common size with
vec_recycle_common()
.With the exception of data frames, inputs are not modified in any way. Character vectors are never converted to factors, and lists are stored as-is for easy creation of list-columns.
Unnamed data frame inputs are automatically spliced. Named data frame inputs are stored unmodified as data frame columns.
NULL
inputs are completely ignored.The dots are dynamic, allowing for splicing of lists with
!!!
and unquoting.
See also
new_data_frame()
for constructing data frame subclasses from a validated
input. data_frame()
for a fast data frame creation helper.
Examples
# `new_data_frame()` can be used to create custom data frame constructors
new_fancy_df <- function(x = list(), n = NULL, ..., class = NULL) {
new_data_frame(x, n = n, ..., class = c(class, "fancy_df"))
}
# Combine this constructor with `df_list()` to create a safe,
# consistent helper function for your data frame subclass
fancy_df <- function(...) {
data <- df_list(...)
new_fancy_df(data)
}
df <- fancy_df(x = 1)
class(df)
#> [1] "fancy_df" "data.frame"