% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/read.R
\name{get_data_dictionary}
\alias{get_data_dictionary}
\title{Extract a data dictionary from a CIS study data frame}
\usage{
get_data_dictionary(data)
}
\arguments{
\item{data}{A data.frame loaded from a CIS \code{.sav} file,
typically the output of \code{\link{read_cis}}.}
}
\value{
A tibble with columns:
\describe{
\item{variable}{Variable name.}
\item{label}{Variable label, or \code{NA} if none.}
\item{value_labels}{A named numeric vector of value labels,
or \code{NULL} for unlabelled variables (list-column).}
}
}
\description{
Returns a tibble listing each variable in the data along with its
variable label and value labels, as loaded by \code{haven}.
}
\examples{
# Create a small labelled data frame
df <- data.frame(
  SEXO = haven::labelled(c(1, 2, 1), labels = c(Hombre = 1, Mujer = 2)),
  EDAD = c(34, 51, 29)
)
attr(df$SEXO, "label") <- "Sexo"
attr(df$EDAD, "label") <- "Edad"

# Inspect its variable dictionary
dict <- get_data_dictionary(df)
print(dict)

# Find variables with a specific keyword in their label
dict[grepl("sexo", dict$label, ignore.case = TRUE), ]

# Inspect value labels for a specific variable
sex_var <- match("SEXO", dict$variable)
if (!is.na(sex_var)) {
  dict$value_labels[[sex_var]]
}
}
