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.
Arguments
- ...
Required metadata and optional steps. Required parameters:
name: Descriptive name for the recipeuser: User/author creating the recipesvy: Base Survey object (usesurvey_empty()for generic recipes)description: Detailed description of the recipe's purpose
Optional parameters include data transformation steps.
Value
A Recipe object containing metadata, transformation steps,
dependency information, and default engine configuration.
Details
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().
See also
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(),
explore_recipes(),
get_recipe(),
print.Recipe(),
publish_recipe(),
read_recipe(),
save_recipe(),
steps_to_recipe()
Examples
# 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: Basic ECH Indicators ──
#> Author: Analyst
#> Survey: ech / 2023
#> Version: 1.0.0
#> Description: Basic labor indicators for ECH 2023
#> Certification: community
#>
# \donttest{
# 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
#>
#> ── Recipe: Demo ──
#> Author: test
#> Survey: demo / 2023
#> Version: 1.0.0
#> Description: Demo recipe
#> Certification: community
#>
#> ── Requires (2 variables) ──
#> income, age
#>
#> ── Pipeline (2 steps) ──
#> 1. [compute] -> income_cat "Compute step"
#> 2. [recode] -> age_group "Recode step"
#>
#> ── Produces (2 variables) ──
#> age_group [categorical], income_cat [numeric]
#>
# }