| Title: | Local Engine for Reproducible Survey Data Processing |
|---|---|
| Description: | The processing engine of the 'metasurvey' ecosystem. Provides a step-based pipeline for reproducible processing of microdata from complex surveys, building on the 'survey' package for design-based estimation. Supports rotating panels with bootstrap replicate weights and a recipe system for reproducing data transformation workflows across editions of the same study. |
| Authors: | Mauro Loprete [aut, cre] (ORCID: <https://orcid.org/0000-0003-1560-0183>), Natalia da Silva [aut] (ORCID: <https://orcid.org/0000-0002-6031-7451>), Fabricio Machado [aut] (ORCID: <https://orcid.org/0009-0008-2653-9166>) |
| Maintainer: | Mauro Loprete <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.3.1 |
| Built: | 2026-10-12 16:02:24 UTC |
| Source: | https://github.com/metasurveyr/metasurvey.core |
Pipe-friendly function to add a category to a Recipe object.
Accepts either a category name (string) or a
RecipeCategory object.
add_category(recipe, category, description = "")add_category(recipe, category, description = "")
recipe |
A Recipe object. |
category |
Character category name or RecipeCategory object. |
description |
Character. Description for the category (used when
|
The modified Recipe object (invisibly for piping).
remove_category, recipe_category,
default_categories
Other tidy-api:
RecipeCategory,
RecipeCertification,
RecipeUser,
certify_recipe(),
default_categories(),
filter_recipes(),
filter_workflows(),
find_workflows_for_recipe(),
list_recipes(),
list_workflows(),
rank_recipes(),
rank_workflows(),
recipe_category(),
recipe_certification(),
recipe_user(),
remove_category(),
search_recipes(),
search_workflows(),
set_user_info(),
set_version()
r <- recipe( name = "Example", user = "Test", svy = survey_empty(type = "ech", edition = "2023"), description = "Example recipe" ) r <- r |> add_category("labor_market", "Labor market indicators") |> add_category("income")r <- recipe( name = "Example", user = "Test", svy = survey_empty(type = "ech", edition = "2023"), description = "Example recipe" ) r <- r |> add_category("labor_market", "Labor market indicators") |> add_category("income")
Tidy wrapper for svy$add_recipe(recipe).
add_recipe(svy, recipe, bake = lazy_default())add_recipe(svy, recipe, bake = lazy_default())
svy |
Survey object |
recipe |
A Recipe object |
bake |
Logical; whether to bake immediately (default: lazy_default()) |
The Survey object (invisibly), modified in place
Other recipes:
Recipe-class,
bake_recipes(),
get_recipe(),
harmonize(),
print.Recipe(),
publish_recipe(),
read_recipe(),
recipe(),
save_recipe(),
steps_to_recipe()
svy <- survey_empty(type = "ech", edition = "2023") r <- recipe( name = "Example", user = "test", svy = svy, description = "Example" ) svy <- add_recipe(svy, r)svy <- survey_empty(type = "ech", edition = "2023") r <- recipe( name = "Example", user = "test", svy = svy, description = "Example" ) svy <- add_recipe(svy, r)
This function configures replicate weights (bootstrap, jackknife, etc.) that allow estimation of variance for complex statistics in surveys with complex sampling designs. It is essential for obtaining correct standard errors in population estimates.
add_replicate( weight, replicate_pattern, replicate_path = NULL, replicate_id = NULL, replicate_type )add_replicate( weight, replicate_pattern, replicate_path = NULL, replicate_id = NULL, replicate_type )
weight |
String with the name of the main weight variable in the survey (e.g., "pesoano", "pesomes") |
replicate_pattern |
String with regex pattern to identify replicate weight columns. Examples: "wr\d+" for columns wr1, wr2, etc. |
replicate_path |
Path to the file containing replicate weights. If NULL, assumes they are in the same main dataset |
replicate_id |
Named vector specifying how to join between the main dataset and replicate file. Format: c("main_var" = "replicate_var") |
replicate_type |
Type of replication used. Options: "bootstrap", "jackknife", "BRR" (Balanced Repeated Replication) |
Replicate weights are essential for:
Correctly estimating variance in complex designs
Calculating appropriate confidence intervals
Obtaining reliable coefficients of variation
Performing valid statistical tests
The regex pattern must exactly match the replicate weight column names in the file. For example, if columns are named "wr001", "wr002", etc., use the pattern "wr\\d+".
This function is typically used within add_weight() for more
complex weight configurations.
List with replicate configuration that will be used by the sampling design for variance estimation
add_weight for complete weight configuration
svrepdesign for replicate design in survey package
load_survey where this configuration is used
Other weights:
add_weight()
# Basic configuration with external file annual_replicates <- add_replicate( weight = "pesoano", replicate_pattern = "wr\\d+", replicate_path = "bootstrap_weights_2023.xlsx", replicate_id = c("ID_HOGAR" = "ID"), replicate_type = "bootstrap" ) # With replicates in same dataset integrated_replicates <- add_replicate( weight = "main_weight", replicate_pattern = "rep_\\d{3}", replicate_type = "jackknife" ) # Use within add_weight weight_config <- add_weight( annual = add_replicate( weight = "pesoano", replicate_pattern = "wr\\d+", replicate_path = "bootstrap_annual.xlsx", replicate_id = c("numero" = "ID_HOGAR"), replicate_type = "bootstrap" ), monthly = "pesomes" )# Basic configuration with external file annual_replicates <- add_replicate( weight = "pesoano", replicate_pattern = "wr\\d+", replicate_path = "bootstrap_weights_2023.xlsx", replicate_id = c("ID_HOGAR" = "ID"), replicate_type = "bootstrap" ) # With replicates in same dataset integrated_replicates <- add_replicate( weight = "main_weight", replicate_pattern = "rep_\\d{3}", replicate_type = "jackknife" ) # Use within add_weight weight_config <- add_weight( annual = add_replicate( weight = "pesoano", replicate_pattern = "wr\\d+", replicate_path = "bootstrap_annual.xlsx", replicate_id = c("numero" = "ID_HOGAR"), replicate_type = "bootstrap" ), monthly = "pesomes" )
This function creates a weight structure that allows specifying different weight variables according to estimation periodicity. It is essential for proper functioning of workflows with multiple temporal estimation types.
add_weight(monthly = NULL, annual = NULL, quarterly = NULL, biannual = NULL)add_weight(monthly = NULL, annual = NULL, quarterly = NULL, biannual = NULL)
monthly |
String with monthly weight variable name, or replicate list
created with |
annual |
String with annual weight variable name, or replicate list for annual weights |
quarterly |
String with quarterly weight variable name, or replicate list for quarterly weights |
biannual |
String with biannual weight variable name, or replicate list for biannual weights |
This function is fundamental for surveys that require different weights according to temporal estimation type. For example, Uruguay's ECH has specific weights for monthly, quarterly, and annual estimations.
Each parameter can be:
A simple string with the weight variable name
A replicate structure created with add_replicate()
for bootstrap or jackknife estimations
Weights are automatically selected in workflow() according to the
specified estimation_type parameter.
Named list with weight configuration by periodicity, which will be
used by load_survey and workflow to
automatically select the appropriate weight
add_replicate to configure bootstrap/jackknife replicates
load_survey where this configuration is used
workflow that automatically selects weights
Other weights:
add_replicate()
# Basic configuration with simple weight variables ech_weights <- add_weight( monthly = "pesomes", quarterly = "pesotri", annual = "pesoano" ) # With bootstrap replicates for variance estimation weights_with_replicates <- add_weight( monthly = add_replicate( weight = "pesomes", replicate_pattern = "wr\\d+", replicate_path = "monthly_replicate_weights.xlsx", replicate_id = c("ID_HOGAR" = "ID"), replicate_type = "bootstrap" ), annual = "pesoano" )# Basic configuration with simple weight variables ech_weights <- add_weight( monthly = "pesomes", quarterly = "pesotri", annual = "pesoano" ) # With bootstrap replicates for variance estimation weights_with_replicates <- add_weight( monthly = add_replicate( weight = "pesomes", replicate_pattern = "wr\\d+", replicate_path = "monthly_replicate_weights.xlsx", replicate_id = c("ID_HOGAR" = "ID"), replicate_type = "bootstrap" ), annual = "pesoano" )
Bake recipes
bake_recipes(svy)bake_recipes(svy)
svy |
Survey object |
Survey object with all recipes applied
Other recipes:
Recipe-class,
add_recipe(),
get_recipe(),
harmonize(),
print.Recipe(),
publish_recipe(),
read_recipe(),
recipe(),
save_recipe(),
steps_to_recipe()
dt <- data.table::data.table(id = 1:20, x = rnorm(20), w = runif(20, 0.5, 2)) svy <- Survey$new( data = dt, edition = "2023", type = "demo", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) r <- recipe( name = "Demo", user = "test", svy = svy, description = "Demo recipe" ) svy <- add_recipe(svy, r) processed <- bake_recipes(svy)dt <- data.table::data.table(id = 1:20, x = rnorm(20), w = runif(20, 0.5, 2)) svy <- Survey$new( data = dt, edition = "2023", type = "demo", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) r <- recipe( name = "Demo", user = "test", svy = svy, description = "Demo recipe" ) svy <- add_recipe(svy, r) processed <- bake_recipes(svy)
Iterates over all pending (lazy) steps attached to a Survey or RotativePanelSurvey and executes them sequentially, mutating the underlying data.table. Each step is validated before execution (checks that required variables exist).
bake_steps(svy)bake_steps(svy)
svy |
A |
Steps are executed in the order they were added. Each step's expressions can reference variables created by previous steps.
For RotativePanelSurvey objects, steps are applied to both the implantation and all follow-up surveys.
The same object with all steps materialized in the data
and each step marked as bake = TRUE.
Other steps:
get_steps(),
step_collapse(),
step_compute(),
step_filter(),
step_join(),
step_quantile(),
step_recode(),
step_remove(),
step_rename(),
step_validate(),
view_graph()
dt <- data.table::data.table(id = 1:5, age = c(15, 30, 45, 50, 70), w = 1) svy <- Survey$new( data = dt, edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) svy <- step_compute(svy, age2 = age * 2) svy <- bake_steps(svy) get_data(svy)dt <- data.table::data.table(id = 1:5, age = c(15, 30, 45, 50, 70), w = 1) svy <- Survey$new( data = dt, edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) svy <- step_compute(svy, age2 = age * 2) svy <- bake_steps(svy) get_data(svy)
Pretty-prints the sampling design configuration for each estimation type in a Survey object, showing PSU, strata, weights, and other design elements in a color-coded, readable format.
cat_design(self)cat_design(self)
self |
Survey object containing design information |
This function displays design information including:
Primary Sampling Units (PSU/clusters)
Stratification variables
Weight variables for each estimation type
Finite Population Correction (FPC) if used
Calibration formulas if applied
Overall design type classification
Output is color-coded for better readability in supporting terminals.
Invisibly returns NULL; called for side effect of printing design info
cat_design_type for design type classification
Other survey-objects:
Survey,
cat_design_type(),
get_data(),
get_metadata(),
has_design(),
has_recipes(),
has_steps(),
is_baked(),
set_data(),
survey_empty(),
survey_to_data_frame(),
survey_to_datatable(),
survey_to_tibble()
dt <- data.table::data.table(id = 1:20, x = rnorm(20), w = runif(20, 0.5, 2)) svy <- Survey$new( data = dt, edition = "2023", type = "demo", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) cat_design(svy)dt <- data.table::data.table(id = 1:20, x = rnorm(20), w = runif(20, 0.5, 2)) svy <- Survey$new( data = dt, edition = "2023", type = "demo", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) cat_design(svy)
Cast design type from survey
cat_design_type(self, design_name)cat_design_type(self, design_name)
self |
Object of class Survey |
design_name |
Name of design |
Character string describing the design type, or "None".
Other survey-objects:
Survey,
cat_design(),
get_data(),
get_metadata(),
has_design(),
has_recipes(),
has_steps(),
is_baked(),
set_data(),
survey_empty(),
survey_to_data_frame(),
survey_to_datatable(),
survey_to_tibble()
dt <- data.table::data.table(id = 1:20, x = rnorm(20), w = runif(20, 0.5, 2)) svy <- Survey$new( data = dt, edition = "2023", type = "demo", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) svy$ensure_design() cat_design_type(svy, "annual")dt <- data.table::data.table(id = 1:20, x = rnorm(20), w = runif(20, 0.5, 2)) svy <- Survey$new( data = dt, edition = "2023", type = "demo", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) svy$ensure_design() cat_design_type(svy, "annual")
Pipe-friendly function to certify a Recipe at a given quality level.
certify_recipe(recipe, user, level)certify_recipe(recipe, user, level)
recipe |
A Recipe object. |
user |
RecipeUser who is certifying. |
level |
Character. Certification level:
|
The modified Recipe object.
recipe_certification, recipe_user
Other tidy-api:
RecipeCategory,
RecipeCertification,
RecipeUser,
add_category(),
default_categories(),
filter_recipes(),
filter_workflows(),
find_workflows_for_recipe(),
list_recipes(),
list_workflows(),
rank_recipes(),
rank_workflows(),
recipe_category(),
recipe_certification(),
recipe_user(),
remove_category(),
search_recipes(),
search_workflows(),
set_user_info(),
set_version()
r <- recipe( name = "Example", user = "Test", svy = survey_empty(type = "ech", edition = "2023"), description = "Example recipe" ) inst <- recipe_user("IECON", type = "institution") r <- r |> certify_recipe(inst, "official")r <- recipe( name = "Example", user = "Test", svy = survey_empty(type = "ech", edition = "2023"), description = "Example recipe" ) inst <- recipe_user("IECON", type = "institution") r <- r |> certify_recipe(inst, "official")
Returns a list of standard built-in categories for recipe classification.
default_categories()default_categories()
List of RecipeCategory objects
Other tidy-api:
RecipeCategory,
RecipeCertification,
RecipeUser,
add_category(),
certify_recipe(),
filter_recipes(),
filter_workflows(),
find_workflows_for_recipe(),
list_recipes(),
list_workflows(),
rank_recipes(),
rank_workflows(),
recipe_category(),
recipe_certification(),
recipe_user(),
remove_category(),
search_recipes(),
search_workflows(),
set_user_info(),
set_version()
cats <- default_categories() vapply(cats, function(c) c$name, character(1))cats <- default_categories() vapply(cats, function(c) c$name, character(1))
Evaluate estimation with Coefficient of Variation
evaluate_cv(cv)evaluate_cv(cv)
cv |
Numeric coefficient of variation value. |
Character string with the quality category
(e.g. "Excellent", "Good"), or NA when the CV is not
defined (e.g. a zero estimate, where CV = 0/0).
Other workflows:
RecipeWorkflow-class,
print.RecipeWorkflow(),
publish_workflow(),
read_workflow(),
save_workflow(),
workflow(),
workflow_from_list(),
workflow_table()
evaluate_cv(3) # "Excellent" evaluate_cv(12) # "Good" evaluate_cv(30) # "Use with caution" evaluate_cv(NaN) # NAevaluate_cv(3) # "Excellent" evaluate_cv(12) # "Good" evaluate_cv(30) # "Use with caution" evaluate_cv(NaN) # NA
Extracts subsets of surveys from a RotativePanelSurvey object based on temporal criteria. Allows obtaining surveys for different types of analysis (monthly, quarterly, annual) respecting the rotating panel's temporal structure.
extract_surveys( RotativePanelSurvey, index = NULL, monthly = NULL, annual = NULL, quarterly = NULL, biannual = NULL, use.parallel = FALSE )extract_surveys( RotativePanelSurvey, index = NULL, monthly = NULL, annual = NULL, quarterly = NULL, biannual = NULL, use.parallel = FALSE )
RotativePanelSurvey |
A |
index |
Integer vector specifying survey indices to extract. If a single value, returns that survey; if a vector, returns a list |
monthly |
Integer vector specifying which months to extract for monthly analysis (1-12) |
annual |
Integer vector specifying which years to extract for annual analysis |
quarterly |
Integer vector specifying which quarters to extract for quarterly analysis (1-4) |
biannual |
Integer vector specifying which semesters to extract for biannual analysis (1-2) |
use.parallel |
Logical indicating whether to use parallel processing for intensive operations. Default FALSE |
This function is essential for working with rotating panels because:
Enables periodicity-based analysis: Extract data for different types of temporal estimations
Preserves temporal structure: Respects temporal relationships between different panel waves
Optimizes memory: Only loads surveys needed for the analysis
Facilitates comparisons: Extract specific periods for comparative analysis
Supports parallelization: For operations with large data volumes
Extraction criteria are interpreted according to survey frequency:
For monthly ECH: monthly=c(1,3,6) extracts January, March and June
For annual analysis: annual=1 typically extracts the first available year
For quarterly analysis: quarterly=c(1,4) extracts Q1 and Q4
If no criteria are specified, the function returns the implantation survey with a warning.
A list of Survey objects matching the specified criteria,
or a single Survey object if a single index is specified
load_panel_survey for loading rotating panels
get_implantation for obtaining implantation data
get_follow_up for obtaining follow-up data
workflow for using extracted surveys in analysis
Other panel-surveys:
PoolSurvey,
RotativePanelSurvey,
get_follow_up(),
get_implantation()
# Panels usually come from load_panel_survey(); here we build a # small one in memory mk <- function(edition) { Survey$new( data = data.table::data.table(id = 1:5, w = 1), edition = edition, type = "ech", psu = NULL, engine = "data.table", weight = add_weight(monthly = "w") ) } panel <- RotativePanelSurvey$new( implantation = mk("2023-01-01"), follow_up = list(mk("2023-01-01"), mk("2023-02-01"), mk("2023-03-01")), type = "ech", default_engine = "data.table", steps = list(), recipes = list(), workflows = list(), design = NULL ) # Extract follow-up surveys by index ech_first <- extract_surveys(panel, index = 1) ech_first_two <- extract_surveys(panel, index = c(1, 2)) ## Not run: # Not run: interval extraction needs a panel loaded from the real # microdata files (editions must carry the survey time pattern) ech_q1 <- extract_surveys(panel_ech, monthly = c(1, 2, 3)) ech_annual <- extract_surveys(panel_ech, annual = 1) results <- workflow( survey = extract_surveys(panel_ech, quarterly = c(1, 2)), svymean(~unemployed, na.rm = TRUE), estimation_type = "quarterly" ) ## End(Not run)# Panels usually come from load_panel_survey(); here we build a # small one in memory mk <- function(edition) { Survey$new( data = data.table::data.table(id = 1:5, w = 1), edition = edition, type = "ech", psu = NULL, engine = "data.table", weight = add_weight(monthly = "w") ) } panel <- RotativePanelSurvey$new( implantation = mk("2023-01-01"), follow_up = list(mk("2023-01-01"), mk("2023-02-01"), mk("2023-03-01")), type = "ech", default_engine = "data.table", steps = list(), recipes = list(), workflows = list(), design = NULL ) # Extract follow-up surveys by index ech_first <- extract_surveys(panel, index = 1) ech_first_two <- extract_surveys(panel, index = c(1, 2)) ## Not run: # Not run: interval extraction needs a panel loaded from the real # microdata files (editions must carry the survey time pattern) ech_q1 <- extract_surveys(panel_ech, monthly = c(1, 2, 3)) ech_annual <- extract_surveys(panel_ech, annual = 1) results <- workflow( survey = extract_surveys(panel_ech, quarterly = c(1, 2)), svymean(~unemployed, na.rm = TRUE), estimation_type = "quarterly" ) ## End(Not run)
Extract time pattern
extract_time_pattern(svy_edition)extract_time_pattern(svy_edition)
svy_edition |
Survey edition string (e.g. "2023", "2023-06", "2023_Q1"). |
List with components: periodicity, year, month (when applicable).
Other survey-loading:
group_dates(),
load_panel_survey(),
load_survey(),
load_survey_example(),
validate_time_pattern()
# Annual edition extract_time_pattern("2023") # Monthly edition extract_time_pattern("2023-06")# Annual edition extract_time_pattern("2023") # Monthly edition extract_time_pattern("2023-06")
Filter recipes in the active backend by survey type, edition, category, or certification level.
filter_recipes( survey_type = NULL, edition = NULL, category = NULL, certification_level = NULL, topic = NULL )filter_recipes( survey_type = NULL, edition = NULL, category = NULL, certification_level = NULL, topic = NULL )
survey_type |
Character survey type or NULL. |
edition |
Character edition or NULL. |
category |
Character category name or NULL. |
certification_level |
Character certification level or NULL. |
topic |
Character topic name or NULL. |
List of matching Recipe objects.
Other tidy-api:
RecipeCategory,
RecipeCertification,
RecipeUser,
add_category(),
certify_recipe(),
default_categories(),
filter_workflows(),
find_workflows_for_recipe(),
list_recipes(),
list_workflows(),
rank_recipes(),
rank_workflows(),
recipe_category(),
recipe_certification(),
recipe_user(),
remove_category(),
search_recipes(),
search_workflows(),
set_user_info(),
set_version()
set_backend("local", path = tempfile(fileext = ".json")) ech_recipes <- filter_recipes(survey_type = "ech") length(ech_recipes)set_backend("local", path = tempfile(fileext = ".json")) ech_recipes <- filter_recipes(survey_type = "ech") length(ech_recipes)
Filter workflows in the active backend by survey type, edition, recipe ID, or certification level.
filter_workflows( survey_type = NULL, edition = NULL, recipe_id = NULL, certification_level = NULL )filter_workflows( survey_type = NULL, edition = NULL, recipe_id = NULL, certification_level = NULL )
survey_type |
Character survey type or |
edition |
Character edition or |
recipe_id |
Character recipe ID or |
certification_level |
Character certification level or |
List of matching RecipeWorkflow objects.
search_workflows,
find_workflows_for_recipe
Other tidy-api:
RecipeCategory,
RecipeCertification,
RecipeUser,
add_category(),
certify_recipe(),
default_categories(),
filter_recipes(),
find_workflows_for_recipe(),
list_recipes(),
list_workflows(),
rank_recipes(),
rank_workflows(),
recipe_category(),
recipe_certification(),
recipe_user(),
remove_category(),
search_recipes(),
search_workflows(),
set_user_info(),
set_version()
set_workflow_backend("local", path = tempfile(fileext = ".json")) ech_wf <- filter_workflows(survey_type = "ech") length(ech_wf)set_workflow_backend("local", path = tempfile(fileext = ".json")) ech_wf <- filter_workflows(survey_type = "ech") length(ech_wf)
Cross-reference query: find all workflows that reference a given recipe ID.
find_workflows_for_recipe(recipe_id)find_workflows_for_recipe(recipe_id)
recipe_id |
Character recipe ID to search for. |
List of RecipeWorkflow objects that reference this recipe.
Other tidy-api:
RecipeCategory,
RecipeCertification,
RecipeUser,
add_category(),
certify_recipe(),
default_categories(),
filter_recipes(),
filter_workflows(),
list_recipes(),
list_workflows(),
rank_recipes(),
rank_workflows(),
recipe_category(),
recipe_certification(),
recipe_user(),
remove_category(),
search_recipes(),
search_workflows(),
set_user_info(),
set_version()
set_workflow_backend("local", path = tempfile(fileext = ".json")) wfs <- find_workflows_for_recipe("recipe_001") length(wfs)set_workflow_backend("local", path = tempfile(fileext = ".json")) wfs <- find_workflows_for_recipe("recipe_001") length(wfs)
Returns the currently configured recipe backend. Defaults to "api" if not configured.
get_backend()get_backend()
RecipeBackend object
Other backends:
get_workflow_backend(),
set_backend(),
set_workflow_backend()
set_backend("local", path = tempfile(fileext = ".json")) backend <- get_backend() backendset_backend("local", path = tempfile(fileext = ".json")) backend <- get_backend() backend
Get data from survey
get_data(svy)get_data(svy)
svy |
Survey object |
A data.table (or data.frame) containing the survey microdata.
Other survey-objects:
Survey,
cat_design(),
cat_design_type(),
get_metadata(),
has_design(),
has_recipes(),
has_steps(),
is_baked(),
set_data(),
survey_empty(),
survey_to_data_frame(),
survey_to_datatable(),
survey_to_tibble()
dt <- data.table::data.table( id = 1:5, age = c(25, 30, 45, 50, 60), w = rep(1, 5) ) svy <- Survey$new( data = dt, edition = "2023", type = "ech", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) head(get_data(svy))dt <- data.table::data.table( id = 1:5, age = c(25, 30, 45, 50, 60), w = rep(1, 5) ) svy <- Survey$new( data = dt, edition = "2023", type = "ech", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) head(get_data(svy))
Retrieves the currently configured engine for loading surveys from system options or environment variables.
get_engine()get_engine()
Character vector with the name of the configured engine.
Other options:
lazy_default(),
set_engine(),
set_lazy_processing(),
set_use_copy(),
show_engines(),
use_copy_default()
get_engine()get_engine()
Extracts one or more follow-up surveys (waves after the implantation) from a RotativePanelSurvey object. Follow-up surveys represent subsequent data collections and are essential for longitudinal and temporal change analysis.
get_follow_up( RotativePanelSurvey, index = seq_along(RotativePanelSurvey$follow_up) )get_follow_up( RotativePanelSurvey, index = seq_along(RotativePanelSurvey$follow_up) )
RotativePanelSurvey |
A |
index |
Integer vector specifying which follow-up surveys to extract. Defaults to all available (1:length(follow_up)). Can be a single index or a vector of indices |
Follow-up surveys are fundamental in rotating panels because:
Enable longitudinal analysis: Track the same units over time
Capture temporal changes: Evolution of economic, social, and demographic variables
Maintain representativeness: Each wave preserves population representativeness through controlled rotation
Optimize resources: Reuse information from previous waves to reduce collection costs
Facilitate comparisons: Consistent temporal structure for trend analysis
In rotating panels like ECH:
Each follow-up wave covers a specific period (monthly/quarterly)
Units rotate gradually maintaining temporal overlap
Indices correspond to the chronological collection order
Each follow-up maintains methodological consistency with implantation
A list of Survey objects corresponding to the specified
follow-up surveys. If a single index is specified, returns a list with
one element
get_implantation for obtaining the implantation survey
extract_surveys for extracting surveys by temporal criteria
load_panel_survey for loading rotating panels
workflow for analysis with follow-up surveys
Other panel-surveys:
PoolSurvey,
RotativePanelSurvey,
extract_surveys(),
get_implantation()
impl <- Survey$new( data = data.table::data.table(id = 1:5, w = 1), edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) fu1 <- Survey$new( data = data.table::data.table(id = 1:5, w = 1), edition = "2023_01", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) fu2 <- Survey$new( data = data.table::data.table(id = 1:5, w = 1), edition = "2023_02", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) panel <- RotativePanelSurvey$new( implantation = impl, follow_up = list(fu1, fu2), type = "test", default_engine = "data.table", steps = list(), recipes = list(), workflows = list(), design = NULL ) get_follow_up(panel, index = 1) get_follow_up(panel)impl <- Survey$new( data = data.table::data.table(id = 1:5, w = 1), edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) fu1 <- Survey$new( data = data.table::data.table(id = 1:5, w = 1), edition = "2023_01", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) fu2 <- Survey$new( data = data.table::data.table(id = 1:5, w = 1), edition = "2023_02", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) panel <- RotativePanelSurvey$new( implantation = impl, follow_up = list(fu1, fu2), type = "test", default_engine = "data.table", steps = list(), recipes = list(), workflows = list(), design = NULL ) get_follow_up(panel, index = 1) get_follow_up(panel)
Extracts the implantation (baseline) survey from a RotativePanelSurvey object. The implantation survey represents the first data collection wave and is essential for establishing the baseline and structural characteristics of the panel.
get_implantation(RotativePanelSurvey)get_implantation(RotativePanelSurvey)
RotativePanelSurvey |
A |
The implantation survey is special in a rotating panel because:
Establishes the baseline: Defines initial characteristics of all panel units
Contains the full sample: Includes all units that will participate in the different panel waves
Defines temporal structure: Establishes rotation and follow-up patterns
Configures metadata: Contains information about periodicity, key variables, and stratification
Serves as tracking reference: Basis for unit tracking in subsequent waves
This function is essential for analysis requiring:
Temporal comparisons from the baseline
Analysis of the complete panel structure
Configuration of longitudinal models
Evaluation of sampling design quality
A Survey object containing the implantation survey with all
its metadata, data, and design configuration
get_follow_up for obtaining follow-up surveys
extract_surveys for extracting multiple surveys by criteria
load_panel_survey for loading rotating panels
workflow for analysis with the implantation survey
Other panel-surveys:
PoolSurvey,
RotativePanelSurvey,
extract_surveys(),
get_follow_up()
impl <- Survey$new( data = data.table::data.table(id = 1:5, w = 1), edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) fu <- Survey$new( data = data.table::data.table(id = 1:5, w = 1), edition = "2023_01", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) panel <- RotativePanelSurvey$new( implantation = impl, follow_up = list(fu), type = "test", default_engine = "data.table", steps = list(), recipes = list(), workflows = list(), design = NULL ) get_implantation(panel)impl <- Survey$new( data = data.table::data.table(id = 1:5, w = 1), edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) fu <- Survey$new( data = data.table::data.table(id = 1:5, w = 1), edition = "2023_01", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) panel <- RotativePanelSurvey$new( implantation = impl, follow_up = list(fu), type = "test", default_engine = "data.table", steps = list(), recipes = list(), workflows = list(), design = NULL ) get_implantation(panel)
Display survey metadata on the console. This function is
the shared implementation behind the print() methods of
Survey, RotativePanelSurvey and
PoolSurvey, which is why it writes with cat()
rather than through the metasurvey.verbose-gated message
helper.
get_metadata(self)get_metadata(self)
self |
Object of class Survey |
NULL (called for side effect: prints metadata to console).
Other survey-objects:
Survey,
cat_design(),
cat_design_type(),
get_data(),
has_design(),
has_recipes(),
has_steps(),
is_baked(),
set_data(),
survey_empty(),
survey_to_data_frame(),
survey_to_datatable(),
survey_to_tibble()
dt <- data.table::data.table( id = 1:5, age = c(25, 30, 45, 50, 60), w = rep(1, 5) ) svy <- Survey$new( data = dt, edition = "2023", type = "ech", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) get_metadata(svy)dt <- data.table::data.table( id = 1:5, age = c(25, 30, 45, 50, 60), w = rep(1, 5) ) svy <- Survey$new( data = dt, edition = "2023", type = "ech", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) get_metadata(svy)
This function retrieves data transformation recipes from the metasurvey repository or API, based on specific criteria such as survey type, edition, and topic. It is the primary way to access predefined and community-validated recipes.
get_recipe( svy_type = NULL, svy_edition = NULL, topic = NULL, allowMultiple = TRUE )get_recipe( svy_type = NULL, svy_edition = NULL, topic = NULL, allowMultiple = TRUE )
svy_type |
String specifying the survey type. Examples: "ech", "eaii", "eai", "eph" |
svy_edition |
String specifying the survey edition. Supported formats: "YYYY", "YYYYMM", "YYYY-YYYY" |
topic |
String specifying the recipe topic. Examples: "labor_market", "poverty", "income", "demographics" |
allowMultiple |
Logical indicating whether multiple recipes are allowed. If FALSE and multiple matches exist, returns the most recent one |
This function is essential for:
Accessing official recipes: Get validated and maintained recipes by specialized teams
Reproducibility: Ensure different users apply the same standard transformations
Automation: Integrate recipes into automatic pipelines
Collaboration: Share methodologies between teams and organizations
Versioning: Access different recipe versions according to edition
The function queries the metasurvey API to retrieve recipes. Internet connection is required. If the API is unavailable or you need to work offline:
Working Offline:
Don't call get_recipe() - work directly with steps
Set options(metasurvey.skip_recipes = TRUE)
to disable API calls
Load recipes from local files using read_recipe()
Create custom recipes with recipe()
Search criteria are combined with AND operator, so all specified criteria must match for a recipe to be returned.
Recipe object or list of Recipe objects according to the
specified criteria and the value of allowMultiple
recipe to create custom recipes
save_recipe to save recipes locally
read_recipe to read recipes from file
publish_recipe to publish recipes to the repository
load_survey where recipes are used
Other recipes:
Recipe-class,
add_recipe(),
bake_recipes(),
harmonize(),
print.Recipe(),
publish_recipe(),
read_recipe(),
recipe(),
save_recipe(),
steps_to_recipe()
# Query a local backend (works offline) old <- set_backend("local", path = tempfile(fileext = ".json")) r <- Recipe$new( name = "labor_market", edition = "2023", survey_type = "ech", default_engine = "data.table", depends_on = list(), user = "demo", description = "Example recipe", steps = list("step_compute(., active = e27 >= 14)"), id = "r_demo" ) publish_recipe(r) # Get recipes for ECH 2023 ech_recipes <- get_recipe(svy_type = "ech", svy_edition = "2023") # Get a single recipe one_recipe <- get_recipe( svy_type = "ech", svy_edition = "2023", allowMultiple = FALSE ) # Restore previous backend options(metasurvey.backend = old)# Query a local backend (works offline) old <- set_backend("local", path = tempfile(fileext = ".json")) r <- Recipe$new( name = "labor_market", edition = "2023", survey_type = "ech", default_engine = "data.table", depends_on = list(), user = "demo", description = "Example recipe", steps = list("step_compute(., active = e27 >= 14)"), id = "r_demo" ) publish_recipe(r) # Get recipes for ECH 2023 ech_recipes <- get_recipe(svy_type = "ech", svy_edition = "2023") # Get a single recipe one_recipe <- get_recipe( svy_type = "ech", svy_edition = "2023", allowMultiple = FALSE ) # Restore previous backend options(metasurvey.backend = old)
Get steps from survey
get_steps(svy)get_steps(svy)
svy |
Survey object |
List of Step objects
Other steps:
bake_steps(),
step_collapse(),
step_compute(),
step_filter(),
step_join(),
step_quantile(),
step_recode(),
step_remove(),
step_rename(),
step_validate(),
view_graph()
dt <- data.table::data.table( id = 1:5, age = c(25, 30, 45, 50, 60), w = rep(1, 5) ) svy <- Survey$new( data = dt, edition = "2023", type = "ech", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) svy <- step_compute(svy, age2 = age * 2) get_steps(svy) # list of Step objectsdt <- data.table::data.table( id = 1:5, age = c(25, 30, 45, 50, 60), w = rep(1, 5) ) svy <- Survey$new( data = dt, edition = "2023", type = "ech", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) svy <- step_compute(svy, age2 = age * 2) get_steps(svy) # list of Step objects
Returns the currently configured workflow backend. Defaults to "local" if not configured.
get_workflow_backend()get_workflow_backend()
WorkflowBackend object
Other backends:
get_backend(),
set_backend(),
set_workflow_backend()
backend <- get_workflow_backend()backend <- get_workflow_backend()
Group dates
group_dates(dates, type = c("monthly", "quarterly", "biannual"))group_dates(dates, type = c("monthly", "quarterly", "biannual"))
dates |
Vector of Date objects. |
type |
Grouping type: "monthly", "quarterly", or "biannual". |
Integer vector of group indices (e.g. 1-12 for monthly, 1-4 for quarterly).
Other survey-loading:
extract_time_pattern(),
load_panel_survey(),
load_survey(),
load_survey_example(),
validate_time_pattern()
dates <- as.Date(c( "2023-01-15", "2023-04-20", "2023-07-10", "2023-11-05" )) group_dates(dates, "quarterly") group_dates(dates, "biannual")dates <- as.Date(c( "2023-01-15", "2023-04-20", "2023-07-10", "2023-11-05" )) group_dates(dates, "quarterly") group_dates(dates, "biannual")
For each survey in the list, fetches matching recipes from the active
backend (by survey type and edition), sorts them by dependency order,
applies them via bake_recipes, and assembles the results
into a PoolSurvey ready for workflow.
harmonize( surveys, survey_type = NULL, topic = NULL, category = NULL, certification_level = NULL, grouping = "annual", group_name = "series", .verbose = getOption("metasurvey.verbose", TRUE) )harmonize( surveys, survey_type = NULL, topic = NULL, category = NULL, certification_level = NULL, grouping = "annual", group_name = "series", .verbose = getOption("metasurvey.verbose", TRUE) )
surveys |
List of |
survey_type |
Character. Override survey type for recipe lookup.
If |
topic |
Character. Filter recipes by topic
(e.g. |
category |
Character. Optional category filter for recipes. |
certification_level |
Character. Optional certification level
filter (e.g. |
grouping |
Character. Time hierarchy for the PoolSurvey structure.
One of |
group_name |
Character. Name of the group in the PoolSurvey
structure (default |
.verbose |
Logical. Print progress messages (default uses
|
The function performs the following steps for each survey:
Calls filter_recipes with the survey's type and
edition (plus optional category/certification filters).
Sorts matching recipes using topological sort on
depends_on_recipes.
Attaches recipes via add_recipe and
applies them with bake_recipes.
If no recipes are found for a survey, it is included in the pool unchanged (with a warning).
A PoolSurvey object containing the harmonized
surveys, structured as
list(<grouping> = list(<group_name> = list(svy1, svy2, ...))).
filter_recipes, bake_recipes,
PoolSurvey, workflow
Other recipes:
Recipe-class,
add_recipe(),
bake_recipes(),
get_recipe(),
print.Recipe(),
publish_recipe(),
read_recipe(),
recipe(),
save_recipe(),
steps_to_recipe()
# Set up a local backend with a temp file old <- set_backend("local", path = tempfile(fileext = ".json")) # Create a small survey and a recipe dt <- data.table::data.table( id = 1:10, x = 1:10, w = rep(1, 10) ) svy <- Survey$new( data = dt, edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) r <- Recipe$new( name = "demo", edition = "2023", survey_type = "test", default_engine = "data.table", depends_on = list(), user = "demo", description = "demo recipe", steps = list("step_compute(., z = x * 2)"), id = "demo_recipe" ) publish_recipe(r) pool <- harmonize(list(svy), .verbose = FALSE) # Restore backend options(metasurvey.backend = old)# Set up a local backend with a temp file old <- set_backend("local", path = tempfile(fileext = ".json")) # Create a small survey and a recipe dt <- data.table::data.table( id = 1:10, x = 1:10, w = rep(1, 10) ) svy <- Survey$new( data = dt, edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) r <- Recipe$new( name = "demo", edition = "2023", survey_type = "test", default_engine = "data.table", depends_on = list(), user = "demo", description = "demo recipe", steps = list("step_compute(., z = x * 2)"), id = "demo_recipe" ) publish_recipe(r) pool <- harmonize(list(svy), .verbose = FALSE) # Restore backend options(metasurvey.backend = old)
Check if survey has a design
has_design(svy)has_design(svy)
svy |
A Survey object. |
Logical.
Other survey-objects:
Survey,
cat_design(),
cat_design_type(),
get_data(),
get_metadata(),
has_recipes(),
has_steps(),
is_baked(),
set_data(),
survey_empty(),
survey_to_data_frame(),
survey_to_datatable(),
survey_to_tibble()
svy <- survey_empty(type = "test", edition = "2023") has_design(svy) # FALSEsvy <- survey_empty(type = "test", edition = "2023") has_design(svy) # FALSE
Check if survey has recipes
has_recipes(svy)has_recipes(svy)
svy |
A Survey or RotativePanelSurvey object. |
Logical.
Other survey-objects:
Survey,
cat_design(),
cat_design_type(),
get_data(),
get_metadata(),
has_design(),
has_steps(),
is_baked(),
set_data(),
survey_empty(),
survey_to_data_frame(),
survey_to_datatable(),
survey_to_tibble()
svy <- survey_empty(type = "test", edition = "2023") has_recipes(svy) # FALSEsvy <- survey_empty(type = "test", edition = "2023") has_recipes(svy) # FALSE
Check if survey has steps
has_steps(svy)has_steps(svy)
svy |
A Survey or RotativePanelSurvey object. |
Logical.
Other survey-objects:
Survey,
cat_design(),
cat_design_type(),
get_data(),
get_metadata(),
has_design(),
has_recipes(),
is_baked(),
set_data(),
survey_empty(),
survey_to_data_frame(),
survey_to_datatable(),
survey_to_tibble()
svy <- survey_empty(type = "test", edition = "2023") has_steps(svy) # FALSEsvy <- survey_empty(type = "test", edition = "2023") has_steps(svy) # FALSE
Returns TRUE when every step attached to the survey has been executed (bake == TRUE), or when there are no steps.
is_baked(svy)is_baked(svy)
svy |
A Survey or RotativePanelSurvey object. |
Logical.
Other survey-objects:
Survey,
cat_design(),
cat_design_type(),
get_data(),
get_metadata(),
has_design(),
has_recipes(),
has_steps(),
set_data(),
survey_empty(),
survey_to_data_frame(),
survey_to_datatable(),
survey_to_tibble()
svy <- survey_empty(type = "test", edition = "2023") is_baked(svy) # TRUE (no steps)svy <- survey_empty(type = "test", edition = "2023") is_baked(svy) # TRUE (no steps)
Lazy processing
lazy_default()lazy_default()
Logical indicating the current lazy processing setting.
Other options:
get_engine(),
set_engine(),
set_lazy_processing(),
set_use_copy(),
show_engines(),
use_copy_default()
# Check current lazy processing default lazy_default()# Check current lazy processing default lazy_default()
List all recipes from the active backend.
list_recipes()list_recipes()
List of all Recipe objects.
search_recipes, filter_recipes
Other tidy-api:
RecipeCategory,
RecipeCertification,
RecipeUser,
add_category(),
certify_recipe(),
default_categories(),
filter_recipes(),
filter_workflows(),
find_workflows_for_recipe(),
list_workflows(),
rank_recipes(),
rank_workflows(),
recipe_category(),
recipe_certification(),
recipe_user(),
remove_category(),
search_recipes(),
search_workflows(),
set_user_info(),
set_version()
set_backend("local", path = tempfile(fileext = ".json")) all <- list_recipes() length(all)set_backend("local", path = tempfile(fileext = ".json")) all <- list_recipes() length(all)
List all workflows from the active workflow backend.
list_workflows()list_workflows()
List of all RecipeWorkflow objects.
search_workflows, filter_workflows
Other tidy-api:
RecipeCategory,
RecipeCertification,
RecipeUser,
add_category(),
certify_recipe(),
default_categories(),
filter_recipes(),
filter_workflows(),
find_workflows_for_recipe(),
list_recipes(),
rank_recipes(),
rank_workflows(),
recipe_category(),
recipe_certification(),
recipe_user(),
remove_category(),
search_recipes(),
search_workflows(),
set_user_info(),
set_version()
set_workflow_backend("local", path = tempfile(fileext = ".json")) all <- list_workflows() length(all)set_workflow_backend("local", path = tempfile(fileext = ".json")) all <- list_workflows() length(all)
Read panel survey files from different formats and create a RotativePanelSurvey object
load_panel_survey( path_implantation, path_follow_up, svy_type, svy_weight_implantation, svy_weight_follow_up, svy_strata = NULL, ... )load_panel_survey( path_implantation, path_follow_up, svy_type, svy_weight_implantation, svy_weight_follow_up, svy_strata = NULL, ... )
path_implantation |
Survey implantation path, file can be in different formats, csv, xtsx, dta, sav and rds |
path_follow_up |
Path with all the needed files with only survey valid files but also can be character vector with path files. |
svy_type |
String with the survey type, supported types; "ech" (Encuensta Continua de Hogares, Uruguay), "eph" (Encuesta Permanente de Hogares, Argentina), "eai" (Encuesta de Actividades de Innovacion, Uruguay) |
svy_weight_implantation |
List with survey implantation weights information specifing periodicity and the name of the weight variable. Recomended to use the helper function add_weight(). |
svy_weight_follow_up |
List with survey follow_up weights information specifing periodicity and the name of the weight variable. Recomended to use the helper function add_weight(). |
svy_strata |
Stratification variable name (character or NULL). Passed to Survey$new(strata = ...). |
... |
Further arguments to be passed to load_panel_survey |
RotativePanelSurvey object
Other survey-loading:
extract_time_pattern(),
group_dates(),
load_survey(),
load_survey_example(),
validate_time_pattern()
# Build a small panel from temporary CSV files impl_dir <- tempfile("panel_") follow_dir <- file.path(impl_dir, "follow_up") dir.create(follow_dir, recursive = TRUE) dt <- data.table::data.table(id = 1:20, income = runif(20), w = 1) data.table::fwrite(dt, file.path(impl_dir, "ech_2023.csv")) data.table::fwrite(dt, file.path(follow_dir, "ech_2023_01.csv")) data.table::fwrite(dt, file.path(follow_dir, "ech_2023_02.csv")) panel <- load_panel_survey( path_implantation = file.path(impl_dir, "ech_2023.csv"), path_follow_up = follow_dir, svy_type = "ech", svy_weight_implantation = add_weight(annual = "w"), svy_weight_follow_up = add_weight(monthly = "w") ) panel unlink(impl_dir, recursive = TRUE) ## Not run: # Not run: requires the full ECH 2023 microdata and bootstrap # replicate-weight files on disk path_dir <- here::here("example-data", "ech", "ech_2023") ech_2023 <- load_panel_survey( path_implantation = file.path( path_dir, "ECH_implantacion_2023.csv" ), path_follow_up = file.path( path_dir, "seguimiento" ), svy_type = "ECH_2023", svy_weight_implantation = add_weight( annual = "W_ANO" ), svy_weight_follow_up = add_weight( monthly = add_replicate( "W", replicate_path = file.path( path_dir, c( "Pesos replicados Bootstrap mensuales enero_junio 2023", "Pesos replicados Bootstrap mensuales julio_diciembre 2023" ), c( "Pesos replicados mensuales enero_junio 2023", "Pesos replicados mensuales Julio_diciembre 2023" ) ), replicate_id = c("ID" = "ID"), replicate_pattern = "wr[0-9]+", replicate_type = "bootstrap" ) ) ) ## End(Not run)# Build a small panel from temporary CSV files impl_dir <- tempfile("panel_") follow_dir <- file.path(impl_dir, "follow_up") dir.create(follow_dir, recursive = TRUE) dt <- data.table::data.table(id = 1:20, income = runif(20), w = 1) data.table::fwrite(dt, file.path(impl_dir, "ech_2023.csv")) data.table::fwrite(dt, file.path(follow_dir, "ech_2023_01.csv")) data.table::fwrite(dt, file.path(follow_dir, "ech_2023_02.csv")) panel <- load_panel_survey( path_implantation = file.path(impl_dir, "ech_2023.csv"), path_follow_up = follow_dir, svy_type = "ech", svy_weight_implantation = add_weight(annual = "w"), svy_weight_follow_up = add_weight(monthly = "w") ) panel unlink(impl_dir, recursive = TRUE) ## Not run: # Not run: requires the full ECH 2023 microdata and bootstrap # replicate-weight files on disk path_dir <- here::here("example-data", "ech", "ech_2023") ech_2023 <- load_panel_survey( path_implantation = file.path( path_dir, "ECH_implantacion_2023.csv" ), path_follow_up = file.path( path_dir, "seguimiento" ), svy_type = "ECH_2023", svy_weight_implantation = add_weight( annual = "W_ANO" ), svy_weight_follow_up = add_weight( monthly = add_replicate( "W", replicate_path = file.path( path_dir, c( "Pesos replicados Bootstrap mensuales enero_junio 2023", "Pesos replicados Bootstrap mensuales julio_diciembre 2023" ), c( "Pesos replicados mensuales enero_junio 2023", "Pesos replicados mensuales Julio_diciembre 2023" ) ), replicate_id = c("ID" = "ID"), replicate_pattern = "wr[0-9]+", replicate_type = "bootstrap" ) ) ) ## End(Not run)
This function reads survey files in multiple formats and creates a Survey object with all necessary metadata for subsequent analysis. Supports various survey types with specific configurations for each one.
load_survey( path = NULL, svy_type = NULL, svy_edition = NULL, svy_weight = NULL, svy_psu = NULL, svy_strata = NULL, ..., bake = FALSE, recipes = NULL )load_survey( path = NULL, svy_type = NULL, svy_edition = NULL, svy_weight = NULL, svy_psu = NULL, svy_strata = NULL, ..., bake = FALSE, recipes = NULL )
path |
Path to the survey file. Supports multiple formats: csv, xlsx, dta (Stata), sav (SPSS), rds (R). If NULL, survey arguments must be specified to create an empty object |
svy_type |
Survey type as string. Supported types:
|
svy_edition |
Survey edition as string. Supports different temporal patterns:
|
svy_weight |
List with weight information specifying periodicity and
weight variable name. Use helper function |
svy_psu |
Primary sampling unit (PSU) variable as string |
svy_strata |
Stratification variable name as string (optional).
Used in |
... |
Additional arguments passed to specific reading functions |
bake |
Logical indicating whether recipes are processed automatically when loading data. Defaults to FALSE |
recipes |
Recipe object obtained with |
The function automatically detects file format and uses the appropriate reader. For each survey type, it applies specific configurations such as standard variables, data types, and validations.
When bake=TRUE is specified, recipes are applied immediately after
loading the data, creating an analysis-ready object.
If no path is provided, an empty Survey object is created that can
be used to build step pipelines without initial data.
Survey object with structure:
data: Survey data
metadata: Information about type, edition, weights
steps: History of applied transformations
recipes: Available recipes
design: Sample design information
add_weight to specify weights
get_recipe to get available recipes
load_survey_example to load example data
load_panel_survey for panel surveys
Other survey-loading:
extract_time_pattern(),
group_dates(),
load_panel_survey(),
load_survey_example(),
validate_time_pattern()
# Load the ECH sample bundled with the package ech_sample <- load_survey( path = system.file( "extdata", "ech_2023_sample.csv", package = "metasurvey.core" ), svy_type = "ech", svy_edition = "2023", svy_weight = add_weight(annual = "W_ANO") ) ech_sample ## Not run: # Not run: needs full local microdata files and a configured backend ech_2023 <- load_survey( path = "data/ech_2023.csv", svy_type = "ech", svy_edition = "2023", svy_weight = add_weight(annual = "pesoano"), recipes = get_recipe("ech", "2023"), bake = TRUE ) # Load monthly survey from STATA format ech_january <- load_survey( path = "data/ech_202301.dta", svy_type = "ech", svy_edition = "202301", svy_weight = add_weight(monthly = "pesomes") ) ## End(Not run)# Load the ECH sample bundled with the package ech_sample <- load_survey( path = system.file( "extdata", "ech_2023_sample.csv", package = "metasurvey.core" ), svy_type = "ech", svy_edition = "2023", svy_weight = add_weight(annual = "W_ANO") ) ech_sample ## Not run: # Not run: needs full local microdata files and a configured backend ech_2023 <- load_survey( path = "data/ech_2023.csv", svy_type = "ech", svy_edition = "2023", svy_weight = add_weight(annual = "pesoano"), recipes = get_recipe("ech", "2023"), bake = TRUE ) # Load monthly survey from STATA format ech_january <- load_survey( path = "data/ech_202301.dta", svy_type = "ech", svy_edition = "202301", svy_weight = add_weight(monthly = "pesomes") ) ## End(Not run)
Downloads and loads example survey data from the metasurvey data repository. This function provides access to sample datasets for testing and demonstration purposes, including ECH (Continuous Household Survey) and other survey types.
load_survey_example(svy_type, svy_edition)load_survey_example(svy_type, svy_edition)
svy_type |
Character string specifying the survey type (e.g., "ech") |
svy_edition |
Character string specifying the survey edition/year (e.g., "2023") |
This function downloads example data from the official metasurvey data repository on GitHub. The data is cached locally in a temporary file to avoid repeated downloads in the same session.
Available survey types and editions can be found at: https://github.com/metasurveyr/metasurvey_data
Character string with the path to the downloaded CSV file containing the example survey data
load_survey for loading the downloaded data
Other survey-loading:
extract_time_pattern(),
group_dates(),
load_panel_survey(),
load_survey(),
validate_time_pattern()
## Not run: # Not run: downloads data from GitHub (requires internet access) ech_path <- load_survey_example("ech", "2023") # Use with load_survey ech_data <- load_survey( path = load_survey_example("ech", "2023"), svy_type = "ech", svy_edition = "2023" ) ## End(Not run)## Not run: # Not run: downloads data from GitHub (requires internet access) ech_path <- load_survey_example("ech", "2023") # Use with load_survey ech_data <- load_survey( path = load_survey_example("ech", "2023"), svy_type = "ech", svy_edition = "2023" ) ## End(Not run)
All errors and warnings signalled by metasurvey.core are classed
conditions: they carry a domain-specific subclass plus the package-wide
base class ("metasurvey_error" or "metasurvey_warning"), so you can
handle them with tryCatch()/withCallingHandlers() without matching
message text.
No return value. This topic documents the condition classes
signalled by metasurvey.core; catch them with tryCatch() or
withCallingHandlers() as shown in the examples.
Every error carries "metasurvey_error" plus one of:
metasurvey_input_errorAn argument of an exported function failed input validation (wrong type, wrong class, missing value).
metasurvey_error_stepA step could not be created or baked
(unknown step type, missing variables, failed step_validate()
checks with .action = "stop").
metasurvey_error_recipeA recipe is invalid or cannot be applied (missing metadata, unmet variable dependencies, dependency cycles).
metasurvey_error_workflowA workflow object or a
workflow() estimation is invalid.
metasurvey_error_panelA rotating-panel operation failed (inconsistent waves, invalid extraction).
metasurvey_error_surveyA survey-level operation failed (design construction, weight or replicate specification).
metasurvey_error_engineThe requested processing engine is not supported or not installed.
metasurvey_error_ioA file could not be loaded (unsupported format, missing reader package, failed download).
metasurvey_error_backendA recipe/workflow backend operation failed.
metasurvey_error_backend_unavailableThe "api" backend was
selected but no provider is registered (also carries
metasurvey_error_backend). Install a provider package such as
metasurvey.explorer.backend.
Every warning carries "metasurvey_warning" plus one of
metasurvey_warning_step, metasurvey_warning_recipe,
metasurvey_warning_workflow, metasurvey_warning_panel,
metasurvey_warning_survey, metasurvey_warning_engine or
metasurvey_warning_backend, following the same domains as the error
classes.
# Catch any metasurvey error by its base class tryCatch( set_engine("not-an-engine"), metasurvey_error = function(e) message("caught: ", conditionMessage(e)) ) # Or target a specific domain tryCatch( set_engine("not-an-engine"), metasurvey_error_engine = function(e) "engine problem" )# Catch any metasurvey error by its base class tryCatch( set_engine("not-an-engine"), metasurvey_error = function(e) message("caught: ", conditionMessage(e)) ) # Or target a specific domain tryCatch( set_engine("not-an-engine"), metasurvey_error_engine = function(e) "engine problem" )
All behavior toggles of metasurvey.core are controlled through R
options() under the metasurvey. prefix. None of them needs to be
set explicitly: every option has a working default.
No return value. This topic documents the global options recognized by metasurvey.core and their defaults.
metasurvey.engineCharacter. Data-processing engine used
when loading surveys. Default "data.table" (set on load). Change
it with set_engine(); see show_engines() for the available
engines.
metasurvey.lazy_processingLogical, default TRUE. When
TRUE, step_*() functions record transformations without
executing them until bake_steps() is called. Set with
set_lazy_processing(); query with lazy_default().
metasurvey.use_copyLogical, default TRUE. When TRUE,
steps operate on a copy of the survey so the original object is
never modified in place. Set with set_use_copy(); query with
use_copy_default().
metasurvey.verboseLogical, default TRUE. Gates all
informational messages emitted by the package. Set it to FALSE
to silence them; errors and warnings are not affected.
metasurvey.backendA RecipeBackend object holding the
active recipe backend. Unset by default (an in-memory local
backend is used). Configure with set_backend(); query with
get_backend().
metasurvey.workflow_backendA WorkflowBackend object
holding the active workflow backend. Unset by default (an
in-memory local backend is used). Configure with
set_workflow_backend(); query with get_workflow_backend().
metasurvey.backend_providerA function (op, args) that
implements the remote ("api") backend. Default NULL: core has
no network access, and selecting the "api" backend without a
registered provider signals a
metasurvey_error_backend_unavailable error (see
metasurvey_conditions). Companion packages such as
metasurvey.explorer.backend register the provider on load.
metasurvey.skip_recipesLogical, default FALSE. When
TRUE, get_recipe() skips every backend lookup and returns
NULL with a warning: useful for fully offline runs.
# Silence informational messages for a session old <- options(metasurvey.verbose = FALSE) options(old) # Current engine and laziness getOption("metasurvey.engine") lazy_default()# Silence informational messages for a session old <- options(metasurvey.verbose = FALSE) options(old) # Current engine and laziness getOption("metasurvey.engine") lazy_default()
This class represents a collection of surveys grouped by specific periods (e.g., monthly, quarterly, annual). It provides methods to access and manipulate the grouped surveys.
An object of class PoolSurvey.
surveysA list containing the grouped surveys.
PoolSurvey$new()Initializes a new instance of the PoolSurvey class.
PoolSurvey$new(surveys)
surveysA list containing the grouped surveys.
PoolSurvey$get_surveys()Retrieves surveys for a specific period.
PoolSurvey$get_surveys(period = NULL)
periodA string specifying the period to retrieve (e.g., "monthly", "quarterly").
A list of surveys for the specified period.
PoolSurvey$print()Prints metadata about the PoolSurvey object.
PoolSurvey$print()
PoolSurvey$clone()The objects of this class are cloneable with this method.
PoolSurvey$clone(deep = FALSE)
deepWhether to make a deep clone.
Other panel-surveys:
RotativePanelSurvey,
extract_surveys(),
get_follow_up(),
get_implantation()
s1 <- Survey$new( data = data.table::data.table(id = 1:3, w = 1), edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) s2 <- Survey$new( data = data.table::data.table(id = 4:6, w = 1), edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) pool <- PoolSurvey$new(list(annual = list("group1" = list(s1, s2))))s1 <- Survey$new( data = data.table::data.table(id = 1:3, w = 1), edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) s2 <- Survey$new( data = data.table::data.table(id = 4:6, w = 1), edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) pool <- PoolSurvey$new(list(annual = list("group1" = list(s1, s2))))
Print provenance information
## S3 method for class 'metasurvey_provenance' print(x, ...)## S3 method for class 'metasurvey_provenance' print(x, ...)
x |
A |
... |
Additional arguments (unused). |
Invisibly returns x.
Other provenance:
print.metasurvey_provenance_diff(),
provenance(),
provenance_diff(),
provenance_to_json()
s <- survey_empty("ech", "2023") s <- set_data(s, data.table::data.table(age = 18:65)) s <- step_compute(s, age2 = age * 2) s <- bake_steps(s) print(provenance(s))s <- survey_empty("ech", "2023") s <- set_data(s, data.table::data.table(age = 18:65)) s <- step_compute(s, age2 = age * 2) s <- bake_steps(s) print(provenance(s))
Print provenance diff
## S3 method for class 'metasurvey_provenance_diff' print(x, ...)## S3 method for class 'metasurvey_provenance_diff' print(x, ...)
x |
A |
... |
Additional arguments (unused). |
Invisibly returns x.
Other provenance:
print.metasurvey_provenance(),
provenance(),
provenance_diff(),
provenance_to_json()
s1 <- survey_empty("ech", "2022") s1 <- set_data(s1, data.table::data.table(age = 18:65)) s1 <- step_compute(s1, age2 = age * 2) s1 <- bake_steps(s1) s2 <- survey_empty("ech", "2023") s2 <- set_data(s2, data.table::data.table(age = 20:70)) s2 <- step_compute(s2, age2 = age * 2) s2 <- bake_steps(s2) diff_result <- provenance_diff(provenance(s1), provenance(s2)) print(diff_result)s1 <- survey_empty("ech", "2022") s1 <- set_data(s1, data.table::data.table(age = 18:65)) s1 <- step_compute(s1, age2 = age * 2) s1 <- bake_steps(s1) s2 <- survey_empty("ech", "2023") s2 <- set_data(s2, data.table::data.table(age = 20:70)) s2 <- step_compute(s2, age2 = age * 2) s2 <- bake_steps(s2) diff_result <- provenance_diff(provenance(s1), provenance(s2)) print(diff_result)
Displays a formatted recipe card showing metadata, required variables, pipeline steps, and produced variables.
## S3 method for class 'Recipe' print(x, ...)## S3 method for class 'Recipe' print(x, ...)
x |
A Recipe object |
... |
Additional arguments (currently unused) |
Invisibly returns the Recipe object
Other recipes:
Recipe-class,
add_recipe(),
bake_recipes(),
get_recipe(),
harmonize(),
publish_recipe(),
read_recipe(),
recipe(),
save_recipe(),
steps_to_recipe()
rec <- Recipe$new( id = "r1", name = "Example", user = "tester", edition = "2023", survey_type = "test", default_engine = "data.table", depends_on = list(), description = "Demo recipe", steps = list() ) print(rec)rec <- Recipe$new( id = "r1", name = "Example", user = "tester", edition = "2023", survey_type = "test", default_engine = "data.table", depends_on = list(), description = "Demo recipe", steps = list() ) print(rec)
Print method for RecipeWorkflow objects
## S3 method for class 'RecipeWorkflow' print(x, ...)## S3 method for class 'RecipeWorkflow' print(x, ...)
x |
A RecipeWorkflow object |
... |
Additional arguments (unused) |
Invisibly returns the object
Other workflows:
RecipeWorkflow-class,
evaluate_cv(),
publish_workflow(),
read_workflow(),
save_workflow(),
workflow(),
workflow_from_list(),
workflow_table()
wf <- RecipeWorkflow$new( id = "w1", name = "Example Workflow", user = "tester", edition = "2023", survey_type = "test", recipe_ids = "r1", calls = list(), description = "Demo" ) print(wf)wf <- RecipeWorkflow$new( id = "w1", name = "Example Workflow", user = "tester", edition = "2023", survey_type = "test", recipe_ids = "r1", calls = list(), description = "Demo" ) print(wf)
Returns the provenance metadata recording the full data lineage: source file, step history with row counts, and environment info.
provenance(x, ...) ## S3 method for class 'Survey' provenance(x, ...) ## S3 method for class 'data.table' provenance(x, ...) ## Default S3 method: provenance(x, ...)provenance(x, ...) ## S3 method for class 'Survey' provenance(x, ...) ## S3 method for class 'data.table' provenance(x, ...) ## Default S3 method: provenance(x, ...)
x |
A Survey object or a |
... |
Additional arguments (unused). |
A metasurvey_provenance list, or NULL if no provenance
is available.
Other provenance:
print.metasurvey_provenance(),
print.metasurvey_provenance_diff(),
provenance_diff(),
provenance_to_json()
svy <- Survey$new( data = data.table::data.table(id = 1:10, age = 20:29, w = 1), edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) provenance(svy)svy <- Survey$new( data = data.table::data.table(id = 1:10, age = 20:29, w = 1), edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) provenance(svy)
Shows differences between two provenance records, useful for comparing processing across survey editions.
provenance_diff(prov1, prov2)provenance_diff(prov1, prov2)
prov1 |
First provenance list. |
prov2 |
Second provenance list. |
A metasurvey_provenance_diff list with detected differences.
Other provenance:
print.metasurvey_provenance(),
print.metasurvey_provenance_diff(),
provenance(),
provenance_to_json()
svy1 <- Survey$new( data = data.table::data.table(id = 1:5, w = rep(1, 5)), edition = "2023", type = "test", engine = "data.table", weight = add_weight(annual = "w") ) svy2 <- Survey$new( data = data.table::data.table(id = 1:5, w = rep(2, 5)), edition = "2024", type = "test", engine = "data.table", weight = add_weight(annual = "w") ) provenance_diff(provenance(svy1), provenance(svy2))svy1 <- Survey$new( data = data.table::data.table(id = 1:5, w = rep(1, 5)), edition = "2023", type = "test", engine = "data.table", weight = add_weight(annual = "w") ) svy2 <- Survey$new( data = data.table::data.table(id = 1:5, w = rep(2, 5)), edition = "2024", type = "test", engine = "data.table", weight = add_weight(annual = "w") ) provenance_diff(provenance(svy1), provenance(svy2))
Serializes a provenance object to JSON format, optionally writing to a file.
provenance_to_json(prov, path = NULL)provenance_to_json(prov, path = NULL)
prov |
A |
path |
File path to write JSON. If |
JSON string (invisibly if path is provided).
Other provenance:
print.metasurvey_provenance(),
print.metasurvey_provenance_diff(),
provenance(),
provenance_diff()
svy <- Survey$new( data = data.table::data.table(id = 1:5, w = rep(1, 5)), edition = "2023", type = "test", engine = "data.table", weight = add_weight(annual = "w") ) prov <- provenance(svy) provenance_to_json(prov)svy <- Survey$new( data = data.table::data.table(id = 1:5, w = rep(1, 5)), edition = "2023", type = "test", engine = "data.table", weight = add_weight(annual = "w") ) prov <- provenance(svy) provenance_to_json(prov)
Publishes a Recipe object to the active backend (local JSON registry or remote API).
publish_recipe(recipe)publish_recipe(recipe)
recipe |
A Recipe object. |
The Recipe object (invisibly).
Other recipes:
Recipe-class,
add_recipe(),
bake_recipes(),
get_recipe(),
harmonize(),
print.Recipe(),
read_recipe(),
recipe(),
save_recipe(),
steps_to_recipe()
set_backend("local", path = tempfile(fileext = ".json")) r <- recipe( name = "Example", user = "Test", svy = survey_empty(type = "ech", edition = "2023"), description = "Example recipe" ) publish_recipe(r) length(list_recipes())set_backend("local", path = tempfile(fileext = ".json")) r <- recipe( name = "Example", user = "Test", svy = survey_empty(type = "ech", edition = "2023"), description = "Example recipe" ) publish_recipe(r) length(list_recipes())
Publishes a RecipeWorkflow to the configured workflow backend.
publish_workflow(wf)publish_workflow(wf)
wf |
A RecipeWorkflow object. |
NULL (called for side effect).
set_workflow_backend, RecipeWorkflow
Other workflows:
RecipeWorkflow-class,
evaluate_cv(),
print.RecipeWorkflow(),
read_workflow(),
save_workflow(),
workflow(),
workflow_from_list(),
workflow_table()
set_workflow_backend("local", path = tempfile(fileext = ".json")) wf <- RecipeWorkflow$new( name = "Example", description = "Test", survey_type = "ech", edition = "2023", recipe_ids = "r_001", estimation_type = "svymean" ) publish_workflow(wf)set_workflow_backend("local", path = tempfile(fileext = ".json")) wf <- RecipeWorkflow$new( name = "Example", description = "Test", survey_type = "ech", edition = "2023", recipe_ids = "r_001", estimation_type = "svymean" ) publish_workflow(wf)
Get the top recipes ranked by download count from the active backend.
rank_recipes(n = NULL)rank_recipes(n = NULL)
n |
Integer. Maximum number of recipes to return, or NULL for all. |
List of Recipe objects sorted by downloads (descending).
search_recipes, filter_recipes
Other tidy-api:
RecipeCategory,
RecipeCertification,
RecipeUser,
add_category(),
certify_recipe(),
default_categories(),
filter_recipes(),
filter_workflows(),
find_workflows_for_recipe(),
list_recipes(),
list_workflows(),
rank_workflows(),
recipe_category(),
recipe_certification(),
recipe_user(),
remove_category(),
search_recipes(),
search_workflows(),
set_user_info(),
set_version()
set_backend("local", path = tempfile(fileext = ".json")) top10 <- rank_recipes(n = 10)set_backend("local", path = tempfile(fileext = ".json")) top10 <- rank_recipes(n = 10)
Get the top workflows ranked by download count.
rank_workflows(n = NULL)rank_workflows(n = NULL)
n |
Integer or |
List of RecipeWorkflow objects sorted by downloads.
search_workflows, filter_workflows
Other tidy-api:
RecipeCategory,
RecipeCertification,
RecipeUser,
add_category(),
certify_recipe(),
default_categories(),
filter_recipes(),
filter_workflows(),
find_workflows_for_recipe(),
list_recipes(),
list_workflows(),
rank_recipes(),
recipe_category(),
recipe_certification(),
recipe_user(),
remove_category(),
search_recipes(),
search_workflows(),
set_user_info(),
set_version()
set_workflow_backend("local", path = tempfile(fileext = ".json")) top5 <- rank_workflows(n = 5) length(top5)set_workflow_backend("local", path = tempfile(fileext = ".json")) top5 <- rank_workflows(n = 5) length(top5)
Reads a Recipe object from a JSON file.
read_recipe(file)read_recipe(file)
file |
A character string specifying the file path. |
This function reads a JSON file and decodes it into a Recipe object.
A Recipe object.
Other recipes:
Recipe-class,
add_recipe(),
bake_recipes(),
get_recipe(),
harmonize(),
print.Recipe(),
publish_recipe(),
recipe(),
save_recipe(),
steps_to_recipe()
r <- recipe( name = "Example", user = "Test", svy = survey_empty(type = "ech", edition = "2023"), description = "Example recipe" ) f <- tempfile(fileext = ".json") save_recipe(r, f) r2 <- read_recipe(f) r2r <- recipe( name = "Example", user = "Test", svy = survey_empty(type = "ech", edition = "2023"), description = "Example recipe" ) f <- tempfile(fileext = ".json") save_recipe(r, f) r2 <- read_recipe(f) r2
Read a RecipeWorkflow from a JSON file
read_workflow(file)read_workflow(file)
file |
Character file path |
A RecipeWorkflow object
Other workflows:
RecipeWorkflow-class,
evaluate_cv(),
print.RecipeWorkflow(),
publish_workflow(),
save_workflow(),
workflow(),
workflow_from_list(),
workflow_table()
wf <- RecipeWorkflow$new( name = "Example", description = "Test", survey_type = "ech", edition = "2023", recipe_ids = "r_001", estimation_type = "svymean" ) f <- tempfile(fileext = ".json") save_workflow(wf, f) wf2 <- read_workflow(f)wf <- RecipeWorkflow$new( name = "Example", description = "Test", survey_type = "ech", edition = "2023", recipe_ids = "r_001", estimation_type = "svymean" ) f <- tempfile(fileext = ".json") save_workflow(wf, f) wf2 <- read_workflow(f)
Creates a Recipe object that encapsulates a sequence of data transformations that can be applied to surveys in a reproducible manner. Recipes allow documenting, sharing, and reusing data processing workflows.
recipe(...)recipe(...)
... |
Required metadata and optional steps. Required parameters:
Optional parameters include data transformation steps. |
Recipes are essential for:
Reproducibility: Ensure transformations are applied consistently
Documentation: Keep a record of what transformations are performed and why
Collaboration: Share workflows between users and teams
Versioning: Maintain different processing versions for different editions
Automation: Apply complex transformations automatically
Steps included in the recipe can be any combination of
step_compute, step_recode, or other transformation steps.
Recipes can be saved with save_recipe(), loaded with
read_recipe(), and applied automatically with bake_recipes().
A Recipe object containing metadata, transformation steps,
dependency information, and default engine configuration.
Recipe for class definition
save_recipe to save recipes
read_recipe to load recipes
get_recipe to retrieve recipes from repository
bake_recipes to apply recipes to data
Other recipes:
Recipe-class,
add_recipe(),
bake_recipes(),
get_recipe(),
harmonize(),
print.Recipe(),
publish_recipe(),
read_recipe(),
save_recipe(),
steps_to_recipe()
# Basic recipe without steps r <- recipe( name = "Basic ECH Indicators", user = "Analyst", svy = survey_empty(type = "ech", edition = "2023"), description = "Basic labor indicators for ECH 2023" ) r # Recipe with steps using local data dt <- data.table::data.table( id = 1:50, age = sample(18:65, 50, TRUE), income = runif(50, 1000, 5000), w = runif(50, 0.5, 2) ) svy <- Survey$new( data = dt, edition = "2023", type = "demo", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) svy <- svy |> step_compute(income_cat = ifelse(income > 3000, "high", "low")) |> step_recode(age_group, age < 30 ~ "young", .default = "adult") r2 <- recipe( name = "Demo", user = "test", svy = svy, description = "Demo recipe", steps = get_steps(svy) ) r2# Basic recipe without steps r <- recipe( name = "Basic ECH Indicators", user = "Analyst", svy = survey_empty(type = "ech", edition = "2023"), description = "Basic labor indicators for ECH 2023" ) r # Recipe with steps using local data dt <- data.table::data.table( id = 1:50, age = sample(18:65, 50, TRUE), income = runif(50, 1000, 5000), w = runif(50, 0.5, 2) ) svy <- Survey$new( data = dt, edition = "2023", type = "demo", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) svy <- svy |> step_compute(income_cat = ifelse(income > 3000, "high", "low")) |> step_recode(age_group, age < 30 ~ "young", .default = "adult") r2 <- recipe( name = "Demo", user = "test", svy = svy, description = "Demo recipe", steps = get_steps(svy) ) r2
Creates a RecipeCategory object for classifying recipes.
recipe_category(name, description = "", parent = NULL)recipe_category(name, description = "", parent = NULL)
name |
Character. Category identifier (e.g. |
description |
Character. Human-readable description. Defaults to empty. |
parent |
RecipeCategory object or character parent
category name (default |
A RecipeCategory object.
RecipeCategory, add_category,
default_categories
Other tidy-api:
RecipeCategory,
RecipeCertification,
RecipeUser,
add_category(),
certify_recipe(),
default_categories(),
filter_recipes(),
filter_workflows(),
find_workflows_for_recipe(),
list_recipes(),
list_workflows(),
rank_recipes(),
rank_workflows(),
recipe_certification(),
recipe_user(),
remove_category(),
search_recipes(),
search_workflows(),
set_user_info(),
set_version()
cat <- recipe_category("labor_market", "Labor market indicators") # With parent hierarchy sub <- recipe_category( "employment", "Employment stats", parent = "labor_market" )cat <- recipe_category("labor_market", "Labor market indicators") # With parent hierarchy sub <- recipe_category( "employment", "Employment stats", parent = "labor_market" )
Creates a RecipeCertification object. Typically you would use
certify_recipe to certify a recipe in a pipeline instead.
recipe_certification(level = "community", certified_by = NULL, notes = NULL)recipe_certification(level = "community", certified_by = NULL, notes = NULL)
level |
Character. One of |
certified_by |
RecipeUser or |
notes |
Character or |
A RecipeCertification object.
RecipeCertification, certify_recipe
Other tidy-api:
RecipeCategory,
RecipeCertification,
RecipeUser,
add_category(),
certify_recipe(),
default_categories(),
filter_recipes(),
filter_workflows(),
find_workflows_for_recipe(),
list_recipes(),
list_workflows(),
rank_recipes(),
rank_workflows(),
recipe_category(),
recipe_user(),
remove_category(),
search_recipes(),
search_workflows(),
set_user_info(),
set_version()
# Default community certification cert <- recipe_certification() # Official certification inst <- recipe_user("IECON", type = "institution") cert <- recipe_certification("official", certified_by = inst)# Default community certification cert <- recipe_certification() # Official certification inst <- recipe_user("IECON", type = "institution") cert <- recipe_certification("official", certified_by = inst)
Creates a RecipeUser object with a simple
functional interface.
recipe_user( name, type = "individual", email = NULL, affiliation = NULL, institution = NULL, url = NULL, verified = FALSE )recipe_user( name, type = "individual", email = NULL, affiliation = NULL, institution = NULL, url = NULL, verified = FALSE )
name |
Character. User or institution name. |
type |
Character. One of |
email |
Character or |
affiliation |
Character or |
institution |
RecipeUser object or character institution name.
Required for |
url |
Character or |
verified |
Logical (default |
A RecipeUser object.
RecipeUser,
set_user_info,
certify_recipe
Other tidy-api:
RecipeCategory,
RecipeCertification,
RecipeUser,
add_category(),
certify_recipe(),
default_categories(),
filter_recipes(),
filter_workflows(),
find_workflows_for_recipe(),
list_recipes(),
list_workflows(),
rank_recipes(),
rank_workflows(),
recipe_category(),
recipe_certification(),
remove_category(),
search_recipes(),
search_workflows(),
set_user_info(),
set_version()
# Individual user user <- recipe_user("Juan Perez", email = "[email protected]") # Institution inst <- recipe_user( "Instituto de Economia", type = "institution", verified = TRUE ) # Member linked to institution member <- recipe_user( "Maria", type = "institutional_member", institution = inst ) # Member with institution name shortcut member2 <- recipe_user( "Pedro", type = "institutional_member", institution = "IECON" )# Individual user user <- recipe_user("Juan Perez", email = "[email protected]") # Institution inst <- recipe_user( "Instituto de Economia", type = "institution", verified = TRUE ) # Member linked to institution member <- recipe_user( "Maria", type = "institutional_member", institution = inst ) # Member with institution name shortcut member2 <- recipe_user( "Pedro", type = "institutional_member", institution = "IECON" )
R6 class representing a reproducible data transformation recipe for surveys. It encapsulates metadata, declared dependencies, and a list of transformation steps to be applied to a Survey object.
An R6 class generator (R6ClassGenerator)
An object of class Recipe.
Class constructor.
Auto-generate documentation from recipe steps. Returns a list with metadata, input_variables, output_variables, and pipeline information.
Validate that a survey object has all required input variables.
nameDescriptive name of the recipe (character).
editionTarget edition/period (character or Date).
survey_typeSurvey type (character), e.g., "ech", "eaii".
default_engineDefault evaluation engine (character).
depends_onVector/list of dependencies declared by the steps.
userAuthor/owner (character).
descriptionRecipe description (character).
idUnique identifier (character/numeric).
stepsList of step calls that make up the workflow.
doiDOI or external identifier (character|NULL).
bakeLogical flag indicating whether it has been applied.
topicRecipe topic (character|NULL).
step_objectsList of Step R6 objects (list|NULL), used for documentation generation.
categoriesList of RecipeCategory objects for classification.
downloadsInteger download/usage count.
certificationRecipeCertification object (default community).
user_infoRecipeUser object or NULL.
versionRecipe version string.
depends_on_recipesList of recipe IDs that must be applied before this one.
data_sourceList with S3 bucket info (s3_bucket, s3_prefix, file_pattern, provider) or NULL.
labelsList with variable and value labels (var_labels, val_labels) or NULL.
Recipe$new()Create a Recipe object
Recipe$new( name, edition, survey_type, default_engine, depends_on, user, description, steps, id, doi = NULL, topic = NULL, step_objects = NULL, cached_doc = NULL, categories = list(), downloads = 0L, certification = NULL, user_info = NULL, version = "1.0.0", depends_on_recipes = list(), data_source = NULL, labels = NULL )
nameDescriptive name of the recipe (character)
editionTarget edition/period (character or Date)
survey_typeSurvey type (character), e.g., "ech", "eaii"
default_engineDefault evaluation engine (character)
depends_onVector or list of declared dependencies
userAuthor or owner of the recipe (character)
descriptionDetailed description of the recipe (character)
stepsList of step calls that make up the workflow
idUnique identifier (character or numeric)
doiDOI or external identifier (character or NULL)
topicRecipe topic (character or NULL)
step_objectsList of Step R6 objects (optional, used for doc generation)
cached_docPre-computed documentation (optional, used when loading from JSON)
categoriesList of RecipeCategory objects (optional)
downloadsInteger download count (default 0)
certificationRecipeCertification object (optional, default community)
user_infoRecipeUser object (optional)
versionRecipe version string (default "1.0.0")
depends_on_recipesList of recipe IDs that must be applied before this one (optional)
data_sourceList with S3 bucket info (optional)
labelsList with var_labels and val_labels (optional)
Recipe$increment_downloads()Increment the download counter
Recipe$increment_downloads()
Recipe$certify()Certify the recipe at a given level
Recipe$certify(user, level)
userRecipeUser who is certifying
levelCharacter certification level ("reviewed" or "official")
Recipe$add_category()Add a category to the recipe
Recipe$add_category(category)
categoryRecipeCategory to add
Recipe$remove_category()Remove a category by name
Recipe$remove_category(name)
nameCharacter category name to remove
Recipe$to_list()Serialize Recipe to a plain list suitable for JSON/API publishing. Steps are encoded as character strings via deparse().
Recipe$to_list()
A named list with all recipe fields.
Recipe$doc()Auto-generate documentation from recipe steps
Recipe$doc()
A list with metadata, input_variables, output_variables, and pipeline information
Recipe$validate()Validate that a survey has all required input variables
Recipe$validate(svy)
svyA Survey object
TRUE if valid, otherwise stops with error listing missing variables
Recipe$clone()The objects of this class are cloneable with this method.
Recipe$clone(deep = FALSE)
deepWhether to make a deep clone.
recipe, save_recipe,
read_recipe, bake_recipes
Other recipes:
add_recipe(),
bake_recipes(),
get_recipe(),
harmonize(),
print.Recipe(),
publish_recipe(),
read_recipe(),
recipe(),
save_recipe(),
steps_to_recipe()
# Use the recipe() constructor: svy <- survey_empty(type = "ech", edition = "2023") r <- recipe( name = "Example", user = "Test", svy = svy, description = "Example recipe" )# Use the recipe() constructor: svy <- survey_empty(type = "ech", edition = "2023") r <- recipe( name = "Example", user = "Test", svy = svy, description = "Example recipe" )
Standardized taxonomy for classifying recipes by domain. Supports hierarchical categories with parent-child relationships.
An R6 object of class RecipeCategory.
nameCharacter. Category identifier.
descriptionCharacter. Human-readable description.
parentRecipeCategory or NULL. Parent category for hierarchy.
RecipeCategory$new()Create a new RecipeCategory
RecipeCategory$new(name, description, parent = NULL)
nameCharacter. Category identifier (non-empty string).
descriptionCharacter. Description of the category.
parentRecipeCategory or NULL. Parent category.
RecipeCategory$is_subcategory_of()Check if this category is a subcategory of another
RecipeCategory$is_subcategory_of(ancestor_name)
ancestor_nameCharacter. Name of the potential ancestor category.
Logical
RecipeCategory$get_path()Get full hierarchical path
RecipeCategory$get_path()
Character string with slash-separated path
RecipeCategory$equals()Check equality by name
RecipeCategory$equals(other)
otherRecipeCategory to compare with.
Logical
RecipeCategory$to_list()Serialize to list for JSON
RecipeCategory$to_list()
List representation
RecipeCategory$print()Print category
RecipeCategory$print(...)
...Additional arguments (not used)
RecipeCategory$from_list()Deserialize a RecipeCategory from a list
RecipeCategory$from_list(lst)
lstList with name, description, parent fields, or NULL
RecipeCategory object or NULL
RecipeCategory$clone()The objects of this class are cloneable with this method.
RecipeCategory$clone(deep = FALSE)
deepWhether to make a deep clone.
Other tidy-api:
RecipeCertification,
RecipeUser,
add_category(),
certify_recipe(),
default_categories(),
filter_recipes(),
filter_workflows(),
find_workflows_for_recipe(),
list_recipes(),
list_workflows(),
rank_recipes(),
rank_workflows(),
recipe_category(),
recipe_certification(),
recipe_user(),
remove_category(),
search_recipes(),
search_workflows(),
set_user_info(),
set_version()
# Use recipe_category() for the public API: cat <- recipe_category( "economics", "Economic indicators" ) sub <- recipe_category( "labor_market", "Labor market", parent = "economics" )# Use recipe_category() for the public API: cat <- recipe_category( "economics", "Economic indicators" ) sub <- recipe_category( "labor_market", "Labor market", parent = "economics" )
Quality certification for recipes with three tiers: community (default), reviewed (peer-reviewed by institutional member), and official (certified by institution).
An object of class RecipeCertification.
levelCharacter. Certification level.
certified_byRecipeUser or NULL. The certifying user.
certified_atPOSIXct. Timestamp of certification.
notesCharacter or NULL. Additional notes.
RecipeCertification$new()Create a new RecipeCertification
RecipeCertification$new( level, certified_by = NULL, notes = NULL, certified_at = NULL )
levelCharacter. One of "community", "reviewed", "official".
certified_byRecipeUser or NULL. Required for reviewed/official.
notesCharacter or NULL. Additional notes.
certified_atPOSIXct or NULL. Auto-set if NULL.
RecipeCertification$numeric_level()Get numeric level for ordering (1=community, 2=reviewed, 3=official)
RecipeCertification$numeric_level()
Integer
RecipeCertification$is_at_least()Check if certification is at least a given level
RecipeCertification$is_at_least(level)
levelCharacter. Level to compare against.
Logical
RecipeCertification$to_list()Serialize to list for JSON
RecipeCertification$to_list()
List representation
RecipeCertification$print()Print certification badge
RecipeCertification$print(...)
...Additional arguments (not used)
RecipeCertification$clone()The objects of this class are cloneable with this method.
RecipeCertification$clone(deep = FALSE)
deepWhether to make a deep clone.
Other tidy-api:
RecipeCategory,
RecipeUser,
add_category(),
certify_recipe(),
default_categories(),
filter_recipes(),
filter_workflows(),
find_workflows_for_recipe(),
list_recipes(),
list_workflows(),
rank_recipes(),
rank_workflows(),
recipe_category(),
recipe_certification(),
recipe_user(),
remove_category(),
search_recipes(),
search_workflows(),
set_user_info(),
set_version()
# Use recipe_certification() for the public API: cert <- recipe_certification() inst <- recipe_user("IECON", type = "institution") official <- recipe_certification("official", certified_by = inst)# Use recipe_certification() for the public API: cert <- recipe_certification() inst <- recipe_user("IECON", type = "institution") official <- recipe_certification("official", certified_by = inst)
User identity for the recipe ecosystem. Supports three account types: individual, institutional_member, and institution.
An object of class RecipeUser.
nameCharacter. User or institution name.
emailCharacter or NULL. Email address.
user_typeCharacter. One of "individual", "institutional_member", "institution".
affiliationCharacter or NULL. Organizational affiliation.
institutionRecipeUser or NULL. Parent institution (for institutional_member).
urlCharacter or NULL. Institution URL.
verifiedLogical. Whether the account is verified.
review_statusCharacter. One of "approved", "pending", "rejected".
RecipeUser$new()Create a new RecipeUser
RecipeUser$new( name, user_type, email = NULL, affiliation = NULL, institution = NULL, url = NULL, verified = FALSE, review_status = "approved" )
nameCharacter. User or institution name.
user_typeCharacter. One of "individual", "institutional_member", "institution".
emailCharacter or NULL. Email address.
affiliationCharacter or NULL. Organizational affiliation.
institutionRecipeUser or NULL. Parent institution for institutional_member.
urlCharacter or NULL. Institution URL.
verifiedLogical. Whether account is verified.
review_statusCharacter. "approved", "pending", or "rejected".
RecipeUser$trust_level()Get trust level (1=individual, 2=member, 3=institution)
RecipeUser$trust_level()
Integer trust level
RecipeUser$can_certify()Check if user can certify at a given level
RecipeUser$can_certify(level)
levelCharacter. Certification level ("reviewed" or "official").
Logical
RecipeUser$to_list()Serialize to list for JSON
RecipeUser$to_list()
List representation
RecipeUser$print()Print user card
RecipeUser$print(...)
...Additional arguments (not used)
RecipeUser$clone()The objects of this class are cloneable with this method.
RecipeUser$clone(deep = FALSE)
deepWhether to make a deep clone.
Other tidy-api:
RecipeCategory,
RecipeCertification,
add_category(),
certify_recipe(),
default_categories(),
filter_recipes(),
filter_workflows(),
find_workflows_for_recipe(),
list_recipes(),
list_workflows(),
rank_recipes(),
rank_workflows(),
recipe_category(),
recipe_certification(),
recipe_user(),
remove_category(),
search_recipes(),
search_workflows(),
set_user_info(),
set_version()
# Use recipe_user() for the public API: user <- recipe_user("Juan Perez", email = "[email protected]") inst <- recipe_user("IECON", type = "institution") member <- recipe_user( "Maria", type = "institutional_member", institution = inst )# Use recipe_user() for the public API: user <- recipe_user("Juan Perez", email = "[email protected]") inst <- recipe_user("IECON", type = "institution") member <- recipe_user( "Maria", type = "institutional_member", institution = inst )
R6 class representing a publishable workflow that captures statistical estimations applied to survey data. Workflows reference the recipes they use and document the estimation calls made.
An R6 class generator (R6ClassGenerator)
An object of class RecipeWorkflow.
Class constructor.
Generate documentation for the workflow.
Serialize to a plain list for JSON export.
Increment the download counter.
Add a category.
Certify the workflow.
idUnique identifier (character).
nameDescriptive name (character).
descriptionWorkflow description (character).
userAuthor/owner (character).
user_infoRecipeUser object or NULL.
survey_typeSurvey type (character).
editionSurvey edition (character).
estimation_typeCharacter vector of estimation types used.
recipe_idsCharacter vector of recipe IDs referenced.
callsList of deparsed call strings.
call_metadataList of lists with type, formula, by, description fields.
categoriesList of RecipeCategory objects.
downloadsInteger download count.
certificationRecipeCertification object.
versionVersion string.
doiDOI or external identifier (character|NULL).
created_atCreation timestamp (character).
weight_specNamed list with weight configuration per periodicity (list|NULL).
RecipeWorkflow$new()Create a RecipeWorkflow object
RecipeWorkflow$new( id = NULL, name, description = "", user = "Unknown", user_info = NULL, survey_type = "Unknown", edition = "Unknown", estimation_type = character(0), recipe_ids = character(0), calls = list(), call_metadata = list(), categories = list(), downloads = 0L, certification = NULL, version = "1.0.0", doi = NULL, created_at = NULL, weight_spec = NULL )
idUnique identifier
nameDescriptive name
descriptionWorkflow description
userAuthor name
user_infoRecipeUser object or NULL
survey_typeSurvey type
editionSurvey edition
estimation_typeCharacter vector of estimation types
recipe_idsCharacter vector of recipe IDs
callsList of deparsed call strings
call_metadataList of call metadata lists
categoriesList of RecipeCategory objects
downloadsInteger download count
certificationRecipeCertification or NULL
versionVersion string
doiDOI or NULL
created_atTimestamp string or NULL (auto-generated)
weight_specNamed list with weight configuration per periodicity
RecipeWorkflow$doc()Generate documentation for this workflow
RecipeWorkflow$doc()
List with meta, recipe_ids, estimations, and estimation_types
RecipeWorkflow$to_list()Serialize to a plain list for JSON export
RecipeWorkflow$to_list()
A list suitable for jsonlite::write_json
RecipeWorkflow$increment_downloads()Increment the download counter
RecipeWorkflow$increment_downloads()
RecipeWorkflow$certify()Certify the workflow at a given level
RecipeWorkflow$certify(user, level)
userRecipeUser who is certifying
levelCharacter certification level
RecipeWorkflow$add_category()Add a category to the workflow
RecipeWorkflow$add_category(category)
categoryRecipeCategory to add
RecipeWorkflow$remove_category()Remove a category by name
RecipeWorkflow$remove_category(name)
nameCharacter category name to remove
RecipeWorkflow$clone()The objects of this class are cloneable with this method.
RecipeWorkflow$clone(deep = FALSE)
deepWhether to make a deep clone.
save_workflow, read_workflow,
workflow
Other workflows:
evaluate_cv(),
print.RecipeWorkflow(),
publish_workflow(),
read_workflow(),
save_workflow(),
workflow(),
workflow_from_list(),
workflow_table()
wf <- RecipeWorkflow$new( name = "Labor workflow", description = "Unemployment rate", user = "test", survey_type = "ech", edition = "2023", estimation_type = "annual", recipe_ids = "r_001", calls = list("svymean(~desocupado, na.rm = TRUE)") )wf <- RecipeWorkflow$new( name = "Labor workflow", description = "Unemployment rate", user = "test", survey_type = "ech", edition = "2023", estimation_type = "annual", recipe_ids = "r_001", calls = list("svymean(~desocupado, na.rm = TRUE)") )
Pipe-friendly function to remove a category from a Recipe by name.
remove_category(recipe, name)remove_category(recipe, name)
recipe |
A Recipe object. |
name |
Character. Category name to remove. |
The modified Recipe object.
Other tidy-api:
RecipeCategory,
RecipeCertification,
RecipeUser,
add_category(),
certify_recipe(),
default_categories(),
filter_recipes(),
filter_workflows(),
find_workflows_for_recipe(),
list_recipes(),
list_workflows(),
rank_recipes(),
rank_workflows(),
recipe_category(),
recipe_certification(),
recipe_user(),
search_recipes(),
search_workflows(),
set_user_info(),
set_version()
r <- recipe( name = "Example", user = "Test", svy = survey_empty(type = "ech", edition = "2023"), description = "Example recipe" ) r <- r |> add_category("labor_market") |> remove_category("labor_market")r <- recipe( name = "Example", user = "Test", svy = survey_empty(type = "ech", edition = "2023"), description = "Example recipe" ) r <- r |> add_category("labor_market") |> remove_category("labor_market")
This class represents a rotative panel survey, which includes implantation and follow-up surveys. It provides methods to access and manipulate survey data, steps, recipes, workflows, and designs.
An object of class RotativePanelSurvey.
implantationA survey object representing the implantation survey.
follow_upA list of survey objects representing the follow-up surveys.
typeA string indicating the type of the survey.
default_engineA string specifying the default engine used for processing.
stepsA list of steps applied to the survey.
recipesA list of recipes associated with the survey.
workflowsA list of workflows associated with the survey.
designA design object for the survey.
periodicityA list containing the periodicity of the implantation and follow-up surveys.
RotativePanelSurvey$new()Initializes a new instance of the RotativePanelSurvey class.
RotativePanelSurvey$new( implantation, follow_up, type, default_engine, steps, recipes, workflows, design )
implantationA survey object representing the implantation survey.
follow_upA list of survey objects representing the follow-up surveys.
typeA string indicating the type of the survey.
default_engineA string specifying the default engine used for processing.
stepsA list of steps applied to the survey.
recipesA list of recipes associated with the survey.
workflowsA list of workflows associated with the survey.
designA design object for the survey.
RotativePanelSurvey$get_implantation()Retrieves the implantation survey.
RotativePanelSurvey$get_implantation()
A survey object representing the implantation survey.
RotativePanelSurvey$get_follow_up()Retrieves the follow-up surveys.
RotativePanelSurvey$get_follow_up( index = length(self$follow_up), monthly = NULL, quarterly = NULL, semiannual = NULL, annual = NULL )
indexAn integer specifying the index of the follow-up survey to retrieve.
monthlyA vector of integers specifying monthly intervals.
quarterlyA vector of integers specifying quarterly intervals.
semiannualA vector of integers specifying semiannual intervals.
annualA vector of integers specifying annual intervals.
A list of follow-up surveys matching the specified criteria.
RotativePanelSurvey$get_type()Retrieves the type of the survey.
RotativePanelSurvey$get_type()
A string indicating the type of the survey.
RotativePanelSurvey$get_default_engine()Retrieves the default engine used for processing.
RotativePanelSurvey$get_default_engine()
A string specifying the default engine.
RotativePanelSurvey$get_steps()Retrieves the steps applied to the survey.
RotativePanelSurvey$get_steps()
A list containing the steps for the implantation and follow-up surveys.
RotativePanelSurvey$get_recipes()Retrieves the recipes associated with the survey.
RotativePanelSurvey$get_recipes()
A list of recipes.
RotativePanelSurvey$get_workflows()Retrieves the workflows associated with the survey.
RotativePanelSurvey$get_workflows()
A list of workflows.
RotativePanelSurvey$get_design()Retrieves the design object for the survey.
RotativePanelSurvey$get_design()
A design object.
RotativePanelSurvey$print()Prints metadata about the RotativePanelSurvey object.
RotativePanelSurvey$print()
RotativePanelSurvey$clone()The objects of this class are cloneable with this method.
RotativePanelSurvey$clone(deep = FALSE)
deepWhether to make a deep clone.
Other panel-surveys:
PoolSurvey,
extract_surveys(),
get_follow_up(),
get_implantation()
impl <- Survey$new( data = data.table::data.table(id = 1:5, w = 1), edition = "2023", type = "ech", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) fu1 <- Survey$new( data = data.table::data.table(id = 1:5, w = 1), edition = "2023_01", type = "ech", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) panel <- RotativePanelSurvey$new( implantation = impl, follow_up = list(fu1), type = "ech", default_engine = "data.table", steps = list(), recipes = list(), workflows = list(), design = NULL )impl <- Survey$new( data = data.table::data.table(id = 1:5, w = 1), edition = "2023", type = "ech", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) fu1 <- Survey$new( data = data.table::data.table(id = 1:5, w = 1), edition = "2023_01", type = "ech", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) panel <- RotativePanelSurvey$new( implantation = impl, follow_up = list(fu1), type = "ech", default_engine = "data.table", steps = list(), recipes = list(), workflows = list(), design = NULL )
Saves a Recipe object to a file in JSON format.
save_recipe(recipe, file)save_recipe(recipe, file)
recipe |
A Recipe object. |
file |
A character string specifying the file path. |
This function encodes the Recipe object and writes it to a JSON file.
NULL.
Other recipes:
Recipe-class,
add_recipe(),
bake_recipes(),
get_recipe(),
harmonize(),
print.Recipe(),
publish_recipe(),
read_recipe(),
recipe(),
steps_to_recipe()
r <- recipe( name = "Example", user = "Test", svy = survey_empty(type = "ech", edition = "2023"), description = "Example recipe" ) f <- tempfile(fileext = ".json") save_recipe(r, f)r <- recipe( name = "Example", user = "Test", svy = survey_empty(type = "ech", edition = "2023"), description = "Example recipe" ) f <- tempfile(fileext = ".json") save_recipe(r, f)
Save a RecipeWorkflow to a JSON file
save_workflow(wf, file)save_workflow(wf, file)
wf |
A RecipeWorkflow object |
file |
Character file path |
NULL (called for side-effect)
Other workflows:
RecipeWorkflow-class,
evaluate_cv(),
print.RecipeWorkflow(),
publish_workflow(),
read_workflow(),
workflow(),
workflow_from_list(),
workflow_table()
wf <- RecipeWorkflow$new( name = "Example", description = "Test", survey_type = "ech", edition = "2023", recipe_ids = "r_001", estimation_type = "svymean" ) f <- tempfile(fileext = ".json") save_workflow(wf, f)wf <- RecipeWorkflow$new( name = "Example", description = "Test", survey_type = "ech", edition = "2023", recipe_ids = "r_001", estimation_type = "svymean" ) f <- tempfile(fileext = ".json") save_workflow(wf, f)
Search for recipes by name or description in the active backend.
search_recipes(query)search_recipes(query)
query |
Character search string. |
List of matching Recipe objects.
filter_recipes, rank_recipes,
set_backend
Other tidy-api:
RecipeCategory,
RecipeCertification,
RecipeUser,
add_category(),
certify_recipe(),
default_categories(),
filter_recipes(),
filter_workflows(),
find_workflows_for_recipe(),
list_recipes(),
list_workflows(),
rank_recipes(),
rank_workflows(),
recipe_category(),
recipe_certification(),
recipe_user(),
remove_category(),
search_workflows(),
set_user_info(),
set_version()
set_backend("local", path = tempfile(fileext = ".json")) r <- recipe( name = "Labor Market", user = "Test", svy = survey_empty(type = "ech", edition = "2023"), description = "Labor market indicators" ) publish_recipe(r) results <- search_recipes("labor") length(results)set_backend("local", path = tempfile(fileext = ".json")) r <- recipe( name = "Labor Market", user = "Test", svy = survey_empty(type = "ech", edition = "2023"), description = "Labor market indicators" ) publish_recipe(r) results <- search_recipes("labor") length(results)
Search for workflows by name or description in the active workflow backend.
search_workflows(query)search_workflows(query)
query |
Character search string. |
List of matching RecipeWorkflow objects.
filter_workflows, rank_workflows
Other tidy-api:
RecipeCategory,
RecipeCertification,
RecipeUser,
add_category(),
certify_recipe(),
default_categories(),
filter_recipes(),
filter_workflows(),
find_workflows_for_recipe(),
list_recipes(),
list_workflows(),
rank_recipes(),
rank_workflows(),
recipe_category(),
recipe_certification(),
recipe_user(),
remove_category(),
search_recipes(),
set_user_info(),
set_version()
set_workflow_backend("local", path = tempfile(fileext = ".json")) results <- search_workflows("labor market") length(results)set_workflow_backend("local", path = tempfile(fileext = ".json")) results <- search_workflows("labor market") length(results)
Configure the active recipe backend via options.
set_backend(type, path = NULL)set_backend(type, path = NULL)
type |
Character. "local" or "api" (also accepts "mongo" for backward compat). |
path |
Character. File path for local backend. |
Invisibly, the RecipeBackend object created.
Other backends:
get_backend(),
get_workflow_backend(),
set_workflow_backend()
set_backend("local", path = tempfile(fileext = ".json"))set_backend("local", path = tempfile(fileext = ".json"))
Tidy wrapper for svy$set_data(data).
set_data(svy, data, .copy = FALSE)set_data(svy, data, .copy = FALSE)
svy |
Survey object |
data |
A data.frame or data.table with survey microdata |
.copy |
Logical; if TRUE, clone the Survey before modifying (default FALSE) |
The Survey object (invisibly). If
.copy=TRUE, returns a new clone.
Other survey-objects:
Survey,
cat_design(),
cat_design_type(),
get_data(),
get_metadata(),
has_design(),
has_recipes(),
has_steps(),
is_baked(),
survey_empty(),
survey_to_data_frame(),
survey_to_datatable(),
survey_to_tibble()
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") ) new_dt <- data.table::data.table(id = 1:3, x = rnorm(3), w = rep(1, 3)) svy <- set_data(svy, new_dt)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") ) new_dt <- data.table::data.table(id = 1:3, x = rnorm(3), w = rep(1, 3)) svy <- set_data(svy, new_dt)
Configures the engine to be used for loading surveys. Checks if the provided engine is supported, sets the default engine if none is specified, and generates a message indicating the configured engine. If the engine is not supported, it throws an error.
set_engine(.engine = show_engines())set_engine(.engine = show_engines())
.engine |
Character vector with the name of the
engine to configure. By default, the engine returned
by the |
Invisibly, the previous engine name (for restoring).
Other options:
get_engine(),
lazy_default(),
set_lazy_processing(),
set_use_copy(),
show_engines(),
use_copy_default()
old <- set_engine("data.table") get_engine()old <- set_engine("data.table") get_engine()
Set lazy processing
set_lazy_processing(lazy)set_lazy_processing(lazy)
lazy |
Logical. If TRUE, steps are deferred until bake_steps() is called. |
Invisibly, the previous value.
Other options:
get_engine(),
lazy_default(),
set_engine(),
set_use_copy(),
show_engines(),
use_copy_default()
old <- lazy_default() set_lazy_processing(FALSE) lazy_default() # now FALSE set_lazy_processing(old) # restoreold <- lazy_default() set_lazy_processing(FALSE) lazy_default() # now FALSE set_lazy_processing(old) # restore
Configures whether survey operations should create copies of the data or modify existing data in place. This setting affects memory usage and performance across the metasurvey package.
set_use_copy(use_copy)set_use_copy(use_copy)
use_copy |
Logical value: TRUE to create data copies (safer), FALSE to modify data in place (more efficient) |
Setting use_copy affects all subsequent survey operations:
TRUE (default): Operations create data copies, preserving original data
FALSE: Operations modify data in place, reducing memory usage
Use FALSE for large datasets where memory is a concern, but ensure you don't need the original data after operations.
Invisibly, the previous value (for restoring).
use_copy_default to check current setting
Other options:
get_engine(),
lazy_default(),
set_engine(),
set_lazy_processing(),
show_engines(),
use_copy_default()
# Set to use copies (default behavior) set_use_copy(TRUE) use_copy_default() # Set to modify in place for better performance set_use_copy(FALSE) use_copy_default() # Reset to default set_use_copy(TRUE)# Set to use copies (default behavior) set_use_copy(TRUE) use_copy_default() # Set to modify in place for better performance set_use_copy(FALSE) use_copy_default() # Reset to default set_use_copy(TRUE)
Pipe-friendly function to assign a RecipeUser to a Recipe.
set_user_info(recipe, user)set_user_info(recipe, user)
recipe |
A Recipe object. |
user |
A RecipeUser object. |
The modified Recipe object.
Other tidy-api:
RecipeCategory,
RecipeCertification,
RecipeUser,
add_category(),
certify_recipe(),
default_categories(),
filter_recipes(),
filter_workflows(),
find_workflows_for_recipe(),
list_recipes(),
list_workflows(),
rank_recipes(),
rank_workflows(),
recipe_category(),
recipe_certification(),
recipe_user(),
remove_category(),
search_recipes(),
search_workflows(),
set_version()
r <- recipe( name = "Example", user = "Test", svy = survey_empty(type = "ech", edition = "2023"), description = "Example recipe" ) user <- recipe_user("Juan Perez", email = "[email protected]") r <- r |> set_user_info(user)r <- recipe( name = "Example", user = "Test", svy = survey_empty(type = "ech", edition = "2023"), description = "Example recipe" ) user <- recipe_user("Juan Perez", email = "[email protected]") r <- r |> set_user_info(user)
Pipe-friendly function to set the version string on a Recipe.
set_version(recipe, version)set_version(recipe, version)
recipe |
A Recipe object. |
version |
Character version string (e.g. |
The modified Recipe object.
Other tidy-api:
RecipeCategory,
RecipeCertification,
RecipeUser,
add_category(),
certify_recipe(),
default_categories(),
filter_recipes(),
filter_workflows(),
find_workflows_for_recipe(),
list_recipes(),
list_workflows(),
rank_recipes(),
rank_workflows(),
recipe_category(),
recipe_certification(),
recipe_user(),
remove_category(),
search_recipes(),
search_workflows(),
set_user_info()
r <- recipe( name = "Example", user = "Test", svy = survey_empty(type = "ech", edition = "2023"), description = "Example recipe" ) r <- r |> set_version("2.0.0")r <- recipe( name = "Example", user = "Test", svy = survey_empty(type = "ech", edition = "2023"), description = "Example recipe" ) r <- r |> set_version("2.0.0")
Configure the active workflow backend via options.
set_workflow_backend(type, path = NULL)set_workflow_backend(type, path = NULL)
type |
Character. "local" or "api" (also accepts "mongo" for backward compat). |
path |
Character. File path for local backend. |
Invisibly, the WorkflowBackend object created.
Other backends:
get_backend(),
get_workflow_backend(),
set_backend()
set_workflow_backend("local", path = tempfile(fileext = ".json"))set_workflow_backend("local", path = tempfile(fileext = ".json"))
Returns a character vector of available engines that can be used for loading surveys.
show_engines()show_engines()
Character vector with the names of the available engines.
Other options:
get_engine(),
lazy_default(),
set_engine(),
set_lazy_processing(),
set_use_copy(),
use_copy_default()
show_engines()show_engines()
Creates a step that collapses the survey data to a single row per group, typically one row per household, so that estimations can be run at the group level with the group's weight (e.g. share of households receiving a transfer).
step_collapse( svy, by, rule = c("first", "max", "min"), .copy = use_copy_default(), comment = "Collapse step", lazy = lazy_default(), record = TRUE )step_collapse( svy, by, rule = c("first", "max", "min"), .copy = use_copy_default(), comment = "Collapse step", lazy = lazy_default(), record = TRUE )
svy |
A Survey or RotativePanelSurvey object. |
by |
Character vector of grouping variables that identify the group (e.g. the household id). |
rule |
How to build the collapsed row (default
|
.copy |
Whether to operate on a copy (default: |
comment |
Descriptive text for the step (default |
lazy |
Internal. Currently ignored: the collapse is always applied immediately and the step is recorded as executed. |
record |
Internal. Whether to record the step (default |
Execution model: The collapse is applied immediately when the step
is created and the step is recorded as already executed (bake = TRUE).
Calling bake_steps() afterwards is safe: executed steps are skipped,
so the data is never collapsed twice.
Interaction with the sampling design: After collapsing, each row
represents one group (household), so the weight column now acts as the
group weight and subsequent estimations are at the group level. The
design is invalidated and rebuilt from the collapsed data on the next
estimation. In household surveys the person weight is constant within
the household, so the collapsed weight is the household weight; if the
weight varies within a group, a warning is issued because the collapsed
weight is ambiguous (it is taken with rule like any other column).
rule = "max" reproduces the person-to-household propagation pattern
("order decreasing + distinct by household id"): a dummy that is 1 for
any household member becomes 1 in the collapsed household row.
The survey object with one row per by group and the step
recorded.
step_quantile() for weighted quantile groups (e.g. household
income quintiles after collapsing).
Other steps:
bake_steps(),
get_steps(),
step_compute(),
step_filter(),
step_join(),
step_quantile(),
step_recode(),
step_remove(),
step_rename(),
step_validate(),
view_graph()
dt <- data.table::data.table( hh = c(1, 1, 2, 2, 3), person = 1:5, receives = c(0, 1, 0, 0, 1), w = c(2, 2, 3, 3, 1) ) svy <- Survey$new( data = dt, edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) hh_svy <- step_collapse(svy, by = "hh", rule = "max") get_data(hh_svy) # one row per household, receives = max over membersdt <- data.table::data.table( hh = c(1, 1, 2, 2, 3), person = 1:5, receives = c(0, 1, 0, 0, 1), w = c(2, 2, 3, 3, 1) ) svy <- Survey$new( data = dt, edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) hh_svy <- step_collapse(svy, by = "hh", rule = "max") get_data(hh_svy) # one row per household, receives = max over members
This function uses optimized expression evaluation with automatic dependency detection and error prevention. All computations are validated before execution.
step_compute( svy = NULL, ..., .by = NULL, .copy = use_copy_default(), comment = "Compute step", .level = "auto", use_copy = deprecated() )step_compute( svy = NULL, ..., .by = NULL, .copy = use_copy_default(), comment = "Compute step", .level = "auto", use_copy = deprecated() )
svy |
A |
... |
Computation expressions with automatic
optimization. Names are assigned using
|
.by |
Vector of variables to group computations by. The system automatically validates these variables exist before execution |
.copy |
Logical indicating whether to create
a copy of the object before applying
transformations. Defaults to |
comment |
Descriptive text for the step for documentation and traceability. Compatible with Markdown syntax. Defaults to "Compute step" |
.level |
For RotativePanelSurvey objects (default |
use_copy |
Execution model: The computation is applied immediately when the
step is created and the step is recorded as already executed
(bake = TRUE). Calling bake_steps() afterwards is safe: executed
steps are skipped, so expressions are never applied twice.
Expression processing:
Expressions are evaluated using data.table's := operator.
Within a single call, expressions are evaluated sequentially, so a
later expression can reference variables created by earlier ones
(mutate semantics): step_compute(svy, horamen = f85 * 4.3, yhora = pt4 / horamen). Variable dependencies are detected
automatically via all.vars(); names created by earlier expressions
of the same call are not reported as dependencies.
Missing variables are caught before execution.
Grouped computations: Use .by to compute aggregated values
(e.g., group means) broadcast to all rows of each group. Row order
is preserved.
For RotativePanelSurvey objects, .level controls where computations
are applied:
"auto" (default): applies to both implantation and follow-ups
"implantation": household/dwelling level only
"follow_up": individual/person level only
Same type of input object (Survey or RotativePanelSurvey)
with new computed variables and the step added to the history
step_recode for categorical recodings
bake_steps to execute all pending steps
Other steps:
bake_steps(),
get_steps(),
step_collapse(),
step_filter(),
step_join(),
step_quantile(),
step_recode(),
step_remove(),
step_rename(),
step_validate(),
view_graph()
# Basic computation dt <- data.table::data.table( id = 1:5, age = c(25, 30, 45, 50, 60), w = 1 ) svy <- Survey$new( data = dt, edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) svy <- svy |> step_compute(age_squared = age^2, comment = "Age squared") svy <- bake_steps(svy) get_data(svy) # ECH example: labor indicator # ech <- ech |> # step_compute( # unemployed = ifelse(POBPCOAC %in% 3:5, 1, 0), # comment = "Unemployment indicator")# Basic computation dt <- data.table::data.table( id = 1:5, age = c(25, 30, 45, 50, 60), w = 1 ) svy <- Survey$new( data = dt, edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) svy <- svy |> step_compute(age_squared = age^2, comment = "Age squared") svy <- bake_steps(svy) get_data(svy) # ECH example: labor indicator # ech <- ech |> # step_compute( # unemployed = ifelse(POBPCOAC %in% 3:5, 1, 0), # comment = "Unemployment indicator")
Creates a step that filters (subsets) rows from the survey data based on logical conditions. Multiple conditions are combined with AND.
step_filter( svy, ..., .by = NULL, .copy = use_copy_default(), comment = "Filter step", .level = "auto" )step_filter( svy, ..., .by = NULL, .copy = use_copy_default(), comment = "Filter step", .level = "auto" )
svy |
A Survey or RotativePanelSurvey object. |
... |
Logical expressions evaluated against the data. Each must return a logical vector. Multiple conditions are combined with AND. |
.by |
Optional grouping variable(s) for within-group filtering. |
.copy |
Whether to operate on a copy (default: |
comment |
Descriptive text for the step (default |
.level |
For RotativePanelSurvey, the level to apply
(default |
Lazy evaluation (default): Like all steps, filter is recorded but
not executed until bake_steps() is called.
The survey object with rows filtered and the step recorded.
Other steps:
bake_steps(),
get_steps(),
step_collapse(),
step_compute(),
step_join(),
step_quantile(),
step_recode(),
step_remove(),
step_rename(),
step_validate(),
view_graph()
svy <- Survey$new( data = data.table::data.table( id = 1:10, age = c(15, 25, 35, 45, 55, 65, 75, 20, 30, 40), w = 1 ), edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) svy <- svy |> step_filter(age >= 18) |> bake_steps() nrow(get_data(svy))svy <- Survey$new( data = data.table::data.table( id = 1:10, age = c(15, 25, 35, 45, 55, 65, 75, 20, 30, 40), w = 1 ), edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) svy <- svy |> step_filter(age >= 18) |> bake_steps() nrow(get_data(svy))
Creates a step that joins additional data into a Survey or RotativePanelSurvey.
step_join( svy, x, by = NULL, type = c("left", "inner", "right", "full"), suffixes = c("", ".y"), .copy = use_copy_default(), comment = "Join step", use_copy = deprecated(), lazy = lazy_default(), record = TRUE )step_join( svy, x, by = NULL, type = c("left", "inner", "right", "full"), suffixes = c("", ".y"), .copy = use_copy_default(), comment = "Join step", use_copy = deprecated(), lazy = lazy_default(), record = TRUE )
svy |
A Survey or RotativePanelSurvey object. If NULL, returns a step call |
x |
A data.frame/data.table or a Survey to join into |
by |
Character vector of join keys. Named vector for different names
between |
type |
Join type: "left" (default), "inner", "right", or "full" |
suffixes |
Length-2 character vector of suffixes
for conflicting columns
from |
.copy |
Whether to operate on a copy (default: use_copy_default()) |
comment |
Optional description for the step (default |
use_copy |
|
lazy |
Internal. Currently ignored: the join always executes immediately and the step is recorded as executed. |
record |
Internal. Whether to record the step (default |
Execution model: The join is applied immediately when the step is
created and the step is recorded as already executed (bake = TRUE).
Calling bake_steps() afterwards is safe: executed steps are skipped,
so the join is never applied twice (which would duplicate overlapping
columns with the .y suffix).
Supports left, inner, right, and full joins. Allows named by
mapping (e.g., c("id" = "code")) or a simple character vector.
Conflicting column names are resolved by appending suffixes
to the right-hand side columns.
Modified survey object with the join recorded as a step (and applied immediately when baked). For RotativePanelSurvey, the join is applied to implantation and every follow_up survey.
Other steps:
bake_steps(),
get_steps(),
step_collapse(),
step_compute(),
step_filter(),
step_quantile(),
step_recode(),
step_remove(),
step_rename(),
step_validate(),
view_graph()
# With data.frame s <- Survey$new( data = data.table::data.table(id = 1:3, w = 1, a = c("x", "y", "z")), edition = "2023", type = "ech", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) info <- data.frame(id = c(1, 2), b = c(10, 20)) s2 <- step_join(s, info, by = "id", type = "left") s2 <- bake_steps(s2) # With another Survey s_right <- Survey$new( data = data.table::data.table(id = c(2, 3), b = c(200, 300), w2 = 1), edition = "2023", type = "ech", psu = NULL, engine = "data.table", weight = add_weight(annual = "w2") ) s3 <- step_join(s, s_right, by = c("id" = "id"), type = "inner") s3 <- bake_steps(s3)# With data.frame s <- Survey$new( data = data.table::data.table(id = 1:3, w = 1, a = c("x", "y", "z")), edition = "2023", type = "ech", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) info <- data.frame(id = c(1, 2), b = c(10, 20)) s2 <- step_join(s, info, by = "id", type = "left") s2 <- bake_steps(s2) # With another Survey s_right <- Survey$new( data = data.table::data.table(id = c(2, 3), b = c(200, 300), w2 = 1), edition = "2023", type = "ech", psu = NULL, engine = "data.table", weight = add_weight(annual = "w2") ) s3 <- step_join(s, s_right, by = c("id" = "id"), type = "inner") s3 <- bake_steps(s3)
Creates a step that assigns each row to a weighted quantile group (quintiles, deciles, ...) of a numeric variable, e.g. income quintiles at the household level. Quantiles are computed directly on the weighted ECDF, without expanding the data by the weights.
step_quantile( svy, new_var, x, n = 5, weight = NULL, .by = NULL, .copy = use_copy_default(), comment = "Quantile step", lazy = lazy_default(), record = TRUE )step_quantile( svy, new_var, x, n = 5, weight = NULL, .by = NULL, .copy = use_copy_default(), comment = "Quantile step", lazy = lazy_default(), record = TRUE )
svy |
A Survey or RotativePanelSurvey object. |
new_var |
Name of the new group variable (unquoted or character). |
x |
Name of the numeric variable to split into quantile groups (unquoted or character). Must be an existing column. |
n |
Number of groups (default |
weight |
Name of the weight column (unquoted or character). Defaults to the survey's own weight. |
.by |
Optional character vector of grouping variables: quantile breaks are computed independently within each group. |
.copy |
Whether to operate on a copy (default: |
comment |
Descriptive text for the step (default |
lazy |
Internal. Currently ignored: the groups are always computed immediately and the step is recorded as executed. |
record |
Internal. Whether to record the step (default |
Execution model: The quantile groups are computed immediately when
the step is created and the step is recorded as already executed
(bake = TRUE). Calling bake_steps() afterwards is safe: executed
steps are skipped.
Algorithm: The break for probability p is the right-continuous
inverse of the weighted ECDF, inf{x : F_w(x) >= p}. This matches
survey::svyquantile(qrule = "math") and, for integer weights,
quantile(rep(x, w), type = 1), but runs in O(n log n) instead of
O(sum(w)) memory. Rows are then assigned with intervals
(q[k-1], q[k]]; rows with NA in x get NA. If breaks are tied
(heavily discrete x), fewer than n groups can result.
For household-level quantiles (one observation per household), collapse
first with step_collapse() or compute on a household-level survey.
The survey object with new_var added (integer codes 1..n)
and the step recorded.
step_collapse() to collapse to household level before
computing household quantiles.
Other steps:
bake_steps(),
get_steps(),
step_collapse(),
step_compute(),
step_filter(),
step_join(),
step_recode(),
step_remove(),
step_rename(),
step_validate(),
view_graph()
dt <- data.table::data.table( id = 1:10, income = c(1:10) * 100, w = rep(1, 10) ) svy <- Survey$new( data = dt, edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) svy <- step_quantile(svy, income_q, income, n = 5) get_data(svy)$income_qdt <- data.table::data.table( id = 1:10, income = c(1:10) * 100, w = rep(1, 10) ) svy <- Survey$new( data = dt, edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) svy <- step_quantile(svy, income_q, income, n = 5) get_data(svy)$income_q
This function uses optimized expression evaluation for all recoding conditions. All conditional expressions are validated and optimized for efficient execution.
step_recode( svy, new_var, ..., .default = NA_character_, .name_step = NULL, ordered = FALSE, .copy = use_copy_default(), comment = "Recode step", .to_factor = FALSE, .level = "auto", use_copy = deprecated() )step_recode( svy, new_var, ..., .default = NA_character_, .name_step = NULL, ordered = FALSE, .copy = use_copy_default(), comment = "Recode step", .to_factor = FALSE, .level = "auto", use_copy = deprecated() )
Execution model: The recoding is applied immediately when the
step is created and the step is recorded as already executed
(bake = TRUE). Calling bake_steps() afterwards is safe: executed
steps are skipped, so rules are never applied twice.
Condition evaluation: Conditions are two-sided formulas evaluated
in order. The first matching condition determines the assigned value.
If no condition matches, .default is used. Replacement values keep
their native type (character, numeric, integer or logical).
Condition examples:
Simple: variable == 1 ~ "Yes"
Complex: age >= 18 & income > 12000 ~ "High"
Vectorized: variable %in% c(1,2,3) ~ "Group A"
Logical: !is.na(education) ~ "Has education"
Same type of input object (Survey or RotativePanelSurvey)
with the new recoded variable and the step added to the history
step_compute for more complex calculations
bake_steps to execute all pending steps
get_steps to view step history
Other steps:
bake_steps(),
get_steps(),
step_collapse(),
step_compute(),
step_filter(),
step_join(),
step_quantile(),
step_remove(),
step_rename(),
step_validate(),
view_graph()
# Basic recode: categorize ages dt <- data.table::data.table( id = 1:6, age = c(10, 25, 45, 60, 70, 80), w = 1 ) svy <- Survey$new( data = dt, edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) svy <- svy |> step_recode( age_group, age < 18 ~ "Under 18", age >= 18 & age < 65 ~ "Working age", age >= 65 ~ "Senior", .default = "Unknown" ) svy <- bake_steps(svy) get_data(svy) # ECH example: labor force status # ech <- ech |> # step_recode(labor_status, # POBPCOAC == 2 ~ "Employed", # POBPCOAC %in% 3:5 ~ "Unemployed", # .default = "Missing")# Basic recode: categorize ages dt <- data.table::data.table( id = 1:6, age = c(10, 25, 45, 60, 70, 80), w = 1 ) svy <- Survey$new( data = dt, edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) svy <- svy |> step_recode( age_group, age < 18 ~ "Under 18", age >= 18 & age < 65 ~ "Working age", age >= 65 ~ "Senior", .default = "Unknown" ) svy <- bake_steps(svy) get_data(svy) # ECH example: labor force status # ech <- ech |> # step_recode(labor_status, # POBPCOAC == 2 ~ "Employed", # POBPCOAC %in% 3:5 ~ "Unemployed", # .default = "Missing")
Creates a step that removes one or more variables from the survey data when baked.
step_remove( svy, ..., vars = NULL, .copy = use_copy_default(), comment = "Remove variables", use_copy = deprecated(), lazy = lazy_default(), record = TRUE )step_remove( svy, ..., vars = NULL, .copy = use_copy_default(), comment = "Remove variables", use_copy = deprecated(), lazy = lazy_default(), record = TRUE )
svy |
A Survey or RotativePanelSurvey object |
... |
Unquoted variable names to remove, or a character vector |
vars |
Character vector of variable names to remove.
Alternative to |
.copy |
Whether to operate on a copy (default: |
comment |
Descriptive text for the step for
documentation and traceability (default |
use_copy |
|
lazy |
Internal. Whether to delay execution (default |
record |
Internal. Whether to record the step (default |
Lazy evaluation (default): By default, steps are recorded but
not executed until bake_steps() is called.
Variables can be specified in two ways:
Unquoted names: step_remove(svy, age, income)
Character vector: step_remove(svy, vars = c("age", "income"))
Name resolution: bare symbols passed via ... that match a
column name always refer to that column, even if a variable with
the same name exists in the calling environment (column takes
precedence). Symbols that do not match any column are looked up in
the calling environment and, if they hold a character vector, its
values are used as column names. For fully programmatic use prefer
vars = c("age", "income"), which skips symbol resolution entirely.
Variables that don't exist in the data produce a warning (not an error), allowing pipelines to be robust to missing columns.
Survey object with the specified variables removed (or queued for removal).
Other steps:
bake_steps(),
get_steps(),
step_collapse(),
step_compute(),
step_filter(),
step_join(),
step_quantile(),
step_recode(),
step_rename(),
step_validate(),
view_graph()
dt <- data.table::data.table( id = 1:5, age = c(25, 30, 45, 50, 60), w = rep(1, 5) ) svy <- Survey$new( data = dt, edition = "2023", type = "ech", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) svy2 <- step_remove(svy, age) svy2 <- bake_steps(svy2) "age" %in% names(get_data(svy2)) # FALSEdt <- data.table::data.table( id = 1:5, age = c(25, 30, 45, 50, 60), w = rep(1, 5) ) svy <- Survey$new( data = dt, edition = "2023", type = "ech", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) svy2 <- step_remove(svy, age) svy2 <- bake_steps(svy2) "age" %in% names(get_data(svy2)) # FALSE
Creates a step that renames variables in the survey data when baked.
step_rename( svy, ..., mapping = NULL, .copy = use_copy_default(), comment = "Rename variables", use_copy = deprecated(), lazy = lazy_default(), record = TRUE )step_rename( svy, ..., mapping = NULL, .copy = use_copy_default(), comment = "Rename variables", use_copy = deprecated(), lazy = lazy_default(), record = TRUE )
svy |
A Survey or RotativePanelSurvey object |
... |
Pairs in the form |
mapping |
A named character vector of the form
|
.copy |
Whether to operate on a copy (default: |
comment |
Descriptive text for the step for
documentation and traceability (default |
use_copy |
|
lazy |
Internal. Whether to delay execution (default |
record |
Internal. Whether to record the step (default |
Lazy evaluation (default): By default, steps are recorded but
not executed until bake_steps() is called.
Variables can be renamed in two ways:
Unquoted pairs: step_rename(svy, new_name = old_name)
Named character vector: step_rename(svy, mapping = c(new_name = "old_name"))
Variables that don't exist in the data cause an error, unlike
step_remove() which issues a warning.
Survey object with the specified variables renamed (or queued for renaming).
Other steps:
bake_steps(),
get_steps(),
step_collapse(),
step_compute(),
step_filter(),
step_join(),
step_quantile(),
step_recode(),
step_remove(),
step_validate(),
view_graph()
dt <- data.table::data.table( id = 1:5, age = c(25, 30, 45, 50, 60), w = rep(1, 5) ) svy <- Survey$new( data = dt, edition = "2023", type = "ech", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) svy2 <- step_rename(svy, edad = age) svy2 <- bake_steps(svy2) "edad" %in% names(get_data(svy2)) # TRUEdt <- data.table::data.table( id = 1:5, age = c(25, 30, 45, 50, 60), w = rep(1, 5) ) svy <- Survey$new( data = dt, edition = "2023", type = "ech", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) svy2 <- step_rename(svy, edad = age) svy2 <- bake_steps(svy2) "edad" %in% names(get_data(svy2)) # TRUE
Creates a non-mutating step that checks data invariants when
bake_steps is called. Each check is a logical expression
evaluated row-wise against the survey data. If any row fails a check,
the pipeline stops (or warns).
step_validate( svy, ..., .action = c("stop", "warn"), .min_n = NULL, .copy = use_copy_default(), comment = "Validate step" )step_validate( svy, ..., .action = c("stop", "warn"), .min_n = NULL, .copy = use_copy_default(), comment = "Validate step" )
svy |
A Survey or RotativePanelSurvey object |
... |
Logical expressions evaluated against the data. Each must
return a logical vector with one value per row. Named expressions
use the name in error messages; unnamed expressions use the deparsed
code. Examples: |
.action |
What to do when a check fails: |
.min_n |
Minimum number of rows required. Checked before row-level expressions. |
.copy |
Whether to operate on a copy (default:
|
comment |
Descriptive text for the step for documentation
and traceability (default |
Lazy evaluation (default): Like all steps, validation checks are
recorded but not executed until bake_steps is called.
This means step_validate can reference variables created by
preceding step_compute calls.
The validate step does not modify the data in any way. It only inspects the current state of the data.table and raises an error or warning if any check fails.
The survey object with a validate step recorded (no data mutation).
Other steps:
bake_steps(),
get_steps(),
step_collapse(),
step_compute(),
step_filter(),
step_join(),
step_quantile(),
step_recode(),
step_remove(),
step_rename(),
view_graph()
dt <- data.table::data.table( id = 1:5, age = c(25, 30, 45, 50, 60), income = c(1000, 2000, 3000, 4000, 5000), w = 1 ) svy <- Survey$new( data = dt, edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) # Validate that all ages are positive and income is not NA svy <- svy |> step_validate(age > 0, !is.na(income), .min_n = 3) |> bake_steps()dt <- data.table::data.table( id = 1:5, age = c(25, 30, 45, 50, 60), income = c(1000, 2000, 3000, 4000, 5000), w = 1 ) svy <- Survey$new( data = dt, edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) # Validate that all ages are positive and income is not NA svy <- svy |> step_validate(age > 0, !is.na(income), .min_n = 3) |> bake_steps()
Convert a list of steps to a recipe
steps_to_recipe( name, user, svy = survey_empty(type = "eaii", edition = "2019-2021"), description, steps, doi = NULL, topic = NULL )steps_to_recipe( name, user, svy = survey_empty(type = "eaii", edition = "2019-2021"), description, steps, doi = NULL, topic = NULL )
name |
A character string with the name of the recipe |
user |
A character string with the user of the recipe |
svy |
A Survey object |
description |
A character string with the description of the recipe |
steps |
A list with the steps of the recipe |
doi |
A character string with the DOI of the recipe |
topic |
A character string with the topic of the recipe |
A Recipe object
Other recipes:
Recipe-class,
add_recipe(),
bake_recipes(),
get_recipe(),
harmonize(),
print.Recipe(),
publish_recipe(),
read_recipe(),
recipe(),
save_recipe()
dt <- data.table::data.table( id = 1:20, age = sample(18:65, 20, TRUE), w = runif(20, 0.5, 2) ) svy <- Survey$new( data = dt, edition = "2023", type = "demo", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) svy <- step_compute(svy, age2 = age^2) my_recipe <- steps_to_recipe( name = "age_vars", user = "analyst", svy = svy, description = "Age-derived variables", steps = get_steps(svy) ) my_recipedt <- data.table::data.table( id = 1:20, age = sample(18:65, 20, TRUE), w = runif(20, 0.5, 2) ) svy <- Survey$new( data = dt, edition = "2023", type = "demo", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) svy <- step_compute(svy, age2 = age^2) my_recipe <- steps_to_recipe( name = "age_vars", user = "analyst", svy = svy, description = "Age-derived variables", steps = get_steps(svy) ) my_recipe
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.
An R6 class generator (R6ClassGenerator)
R6 class generator for Survey.
Constructor.
Set data.
Set edition.
Set type.
Set weight specification.
Print summarized metadata.
Add a step and invalidate design.
Add a recipe (validates type and dependencies).
Add a workflow.
Apply recipes and return updated Survey.
Lazily initialize the sampling design.
Update design variables with current data.
Efficient copy (shares design, copies data).
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()).
design_activeDeprecated. Use ensure_design() instead.
Survey$new()Create a Survey object
Survey$new( data, edition, type, psu = NULL, strata = NULL, engine, weight, design = NULL, steps = NULL, recipes = list() )
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)
Survey$get_data()Return the underlying data
Survey$get_data()
Survey$get_edition()Return the survey edition/period
Survey$get_edition()
Survey$get_type()Return the survey type identifier
Survey$get_type()
Survey$set_data()Set the underlying data
Survey$set_data(data)
dataNew survey data
Survey$set_edition()Set the survey edition/period
Survey$set_edition(edition)
editionNew edition or period
Survey$set_type()Set the survey type
Survey$set_type(type)
typeNew type identifier
Survey$set_weight()Set weight specification(s) per estimation type
Survey$set_weight(weight)
weightWeight specification list or character
Survey$print()Print summarized metadata to console
Survey$print()
Survey$add_step()Add a step and invalidate design
Survey$add_step(step)
stepStep object
Survey$add_recipe()Add a recipe
Survey$add_recipe(recipe, bake = lazy_default())
recipeRecipe object
bakeWhether to bake lazily (internal flag)
Survey$add_workflow()Add a workflow to the survey
Survey$add_workflow(workflow)
workflowWorkflow object
Survey$bake()Apply recipes and return updated Survey
Survey$bake()
Survey$head()Return the head of the underlying data
Survey$head()
Survey$str()Display the structure of the underlying data
Survey$str()
Survey$set_design()Set the survey design object
Survey$set_design(design)
designSurvey design object or list
Survey$ensure_design()Ensure survey design is initialized (lazy initialization)
Survey$ensure_design()
Invisibly returns self
Survey$update_design()Update design variables using current data and weight
Survey$update_design()
Survey$shallow_clone()Create a shallow copy of the Survey (optimized for performance)
Survey$shallow_clone()
New Survey object with copied data but shared design
Survey$clone()The objects of this class are cloneable with this method.
Survey$clone(deep = FALSE)
deepWhether to make a deep clone.
survey_empty, bake_recipes,
cat_design, cat_recipes
Other survey-objects:
cat_design(),
cat_design_type(),
get_data(),
get_metadata(),
has_design(),
has_recipes(),
has_steps(),
is_baked(),
set_data(),
survey_empty(),
survey_to_data_frame(),
survey_to_datatable(),
survey_to_tibble()
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") ) svydt <- 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
Create an empty survey
survey_empty( edition = NULL, type = NULL, weight = NULL, engine = NULL, psu = NULL, strata = NULL )survey_empty( edition = NULL, type = NULL, weight = NULL, engine = NULL, psu = NULL, strata = NULL )
edition |
Edition of survey |
type |
Type of survey |
weight |
Weight of survey |
engine |
Engine of survey |
psu |
PSU variable or formula (optional) |
strata |
Stratification variable name (optional) |
Survey object
Other survey-objects:
Survey,
cat_design(),
cat_design_type(),
get_data(),
get_metadata(),
has_design(),
has_recipes(),
has_steps(),
is_baked(),
set_data(),
survey_to_data_frame(),
survey_to_datatable(),
survey_to_tibble()
empty <- survey_empty(edition = "2023", type = "test") empty_typed <- survey_empty(edition = "2023", type = "ech")empty <- survey_empty(edition = "2023", type = "test") empty_typed <- survey_empty(edition = "2023", type = "ech")
Convert survey to data.frame
survey_to_data_frame(svy)survey_to_data_frame(svy)
svy |
Survey object |
data.frame
Other survey-objects:
Survey,
cat_design(),
cat_design_type(),
get_data(),
get_metadata(),
has_design(),
has_recipes(),
has_steps(),
is_baked(),
set_data(),
survey_empty(),
survey_to_datatable(),
survey_to_tibble()
dt <- data.table::data.table( id = 1:5, age = c(25, 30, 45, 50, 60), w = rep(1, 5) ) svy <- Survey$new( data = dt, edition = "2023", type = "ech", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) df <- survey_to_data_frame(svy) class(df) # "data.frame"dt <- data.table::data.table( id = 1:5, age = c(25, 30, 45, 50, 60), w = rep(1, 5) ) svy <- Survey$new( data = dt, edition = "2023", type = "ech", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) df <- survey_to_data_frame(svy) class(df) # "data.frame"
Extracts the survey microdata as a data.table.
survey_to_datatable(svy) survey_to_data.table(svy)survey_to_datatable(svy) survey_to_data.table(svy)
svy |
Survey object. |
A data.table.
Other survey-objects:
Survey,
cat_design(),
cat_design_type(),
get_data(),
get_metadata(),
has_design(),
has_recipes(),
has_steps(),
is_baked(),
set_data(),
survey_empty(),
survey_to_data_frame(),
survey_to_tibble()
dt <- data.table::data.table( id = 1:5, age = c(25, 30, 45, 50, 60), w = rep(1, 5) ) svy <- Survey$new( data = dt, edition = "2023", type = "ech", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) result <- survey_to_datatable(svy) data.table::is.data.table(result) # TRUEdt <- data.table::data.table( id = 1:5, age = c(25, 30, 45, 50, 60), w = rep(1, 5) ) svy <- Survey$new( data = dt, edition = "2023", type = "ech", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) result <- survey_to_datatable(svy) data.table::is.data.table(result) # TRUE
Convert survey to tibble
survey_to_tibble(svy)survey_to_tibble(svy)
svy |
Survey object |
A tibble (tbl_df) containing the survey data.
Other survey-objects:
Survey,
cat_design(),
cat_design_type(),
get_data(),
get_metadata(),
has_design(),
has_recipes(),
has_steps(),
is_baked(),
set_data(),
survey_empty(),
survey_to_data_frame(),
survey_to_datatable()
dt <- data.table::data.table( id = 1:5, age = c(25, 30, 45, 50, 60), w = rep(1, 5) ) svy <- Survey$new( data = dt, edition = "2023", type = "ech", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) tbl <- survey_to_tibble(svy) class(tbl)dt <- data.table::data.table( id = 1:5, age = c(25, 30, 45, 50, 60), w = rep(1, 5) ) svy <- Survey$new( data = dt, edition = "2023", type = "ech", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) tbl <- survey_to_tibble(svy) class(tbl)
Retrieves the current setting for the use_copy option, which controls whether survey operations create copies of the data or modify in place.
use_copy_default()use_copy_default()
The use_copy option affects memory usage and performance:
TRUE: Creates copies, safer but uses more memory
FALSE: Modifies in place, more efficient but requires caution
Logical value indicating whether to use data copies (TRUE) or modify data in place (FALSE). Default is TRUE.
set_use_copy to change the setting
Other options:
get_engine(),
lazy_default(),
set_engine(),
set_lazy_processing(),
set_use_copy(),
show_engines()
# Check current setting current_setting <- use_copy_default() print(current_setting)# Check current setting current_setting <- use_copy_default() print(current_setting)
Validate time pattern
validate_time_pattern(svy_type = NULL, svy_edition = NULL)validate_time_pattern(svy_type = NULL, svy_edition = NULL)
svy_type |
Survey type (e.g. "ech"). |
svy_edition |
Survey edition string (e.g. "2023", "2023-06"). |
List with components: svy_type, svy_edition (parsed), svy_periodicity.
Other survey-loading:
extract_time_pattern(),
group_dates(),
load_panel_survey(),
load_survey(),
load_survey_example()
validate_time_pattern(svy_type = "ech", svy_edition = "2023") validate_time_pattern( svy_type = "ech", svy_edition = "2023-06" )validate_time_pattern(svy_type = "ech", svy_edition = "2023") validate_time_pattern( svy_type = "ech", svy_edition = "2023-06" )
View graph
view_graph(svy, init_step = "Load survey")view_graph(svy, init_step = "Load survey")
svy |
Survey object |
init_step |
Initial step label (default: "Load survey") |
A visNetwork interactive graph of the survey processing steps.
Other steps:
bake_steps(),
get_steps(),
step_collapse(),
step_compute(),
step_filter(),
step_join(),
step_quantile(),
step_recode(),
step_remove(),
step_rename(),
step_validate()
dt <- data.table::data.table( id = 1:5, age = c(25, 30, 45, 50, 60), w = rep(1, 5) ) svy <- Survey$new( data = dt, edition = "2023", type = "ech", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) svy <- step_compute(svy, age2 = age * 2) view_graph(svy)dt <- data.table::data.table( id = 1:5, age = c(25, 30, 45, 50, 60), w = rep(1, 5) ) svy <- Survey$new( data = dt, edition = "2023", type = "ech", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) svy <- step_compute(svy, age2 = age * 2) view_graph(svy)
This function executes a sequence of statistical estimations on Survey objects, applying functions from the R survey package with appropriate metadata. Automatically handles different survey types and periodicities.
workflow(svy, ..., estimation_type = "monthly", level = 0.95)workflow(svy, ..., estimation_type = "monthly", level = 0.95)
svy |
A Survey object, a list of Survey objects, a PoolSurvey,
or a RotativePanelSurvey. A single Survey is automatically wrapped
in |
... |
Calls to survey package functions (such as |
estimation_type |
Type of estimation (default |
level |
Confidence level for the interval (default |
The function automatically selects the appropriate sample design according
to the specified estimation_type. For each Survey in the input list,
it executes all functions specified in ... and combines the results.
Supported estimation types:
"monthly": Monthly estimations
"quarterly": Quarterly estimations
"annual": Annual estimations
Each estimation call accepts an optional domain argument to
restrict the estimation to a subpopulation (domain) while respecting
the sampling design. The expression is captured unevaluated and applied
with subset.survey.design on the design — never by
filtering the data — so standard errors and degrees of freedom are the
correct ones for domain estimation:
workflow( list(svy), survey::svymean(~pea, domain = e27 >= 14), estimation_type = "annual" )
domain works with any estimation function, including
svyby (domain + groups). When a domain is used, the stat
column includes the domain expression to disambiguate estimations of
the same variable over different domains.
For PoolSurvey objects, it uses a specialized methodology that handles
pooling of multiple surveys. When a compound estimation_type is used
(e.g. "annual:monthly"), point estimates are averaged across the k
pooled surveys and the standard error is computed as
sqrt(mean(variance) * (1 + rho * (k - 1)) / k), where rho
(default 0, passed as a named argument through ...) is the
correlation between waves of a rotating panel. The former R argument
is deprecated and ignored.
For RotativePanelSurvey objects with monthly follow-up surveys (e.g.
ECH 2021+), estimation_type = "annual:mean_of_months" computes the
annual estimate as the simple average of the monthly estimates: each
follow-up is estimated with its monthly weight (replicate weights are
used when the monthly design has them), the point estimates are
averaged within each year, and the standard errors are combined
assuming independence between months
(se = sqrt(mean(variance) / k) for k months, or with the rho
correction described above when rho is supplied). One row per year
and statistic is returned, with the year in the type column. The
alias "annual:mean_of_months" is also accepted for PoolSurvey
objects, where it is equivalent to "annual:monthly".
data.table with results from all
estimations, including columns:
stat: Estimation call and variable name
variable: Variable name (for filtering)
value: Point estimate
se: Standard error
cv: Coefficient of variation (proportion)
confint_lower: Lower bound of confidence interval
confint_upper: Upper bound of confidence interval
evaluate: CV quality label from
evaluate_cv (e.g. "Excellent", "Good",
"Use with caution")
For svyby estimations, grouping variables (e.g.
region, sexo) appear as additional columns.
svymean for population means
svytotal for population totals
svyratio for ratios
svyby for domain estimations
PoolSurvey for survey pooling
Other workflows:
RecipeWorkflow-class,
evaluate_cv(),
print.RecipeWorkflow(),
publish_workflow(),
read_workflow(),
save_workflow(),
workflow_from_list(),
workflow_table()
# Simple estimation dt <- data.table::data.table( x = rnorm(100), g = sample(c("a", "b"), 100, TRUE), w = rep(1, 100) ) svy <- Survey$new( data = dt, edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) result <- workflow( svy = list(svy), survey::svymean(~x, na.rm = TRUE), estimation_type = "annual" ) # Domain estimation with svyby result_by <- workflow( svy = list(svy), survey::svyby(~x, ~g, survey::svymean, na.rm = TRUE), estimation_type = "annual" ) # Domain (subpopulation) estimation: subset applied on the design result_domain <- workflow( svy = list(svy), survey::svymean(~x, na.rm = TRUE, domain = g == "a"), estimation_type = "annual" ) # Custom confidence level (90%) for all estimations result_90 <- workflow( svy = list(svy), survey::svymean(~x, na.rm = TRUE), estimation_type = "annual", level = 0.90 ) # Per-call confidence level (overrides workflow default) result_mixed <- workflow( svy = list(svy), survey::svymean(~x, na.rm = TRUE, level = 0.80), estimation_type = "annual" )# Simple estimation dt <- data.table::data.table( x = rnorm(100), g = sample(c("a", "b"), 100, TRUE), w = rep(1, 100) ) svy <- Survey$new( data = dt, edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) result <- workflow( svy = list(svy), survey::svymean(~x, na.rm = TRUE), estimation_type = "annual" ) # Domain estimation with svyby result_by <- workflow( svy = list(svy), survey::svyby(~x, ~g, survey::svymean, na.rm = TRUE), estimation_type = "annual" ) # Domain (subpopulation) estimation: subset applied on the design result_domain <- workflow( svy = list(svy), survey::svymean(~x, na.rm = TRUE, domain = g == "a"), estimation_type = "annual" ) # Custom confidence level (90%) for all estimations result_90 <- workflow( svy = list(svy), survey::svymean(~x, na.rm = TRUE), estimation_type = "annual", level = 0.90 ) # Per-call confidence level (overrides workflow default) result_mixed <- workflow( svy = list(svy), survey::svymean(~x, na.rm = TRUE, level = 0.80), estimation_type = "annual" )
Construct a RecipeWorkflow from a plain list
workflow_from_list(lst)workflow_from_list(lst)
lst |
A list (typically from JSON) with workflow fields |
A RecipeWorkflow object
Other workflows:
RecipeWorkflow-class,
evaluate_cv(),
print.RecipeWorkflow(),
publish_workflow(),
read_workflow(),
save_workflow(),
workflow(),
workflow_table()
lst <- list( name = "example", user = "test", survey_type = "ech", edition = "2023", estimation_type = "svymean" ) wf <- workflow_from_list(lst)lst <- list( name = "example", user = "test", survey_type = "ech", edition = "2023", estimation_type = "svymean" ) wf <- workflow_from_list(lst)
Formats a workflow() result as a gt table with confidence intervals,
CV quality classification, and provenance-based source notes.
workflow_table( result, ci = 0.95, digits = 2, compare_by = NULL, show_cv = TRUE, show_se = TRUE, title = NULL, subtitle = NULL, source_note = TRUE, locale = "en", theme = "publication" )workflow_table( result, ci = 0.95, digits = 2, compare_by = NULL, show_cv = TRUE, show_se = TRUE, title = NULL, subtitle = NULL, source_note = TRUE, locale = "en", theme = "publication" )
result |
A |
ci |
Confidence level for intervals (default 0.95).
Set to |
digits |
Number of decimal places (default 2). |
compare_by |
Column name to pivot for side-by-side comparison
(e.g., |
show_cv |
Logical; show CV column with quality classification. |
show_se |
Logical; show SE column. |
title |
Table title. Auto-generated if |
subtitle |
Table subtitle. Auto-generated if |
source_note |
Logical; show provenance footer. |
locale |
Locale for number formatting ( |
theme |
Table theme: |
CV quality classification follows INE/CEPAL standards:
Excellent: CV < 5\
Very good: 5-10\
Good: 10-15\
Acceptable: 15-25\
Use with caution: 25-35\
Do not publish: >= 35\
A gt_tbl object. Export via gt::gtsave() to .html, .docx,
.pdf, .png, or .rtx. Falls back to knitr::kable() if gt is not
installed.
Other workflows:
RecipeWorkflow-class,
evaluate_cv(),
print.RecipeWorkflow(),
publish_workflow(),
read_workflow(),
save_workflow(),
workflow(),
workflow_from_list()
svy <- Survey$new( data = data.table::data.table( x = rnorm(100), g = sample(c("a", "b"), 100, TRUE), w = rep(1, 100) ), edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) result <- workflow( list(svy), survey::svymean(~x, na.rm = TRUE), estimation_type = "annual" ) if (requireNamespace("gt", quietly = TRUE)) { workflow_table(result) }svy <- Survey$new( data = data.table::data.table( x = rnorm(100), g = sample(c("a", "b"), 100, TRUE), w = rep(1, 100) ), edition = "2023", type = "test", psu = NULL, engine = "data.table", weight = add_weight(annual = "w") ) result <- workflow( list(svy), survey::svymean(~x, na.rm = TRUE), estimation_type = "annual" ) if (requireNamespace("gt", quietly = TRUE)) { workflow_table(result) }