Reads a recipe written by write_recipe(). With data = NULL (the default) it
returns an inspectable recipe manifest (for review or archival); pass data to
reconstruct an executable weighting_spec bound to that data, ready for prep().
Arguments
- file
path to the recipe
.yml/.yamlfile.- data
optional data frame. When supplied, the recipe is rebuilt into a
weighting_specon this data. The columns the steps reference (weights, auxiliaries, disposition flags) must exist indata.- references
optional named list, named by the id of the step that needs each object, restoring what the recipe stores only as a descriptor because it is microdata rather than metadata: a
reference_sample()for a step that calibrates or pseudo-weights against a reference, and thepopulationdata frame ofstep_calibrate()/step_model_calibration().- allow_code
single logical, the gate on every executable thing a recipe file can carry: the conditions and formulas it stores as text, and a step that stores an R function as source. With
FALSE(the default) a stored expression is accepted only if every call in it is on a fixed whitelist of data-manipulation functions (comparisons, arithmetic,is.na(),factor(),cut(), string andapply-free helpers), and a function node is refused outright. That matters because a recipe is meant to be exchanged between organizations: an expression like{ system("...") ; responded }runs at the firstprep(), not at read time. SetTRUEonly for a file you trust, exactly as you wouldsource()it.
Value
With data = NULL, a weightflow_recipe manifest (a list with a print
method). With data, a weighting_spec.
Details
A reconstructed recipe is validated only when you call prep(): a hand-edited
recipe with an out-of-range or mistyped value surfaces its error there, not at
read_recipe() time. And because reading a recipe evaluates the stored
expressions, only read recipes you trust, as you would source() an R script.
See also
Other recipe serialization:
write_recipe()
Examples
spec <- weighting_spec(sample_survey, base_weights = pw) |>
step_nonresponse(respondent = responded, method = "weighting_class", by = "region")
f <- tempfile(fileext = ".yml"); write_recipe(spec, f)
read_recipe(f) # inspect the manifest
#> weightflow recipe (written by version 1.3.1, 2026-09-28T18:37:27Z)
#> base weights: pw
#> 1 step(s):
#> - nonresponse nonresponse_1
#> Pass `data =` to read_recipe() to rebuild an executable recipe.
spec2 <- read_recipe(f, data = sample_survey) # rebuild an executable recipe
