% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/decode.R
\name{decode_names}
\alias{decode_names}
\title{Rename UKB field ID columns to human-readable snake_case names}
\usage{
decode_names(data, max_nchar = 60L)
}
\arguments{
\item{data}{(data.frame or data.table) Data extracted from UKB-RAP via
\code{extract_pheno()} or \code{job_result()}.}

\item{max_nchar}{(integer) Column names longer than this value are flagged.
Default: \code{60}.}
}
\value{
The input \code{data} with column names replaced by snake_case
labels. Returns a \code{data.table} if the input is a \code{data.table}.
}
\description{
Renames columns from the raw UKB field ID format used by
\code{\link{extract_pheno}} (e.g. \code{participant.p31}) and
\code{\link{job_result}} (e.g. \code{p53_i0}) to human-readable
snake_case identifiers (e.g. \code{sex},
\code{date_of_attending_assessment_centre_i0}).
}
\details{
Column labels are taken from the UKB field title dictionary via
\code{\link{extract_ls}}. Both the dataset name and field list are cached
after the first call, so subsequent calls to \code{decode_names()} involve
no network requests.

When an auto-generated name exceeds \code{max_nchar} characters it is
flagged with a warning so you can decide whether to shorten it manually
with \code{names(data)[...] <- ...}. The function never truncates names
automatically, because the right short name depends on scientific context
that only you know.
}
\examples{
\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"
}
}
