Skip to contents

Column names travel: they become variable names in analysis scripts, chunk labels and figure file names in generated codebooks, and keys in metadata files. A name that contains characters that are illegal in file names (< > : " / \ | ? *), control characters (tabs, newlines), leading/trailing whitespace, or that runs to hundreds of characters cannot be used in those places without modification – tools either fail (e.g. a figure file cannot be created on Windows) or silently rename the variable so it no longer matches the shared data. Good practice is short names built from letters, digits and underscores.

Usage

data_check_colname(col_name, max_chars = 64L)

Arguments

col_name

the column name

max_chars

names longer than this are flagged as excessively long; the default is SPSS's 64-byte maximum variable-name length (see Details)

Value

list(problem, message, values)

Details

Such names typically signal an upstream problem: a file whose header was not parsed as intended (e.g. a whole header line captured as a single "name"), or export settings that leaked formatting into the header.

The length threshold is not arbitrary: 64 bytes is the maximum variable-name length SPSS supports (https://www.ibm.com/docs/en/spss-statistics/32.0.0?topic=view-variable-names), and SAS and Stata cap names at 32 characters (https://www.stata.com/manuals/rlimits.pdf), so a name over 64 characters cannot be imported into any of the three major statistical packages without being renamed – after which it no longer matches the shared data or its documentation. (DDI-Codebook's var@name documentation still notes names are "usually up to eight characters, following the rules of SAS and SPSS" – a legacy of those systems' old limits, not a modern recommendation, so DDI imposes no constraint of its own.)

This check only warns; nothing is renamed or dropped. (convert_codebook() separately excludes columns whose name would push a generated figure's file path past Windows' 260-character limit – the one case where a name makes rendering impossible; that budget depends on the output path, so it is computed there, not here.)

Author

Daniel Lakens and Levi Baruch

Examples

data_check_colname("this/is:an*illegal|name")$problem
#> [1] TRUE
data_check_colname("reaction_time")$problem
#> [1] FALSE