Survey R6 class
Survey R6 class
Details
R6 class that encapsulates survey data, metadata (type, edition, periodicity), sampling design (simple/replicate), steps/recipes/workflows, and utilities to manage them.
Only copies the data; reuses design objects and other metadata. Much faster than clone(deep=TRUE) but design objects are shared.
Main methods
- $new(data, edition, type, psu, strata, engine, weight, design = NULL, steps = NULL, recipes = list())
Constructor.
- $set_data(data)
Set data.
- $set_edition(edition)
Set edition.
- $set_type(type)
Set type.
- $set_weight(weight)
Set weight specification.
- $print()
Print summarized metadata.
- $add_step(step)
Add a step and invalidate design.
- $add_recipe(recipe)
Add a recipe (validates type and dependencies).
- $add_workflow(workflow)
Add a workflow.
- $bake()
Apply recipes and return updated Survey.
- $ensure_design()
Lazily initialize the sampling design.
- $update_design()
Update design variables with current data.
- $shallow_clone()
Efficient copy (shares design, copies data).
Public fields
dataSurvey data (data.frame/data.table).
editionReference edition or period.
typeSurvey type, e.g., "ech" (character).
periodicityPeriodicity detected by validate_time_pattern.
default_engineDefault engine (character).
weightList with weight specifications per estimation type.
stepsList of steps applied to the survey.
recipesList of Recipe objects associated.
workflowsList of workflows.
designList of survey design objects (survey/surveyrep).
psuPrimary Sampling Unit specification (formula or character).
strataStratification variable name (character or NULL).
design_initializedLogical flag for lazy design initialization.
provenanceData lineage metadata (see
provenance()).
Methods
Method new()
Create a Survey object
Arguments
dataSurvey data
editionEdition or period
typeSurvey type (character)
psuPSU variable or formula (optional)
strataStratification variable name (optional)
engineDefault engine
weightWeight specification(s) per estimation type
designPre-built design (optional)
stepsInitial steps list (optional)
recipesList of Recipe (optional)
Method set_data()
Set the underlying data
Examples
dt <- data.table::data.table(id = 1:5, x = rnorm(5), w = rep(1, 5))
svy <- Survey$new(
data = dt, edition = "2023", type = "test",
psu = NULL, engine = "data.table", weight = add_weight(annual = "w")
)
svy
#> Type: TEST
#> Edition: 2023
#> Periodicity: Annual
#> Engine: data.table
#> Design:
#> Design: Not initialized (lazy initialization - will be created when needed)
#>
#> Steps: None
#> Recipes: None