% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/core-metadata.R
\name{classify_question_type}
\alias{classify_question_type}
\title{Classify Variable Question Types}
\usage{
classify_question_type(x, ..., variable = NULL)
}
\arguments{
\item{x}{A survey design object or \code{data.frame}.}

\item{...}{<\code{\link[tidyselect:language]{tidy-select}}> Variables to classify.
Supports selection helpers: \code{\link[tidyselect:starts_with]{tidyselect::starts_with()}},
\code{\link[tidyselect:all_of]{tidyselect::all_of()}}, \code{\link[tidyselect:all_of]{tidyselect::any_of()}}, etc. Cannot be combined
with \code{variable}.}

\item{variable}{\code{character}. Alternative programmatic interface: character
vector of variable names. Cannot be combined with \code{...}.}
}
\value{
A tibble with columns:
\itemize{
\item \code{variable} (character) — variable name
\item \code{question_preface} (character) — the preface, or \code{NA} if none
\item \code{type} (character) — one of \code{"single"}, \code{"sata"}, or \code{"battery"}
\item \code{group} (integer) — group id; variables with the same non-NA preface
share a group
}
}
\description{
Groups variables by their shared \code{question_preface} metadata and classifies
each group as one of \code{"single"}, \code{"sata"}, or \code{"battery"}. This is the single
source of truth used by downstream export functions to decide how to render
each question.
}
\details{
The classification rules, applied per requested variable:
\enumerate{
\item If the variable has no \code{question_preface}, or is the only requested
variable sharing its preface, \code{type = "single"}.
\item If a \code{question_preface} is shared by 2+ requested variables and at least
one is flagged via \code{\link[=set_sata]{set_sata()}}, all variables in that group get
\code{type = "sata"}.
\item Otherwise (shared preface, no SATA flag), all variables in the group
get \code{type = "battery"}.
}

Group numbers are assigned sequentially by first appearance in the input.
}
\examples{
d <- as_survey(nhanes_2017, ids = sdmvpsu, weights = wtint2yr,
               strata = sdmvstra, nest = TRUE)
d <- set_question_preface(d, riagendr = "Demographics",
                             ridageyr = "Demographics")
d <- set_sata(d, riagendr, ridageyr)
classify_question_type(d, riagendr, ridageyr, bpxsy1)

}
\seealso{
\code{\link[=set_sata]{set_sata()}}, \code{\link[=extract_sata]{extract_sata()}}, \code{\link[=set_question_preface]{set_question_preface()}}

Other metadata: 
\code{\link{extract_metadata}()},
\code{\link{extract_missing_codes}()},
\code{\link{extract_question_preface}()},
\code{\link{extract_sata}()},
\code{\link{extract_universe}()},
\code{\link{extract_val_labels}()},
\code{\link{extract_var_label}()},
\code{\link{extract_var_note}()},
\code{\link{infer_question_prefaces}()},
\code{\link{set_missing_codes}()},
\code{\link{set_question_preface}()},
\code{\link{set_sata}()},
\code{\link{set_universe}()},
\code{\link{set_val_labels}()},
\code{\link{set_var_label}()},
\code{\link{set_var_note}()},
\code{\link{survey_metadata}()},
\code{\link{survey_weighting_history}()}
}
\concept{metadata}
