Runtime helper: undo the cmt(0) -> cmt(initial) rewrite before evaluating the captured object expression.
Source: R/simplify.R
nlmixr_object_zero_initial_eval.RdWrapped around the captured expression at construction time when
tar_nlmixr_protect_zero_initial() performed any rewrites. Needed
for pipe forms like pheno |> model({...}) and pheno |> ini(...),
because nlmixr2's pipe handlers parse pheno's body before the
existing nlmixr_object_simplify_zero_initial_helper() could
intervene. Harmless for symbol-only forms (the existing helper
reaches them at simplify time anyway).
Usage
nlmixr_object_zero_initial_eval(expr, envir = parent.frame())Details
Mechanism:
Walk the quoted expression, rewriting
name(initial) <- valback toname(0) <- valvia the existing inverse helper.Walk the (rewritten) expression for symbols. For each that resolves to a function whose body still contains
name(initial) <- valinsidemodel({...}), build a corrected closure withname(0) <- valand bind it in an override frame.Evaluate the rewritten expression in the override frame (whose parent is
envir), so any lookup of a rewritten symbol hits the corrected closure first.
The corrected copies retain the original closure environment of the user's function; only the body is swapped.