% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lpr_extract_ros.R
\name{lpr_extract_ros}
\alias{lpr_extract_ros}
\title{Extract Response Option (RO) values and texts for all variables into a tidy table.}
\usage{
lpr_extract_ros(
  data,
  lang_id = "en",
  include_special = FALSE,
  restrict_to_present = TRUE,
  one_row_per_var = FALSE,
  pair_sep = " | ",
  attr_name = "label.table"
)
}
\arguments{
\item{data}{A data.frame read with readstata13/haven/etc.}

\item{lang_id}{Language code used in label table names ("en", "es", "pt").
If `NULL` or `""`, auto-detect per variable (dataset-level only). Ignored for per-variable `levels`.}

\item{include_special}{Logical; if FALSE, drop codes >= 1000 when codes are numeric. Default FALSE.}

\item{restrict_to_present}{Logical; if TRUE, keep only codes that appear in the data. Default TRUE.}

\item{one_row_per_var}{Logical; if TRUE, return one row per variable_name with concatenated ROs. Default FALSE.}

\item{pair_sep}{String used to separate each "(value) answer_text" pair when collapsing. Default " | ".}

\item{attr_name}{Name of the attribute that stores RO info. Default "label.table".}
}
\value{
If `one_row_per_var = FALSE`: tibble with columns `variable_name`, `value`, `answer_text`.
If `one_row_per_var = TRUE`: tibble with columns `variable_name`, `answer_text` (collapsed pairs).
}
\description{
Works with:
 (a) dataset-level dictionaries (e.g., attr(data, "label.table") is a list keyed by "<VAR>_<lang>"), or
 (b) per-variable attributes (e.g., attr(data[[VAR]], "levels") or factor levels).
}
\examples{
toy <- data.frame(
  ing4 = c(1L, 2L, 1L),
  b12 = c(1L, 2L, NA_integer_)
)
attr(toy, "label.table") <- list(
  ing4_pt = c("Apoia muito" = 1L, "Apoia" = 2L, "NS/NR" = 1000L),
  b12_pt = c("Muito" = 1L, "Algo" = 2L, "NS/NR" = 1000L)
)

lpr_extract_ros(toy, lang_id = "pt")
lpr_extract_ros(toy, lang_id = "pt", one_row_per_var = TRUE)

}
\author{
Robert Vidigal, \email{robert.vidigal@vanderbilt.edu}
}
