This function is typically not needed by end users.
Usage
nlmixr_object_simplify(object, error = c("stop", "continue"))Arguments
- object
Fitted object or function specifying the model.
- error
What should happen if any step of a model's chain throws an error?
"stop"(the default) lets the error propagate, haltingtargets::tar_make()as usual."continue"catches an error from any of the model's steps – simplifying the object, reading its covariates, simplifying the data, or the estimation itself – and stores a failure sentinel (an object of classnlmixr2targetsError, which also inherits from"try-error") carrying the error message. The sentinel is passed down the model's remaining steps to its final target, so a single failed model does not stop the rest of the pipeline. Detect a failed model withinherits(fit, "nlmixr2targetsError")or the broaderinherits(fit, "try-error").
Details
The object simplification removes comments (so please use label()
instead of comments to label parameters) and then converts the object
to a "nlmixrui" object.
Object metadata (ui$meta) and parameter labels (ui$iniDf$label) are
also stripped from the simplified object. They do not affect estimation,
and stripping them keeps the simplified object unchanged across edits to
either, so editing only labels or metadata will not invalidate a fit. The
stripped values are restored on the final fit by
nlmixr_object_complicate(), which reads them straight back off the
original model.
The natural nlmixr2 DSL form for compartment initial conditions
(cmt(0) <- value inside a model({...}) block) trips targets'
static analysis because codetools::findGlobals() interprets it as
a replacement-function assignment with a non-symbol target.
tar_nlmixr() auto-rewrites cmt(0) <- value to cmt(initial) <- value
inside model({...}) blocks at construction time (mutating the
user's model function in env), and converts back to cmt(0) <- value
before nlmixr2 sees the model. The user can therefore write
cmt(0) <- value directly.
Manual cmt(initial) <- value is also accepted, but it is a
nlmixr2targets-only workaround: bare nlmixr2 does not understand
the cmt(initial) form, so a model function written this way only
fits when routed through tar_nlmixr() /
tar_nlmixr_multimodel(). Note: because the rewrite mutates the
function in env, calling the model function directly (outside
tar_make()) after tar_nlmixr() will see cmt(initial) in its
body.
The simplified model's model.name is always set to "object", so the
simplified output does not depend on the symbol the caller bound the model
function to.
See also
nlmixr_object_complicate() for the inverse operation that
re-attaches labels, metadata, and the original data on the final fit.
Other Simplifiers:
nlmixr_data_simplify(),
nlmixr_object_complicate(),
nlmixr_object_covariates()