df_list: Collect columns for data frame construction

Description Usage Arguments Properties See Also Examples

View source: R/type-data-frame.R

Description

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

1
2
3
4
5
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 .... If NULL, this will be computed as the common size of the inputs.

.name_repair

One of "check_unique", "unique", "universal" or "minimal". See vec_as_names() for the meaning of these options.

Properties

See Also

new_data_frame() for constructing data frame subclasses from a validated input. data_frame() for a fast data frame creation helper.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# `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)

vctrs documentation built on April 29, 2021, 5:08 p.m.