Skip to contents

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.frame containing the variable to format.

var

Unquoted column name in df to 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 ~ label or label ~ code. The following shorthand codes are allowed:

    • 7 for . == 7

    • c(7, 9) for . %in% c(7, 9)

    • 7:9 for . %in% 7:9

  • List representing subsets of the previous entry, with an attribute subset containing logical values exhaustive and disjoint.

name

Name for the resulting variable format as character string. If name = NULL (default) and var is provided, a name is generated from var. Either name or var must be provided.

add_total

Logical or character. Adds a row with the total for disjoint subsets at the top. TRUE generates a row named "Total"; a string provides a custom label. FALSE (default) adds no row. Mutually exclusive with add_total_overlapping.

total_subset_label

Character. Label to be used for subsets of total added by add_total or add_total_overlapping.

include_na

Logical; if TRUE, NA values are included.

Value

A procr_varformat object.

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_                                             
#>