Skip to contents

[Experimental]

These functions supply the label and levels arguments to collect_mr(). Each receives a named list of the original component columns, with attributes intact. Label helpers return one string or NULL; levels helpers return one string per component or NULL when that strategy cannot extract valid levels.

The default helpers try survey metadata, then longest common prefix (LCP), then fallback. Metadata helpers read the metadata attribute assigned by g6tr.survey step functions: question and template_elements$option. No dependency on g6tr.survey is required.

LCP helpers use component label attributes. The common prefix is trimmed at word boundaries and trailing separators are removed from the question label. Levels come from the remaining text. A single component skips LCP extraction. Fallback levels use complete component labels, or source names if labels are missing or duplicated. The fallback question label uses an identical label shared by all components, otherwise returns NULL.

Usage

collect_mr_label_default(columns)

collect_mr_levels_default(columns)

collect_mr_label_metadata(columns)

collect_mr_levels_metadata(columns)

collect_mr_label_lcp(columns)

collect_mr_levels_lcp(columns)

collect_mr_label_fallback(columns)

collect_mr_levels_fallback(columns)

Arguments

columns

A nonempty named list of component columns.

Value

A question label or response levels, or NULL if extraction is unavailable.

Examples

columns <- list(tv = c(TRUE, FALSE), radio = c(FALSE, TRUE))
attr(columns$tv, "label") <- "News sources | Television"
attr(columns$radio, "label") <- "News sources | Radio"
collect_mr_label_default(columns)
#> [1] "News sources"
collect_mr_levels_default(columns)
#> [1] "Television" "Radio"