Sanitize character vector, for instance useful for variable label in labelled::update_variable_labels_with()
Source: R/sanitize_character_vector.R
sanitize_chr_vec.RdSanitize character vector, for instance useful for variable label in labelled::update_variable_labels_with()
Usage
sanitize_chr_vec(
x,
sep = " - ",
multi_sep_replacement = ": ",
replace_ascii_with_utf = FALSE
)Examples
# Example 1: Basic usage
input <- c("<b>Bold</b>", " Extra spaces ", "- Selected Choice -")
sanitize_chr_vec(input)
#> [1] "Bold" "Extra spaces" ""
# Example 2: Replace ASCII with UTF
input <- c("À", "É", "Ö")
sanitize_chr_vec(input, replace_ascii_with_utf = TRUE)
#> [1] "À" "É" "Ö"
# Example 3: Custom separators
input <- c("Question - Subquestion", "Another - Example")
sanitize_chr_vec(input, sep = " - ", multi_sep_replacement = ": ")
#> [1] "Question - Subquestion" "Another - Example"