
Iteratively refine an existing spec_ir via natural language
Source: R/translator-nl.R
refine_spec.RdApplies a conversational modification instruction to an existing spec_ir
(or spec_translation), validates the updated specification, and computes a
semantic diff_spec_ir() highlighting exactly what changed.
Usage
refine_spec(spec, instruction, translator = translator_rule(), validate = TRUE)Arguments
- spec
A
spec_irorspec_translationobject.- instruction
Character scalar specifying the desired edit (e.g.,
"increase clusters to 80","add random slope for x1 with sd 0.25","set 20% MAR missingness","sweep ICC across 0.1, 0.2, 0.3").- translator
A
spec_translatorbackend (defaults totranslator_rule()).- validate
Logical; if
TRUE(default), enforcesassert_valid_spec_ir().
Value
An S3 object of class c("spec_refinement", "spec_translation") with
elements spec, previous_spec, diff, clarifications, validation,
instruction, backend, prompt, and parsed_fields.
Examples
base <- nl_to_spec("2-level study with 40 schools, 20 students per school, ICC 0.15")
ref <- refine_spec(base, "increase clusters to 80 and add 15% MAR missingness")
ref$diff
#>
#> ── spec_diff (5 changes across 2 sections)
#> • hierarchy.n_clusters: 40 -> 80
#> • missingness.mechanism: none -> MAR
#> • missingness.rate: 0 -> 0.15
#> ✔ missingness.auxiliary: added (x1)
#> ✔ missingness.strength: added (1)