Applies a function to the levels of one or more factor columns, replacing them
with the returned labels. .fn receives the character vector of a column's
current levels and must return a character vector of the same length.
Useful for tidying option labels in bulk (trimming, recasing, prefix removal)
while preserving level order and the column's metadata.
Usage
step_relevel(x, .cols = everything(), .fn = NULL, snapshot_data = FALSE)Arguments
- x
A
srv_tblobject.- .cols
Tidy-select expression picking the factor columns. Defaults to every column.
- .fn
A function mapping a character vector of levels to a new character vector of the same length.
- snapshot_data
Logical. If
TRUE, a snapshot with data is taken; ifFALSE, without data; ifNULL, no snapshot.
Examples
if (FALSE) { # \dontrun{
data("srv_example", package = "g6tr.survey")
x <- srv_example |>
step_set_sr("s_gender") |>
step_relevel(s_gender, .fn = toupper)
levels(x$s_gender)
} # }