Builds a survey_collection from one or more survey design objects for comparative analysis across waves, cross-sections, or sub-populations. Each element is stored independently — designs are never combined, and variance estimation is never re-specified.
Arguments
- ...
One or more
survey_baseobjects, passed with explicit names or as bare symbols. At least one argument is required.- group
<
tidy-select> Grouping variable(s) to apply uniformly across every member survey. Accepts bare names (region,c(region, stratum)),all_of(), etc. When supplied and resolving to a non-empty character vector, the named columns must exist in every member's@data; they are propagated onto each member's@groupsand set ascoll@groups. If a member already carries a non-empty@groupsthat differs from the resolved target, the target takes precedence and asurveycore_warning_collection_group_overriddenwarning is emitted (one per divergent member). When missing or resolving to an empty vector (NULL,character(0),c(),all_of(character(0))), the collection adopts the members' uniform@groupsif they are all identical, or errorssurveycore_error_collection_group_divergentif they differ. Default: missing (adopt-from-members).- .id
Character(1). Identifier column name used when dispatching analysis functions across the collection. Default
".survey". Stored on the returned collection's@idproperty and used as the default by.dispatch_over_collection()when a per-call.idis not supplied (i.e., when an analysis function is called with.id = NULL). Mutate viaset_collection_id().- .if_missing_var
Character(1), one of
c("error", "skip"). Default"error". Stored on the returned collection's@if_missing_varproperty and used as the default by.dispatch_over_collection()when a per-call.if_missing_varis not supplied (i.e., when an analysis function is called with.if_missing_var = NULL). When"skip", member surveys missing a requested variable are dropped from the dispatched result; when"error", the dispatcher aborts. Mutate viaset_collection_if_missing_var().
Details
Arguments may be passed with explicit names ("wave1" = d1) or as bare
symbols (d1, auto-named to "d1"). An unnamed argument that is not a
bare symbol (e.g., an inline as_survey(...) call) raises
surveycore_error_collection_unnamed_expr — name such arguments
explicitly.
Duplicate names are repaired by appending _1, _2, … to subsequent
occurrences (first occurrence preserved). When any rename occurs,
a surveycore_warning_collection_duplicate_name_repaired warning is
emitted showing the original -> repaired mapping.
Examples
d1 <- as_survey(gss_2024, ids = vpsu, weights = wtssps,
strata = vstrat, nest = TRUE)
d2 <- as_survey(gss_2024, ids = vpsu, weights = wtssps,
strata = vstrat, nest = TRUE)
# Explicit names
coll <- as_survey_collection("2020" = d1, "2024" = d2)
names(coll)
#> [1] "2020" "2024"
# Bare-symbol auto-naming
coll2 <- as_survey_collection(d1, d2)
names(coll2)
#> [1] "d1" "d2"
# Uniform grouping across members
coll3 <- as_survey_collection(d1, d2, group = vstrat)
coll3@groups
#> [1] "vstrat"
