% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{combine_checkboxes}
\alias{combine_checkboxes}
\title{Combine checkbox variables into a single list column}
\usage{
combine_checkboxes(data, var_basename, var_sep = "___", name = NULL)
}
\arguments{
\item{data}{tbl. Data frame containing the participant responses.}

\item{var_basename}{character of length 1. The base name of the checkbox
field.}

\item{var_sep}{character of length 1. The string separating the base name
of the checkbox and the checkbox value. Default is \code{"___"}.
In the default scenario, all checkbox columns to be collapsed are expected
in the format, \verb{\{ var_basename \}___\{ value \}}, where three underscores
separate the checkbox basename and the checkbox value.}

\item{name}{character of length 1 or \code{NULL}. Optional. The name of the
output column that will store the combined checkbox selections.
If \code{NULL}, the value of \code{var_basename} is used as the output column name.}
}
\value{
tbl. The input data frame with an additional column containing a list
of integers corresponding to the selected checkbox options for each
participant and session.
}
\description{
Takes a group of checkbox-style variables, have a common prefix
and numeric suffixes representing options, and combines them into a single
list column where each element is a vector of selected options (numbers).

This function expects the input data to include \code{participant_id} and
\code{session_id} columns, which are used to group responses. For each participant
and session, it collects all checkbox numbers that were selected as a single
list. The resulting column can be renamed via the \code{name} parameter.
}
\examples{
# Example data
dat <- tibble::tibble(
  participant_id = c(1, 1, 2),
  session_id = c(1, 2, 1),
  q1___1 = c(1, NA, 0),
  q1___2 = c(0, 1, 1),
  q1___3 = c(NA, NA, 0)
)

# Combine q1 checkboxes into a single list column
combine_checkboxes(dat, var_basename = "q1")

# Combine and rename the output column
combine_checkboxes(dat, var_basename = "q1", name = "q1_combined")

}
