Renames columns from the raw UKB field ID format used by
extract_pheno (e.g. participant.p31) and
job_result (e.g. p53_i0) to human-readable
snake_case identifiers (e.g. sex,
date_of_attending_assessment_centre_i0).
Arguments
- data
(data.frame or data.table) Data extracted from UKB-RAP via
extract_pheno()orjob_result().- max_nchar
(integer) Column names longer than this value are flagged. Default:
60.
Value
The input data with column names replaced by snake_case
labels. Returns a data.table if the input is a data.table.
Details
Column labels are taken from the UKB field title dictionary via
extract_ls. Both the dataset name and field list are cached
after the first call, so subsequent calls to decode_names() involve
no network requests.
When an auto-generated name exceeds max_nchar characters it is
flagged with a warning so you can decide whether to shorten it manually
with names(data)[...] <- .... The function never truncates names
automatically, because the right short name depends on scientific context
that only you know.
Examples
if (FALSE) { # \dontrun{
df <- extract_pheno(c(31, 53, 21022))
df <- decode_names(df)
# participant.eid → eid
# participant.p31 → sex
# participant.p21022 → age_at_recruitment
# participant.p53_i0 → date_of_attending_assessment_centre_i0 (warned if > 60)
# Shorten a long name afterwards
names(df)[names(df) == "date_of_attending_assessment_centre_i0"] <- "date_baseline"
} # }
