get_rename_tribbles: Get code to generate tibbles to rename categorical variables...

get_rename_tribblesR Documentation

Get code to generate tibbles to rename categorical variables and their levels

Description

Renaming categorical variables and their levels, for instance for summary tables, can be fiddly. This function generates code in which only the new names need to be modified, and which can then be passed to either rename_cat_variables() or directly to report_cat_vars()

Usage

get_rename_tribbles(
  data,
  ...,
  show = TRUE,
  which = c("both", "vars", "levels"),
  max_levels = 20
)

Arguments

data

A dataframe that contains the variables - only used to extract their possible levels.

...

The variables to be included in the rename tribbles. If none are specified, all are included, unless there are more than max_level variables in the data

show

Logical - should the output be printed to the console. In any case, it is returned invisibly

which

Should tribble code be generated for variables ("vars"), levels ("levels") or both ("both") (default)

max_levels

The maximum number of levels before a variable is dropped from the levels_tribble. Defaults to 20

Details

Only categorical variables should be passed to the function if code for levels is requested. If a variable has more than 20 distinct values, it is dropped from the levels-tribble-code, unless the max_levels argument is increased.

Value

Code to be edited and passed to tibble::tribble() to create var_names and level_names arguments for rename_cat_variables() and report_cat_vars(). 'New' variable and level names are minimally transformed, but are primarily intended to be placeholders.

Examples

get_rename_tribbles(iris)

LukasWallrich/timesaveR documentation built on Nov. 29, 2024, 4:47 a.m.