Skip to contents

Updates the @if_missing_var property of a survey_collection. The new value is the per-call default .dispatch_over_collection() uses when an analysis function (get_means(), get_freqs(), etc.) is dispatched across the collection without an explicit per-call .if_missing_var.

Usage

set_collection_if_missing_var(x, if_missing_var)

Arguments

x

A survey_collection.

if_missing_var

Character(1), one of c("error", "skip"). When "skip", member surveys missing a requested variable are dropped from the dispatched result; when "error", the dispatcher aborts.

Value

The modified survey_collection, invisibly.

Details

Setting the same value as the existing @if_missing_var returns the collection unchanged (no error, no warning). All other invariants on the collection (@surveys, @groups, @id) are preserved.

Pipes naturally with the rest of the collection API:

Examples

d1 <- as_survey(gss_2024, ids = vpsu, weights = wtssps,
                strata = vstrat, nest = TRUE)
coll <- as_survey_collection(a = d1)
coll <- set_collection_if_missing_var(coll, "skip")
coll@if_missing_var
#> [1] "skip"