Skip to contents

Check for values that differ only in their case

Usage

check_case(x, signal = c("error", "warning", "message", "quiet"))

Arguments

x

Character vector to check.

signal

character string indicating the type of signal to be used: "error" to throw an error, "warning" to issue a warning, "message" to show a message, or "quiet" to be quiet.

Value

A character vector with unique, sorted values in x that only differ from each other in their case, or character(0) if no such values are present, returned invisibly.

Details

Values in x that only differ from each other in their case lead to a signal as indicated by argument signal.

Notes

The sorting order in the result depends on the used locale (see also the section Details of Comparison), which also affects if uppercase characters are sorted before or after lowercase characters.

See also

tolower() and toupper() to change case.

Other functions to check equality: are_equal(), get_file_path(), not_in(), replace_vals()

Examples

x <- c("Ee", "Ee", "LL", "Ll")
try(check_case(x = x, signal = "error"))
#> Error : 'x' contains values that only differ in their case: 'LL', 'Ll'
check_case(x = x, signal = "warning")
#> Warning: 'x' contains values that only differ in their case: 'LL', 'Ll'