V05 Replace and remove a recipe
Use your current course session. Preparation and course runner · R script ↓
Optional deep dive. Enable only the options named in each block, after preparing its packages or services.
V05a Extract a recipe
Goal: Reuse preparation on another product.
Prerequisites: H09; extras.
Extracting a recipe does not execute it.
training_step(
"V05a",
{
reused_recipe <- dr_extract_recipe(prepared_product)
reused_product <- dr_product(
"policies.reused",
precise_policies,
contract = policy_contract
) |>
dr_add_recipe(reused_recipe)
print(dr_collect(dr_run(reused_product, write = FALSE)))
},
needs = c("H09"),
enabled = training_options$extras,
optional = TRUE
)Expected result: The first policy has premium 100.13.
Task: Is the recipe tied to the old product ID?
Show solution
No. Preparation is a reusable object of its own.
V05 Replace and remove a recipe
Goal: Change definitions deliberately.
Prerequisites: V05a.
update replaces existing steps. remove removes preparation entirely.
training_step(
"V05",
{
replaced_product <- dr_update_recipe(
reused_product,
dr_recipe() |> dr_step_mutate(premium = round(premium, 0))
)
plain_product <- dr_remove_recipe(reused_product)
print(dr_collect(dr_run(replaced_product, write = FALSE)))
print(dr_collect(dr_run(plain_product, write = FALSE)))
},
needs = c("V05a"),
enabled = training_options$extras,
optional = TRUE
)Expected result: 100 after replacement; 100.126 without a recipe.
Task: Was reused_product itself modified?
Show solution
No. Both calls produce new definition objects.