Add variable attributes to an ARD data frame.
The
label
attribute will be added for all columns, and when no label is specified and no label has been set for a column using thelabel=
argument, the column name will be placed in the label statistic.The
class
attribute will also be returned for all columns.Any other attribute returned by
attributes()
will also be added, e.g. factor levels.
Usage
ard_attributes(data, variables = everything(), label = NULL)
Arguments
- data
(
data.frame
)
a data frame- variables
(
tidy-select
)
variables to include- label
(named
list
)
named list of variable labels, e.g.list(cyl = "No. Cylinders")
. Default isNULL
Examples
df <- dplyr::tibble(var1 = letters, var2 = LETTERS)
attr(df$var1, "label") <- "Lowercase Letters"
ard_attributes(df, variables = everything())
#> {cards} data frame: 4 x 5
#> variable stat_name stat stat_label context
#> 1 var1 label Lowercas… Variable… attribut…
#> 2 var1 class character Variable… attribut…
#> 3 var2 label var2 Variable… attribut…
#> 4 var2 class character Variable… attribut…