Skip to contents

Many tools replace the special characters in a variable name with _ or drop them: R's make.names(), SPSS/SAS/Stata on import, and generated codebooks (section ids, figure file names). Two columns whose names differ only in special characters – e.g. the phoneme symbols t' and a t-with-diacritic, which both sanitize to t_ – therefore become indistinguishable the moment the data leave the original file, and links or merged results silently point at the wrong variable. Identical duplicate names collide trivially and are flagged too.

Usage

data_check_colname_collisions(col_names)

Arguments

col_names

character vector of a file's column names

Value

a named list mapping each colliding column name to a message (empty list when all names stay distinct)

Details

The sanitization mirrored here (every character that is not a Unicode letter or digit becomes _) is the one the codebook package uses for its section ids, where collisions surface as pandoc "Duplicate identifier" warnings.

Examples

# "score 1" and "score_1" both become "score_1" when special characters
# are replaced
data_check_colname_collisions(c("score 1", "score_1", "age"))
#> $`score 1`
#> [1] "Column name becomes \"score_1\" when special characters are replaced, the same as \"score_1\": tools that sanitize names (R's make.names(), SPSS/SAS/Stata import, codebook section links) cannot tell these columns apart."
#> 
#> $score_1
#> [1] "Column name becomes \"score_1\" when special characters are replaced, the same as \"score 1\": tools that sanitize names (R's make.names(), SPSS/SAS/Stata import, codebook section links) cannot tell these columns apart."
#>