This function generates a hierarchical procr_varformat object where each unique
value of a column in df is converted into a separate entry. Essentially, it wraps
new_format() for "as-is" value-to-label conversion.
Usage
new_format_asis(
df,
var,
...,
name = NULL,
add_total = FALSE,
total_subset_label = "davon",
include_na = TRUE
)Arguments
- df
data.framecontaining the variable to format.- var
Unquoted column name in
dfto convert to a variable format.- ...
One or more variable format entries, which can be:
Character string representing parent of collectively exhaustive subsets (must be followed by a list with subsets).
Two-sided formula specifying
code ~ labelorlabel ~ code. The following shorthand codes are allowed:7for. == 7c(7, 9)for. %in% c(7, 9)7:9for. %in% 7:9
List representing subsets of the previous entry, with an attribute
subsetcontaining logical valuesexhaustiveanddisjoint.
- name
Name for the resulting variable format as character string. If
name = NULL(default) andvaris provided, a name is generated fromvar. Eithernameorvarmust be provided.- add_total
Logical or character. Adds a row with the total for disjoint subsets at the top.
TRUEgenerates a row named "Total"; a string provides a custom label.FALSE(default) adds no row. Mutually exclusive withadd_total_overlapping.- total_subset_label
Character. Label to be used for subsets of total added by
add_totaloradd_total_overlapping.- include_na
Logical; if
TRUE,NAvalues are included.
Examples
df <- data.frame(status = c("A", "B", "A", NA))
fmt <- new_format_asis(df, status, add_total = TRUE)
fmt
#> status code
#> ╲╴Total status %in% "A" | status %in% "B" | status %in% NA_character_
#> ├╴A status %in% "A"
#> ├╴B status %in% "B"
#> └╴NA status %in% NA_character_
#>