Skip to contents

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

Usage

set_collection_id(x, id)

Arguments

x

A survey_collection.

id

Character(1). The new identifier column name. Must be non-NA and non-empty.

Value

The modified survey_collection, invisibly.

Details

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

Pipes naturally with the rest of the collection API:

coll |> set_collection_id("wave") |> get_means(y1)

Examples

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