Skip to contents

Package developers register a function called with a freshly assembled rxUi before it is compressed. Use it to attach parse-time state to the model – for example values that a user-defined function (see rxUdfUi()) generated while the model was being parsed, which the rxUdfUi() return list has no field to carry.

Usage

rxRegisterUiAssembled(name, fn)

rxRemoveUiAssembled(name)

Arguments

name

Unique hook name; re-registering the same name replaces it.

fn

Function of one argument (the freshly assembled ui environment). The return value is ignored; errors are downgraded to a warning so a buggy hook cannot break unrelated model builds.

Value

Invisibly, the hook name (register) or NULL (remove).

Details

The hook receives the ui environment and may assign into it in place; pair that with the sticky mechanism (see rxForcedPars()) so the slot survives model piping and saveRDS(). A hook must not reorder rxModelVars(ui)$params, must be cheap, and must be a no-op for models it does not own.

Author

Matthew L. Fidler

Examples

# \donttest{
rxRegisterUiAssembled("myPkg:tag", function(ui) {
  assign("myTag", "built", envir = ui)
  assign("sticky", unique(c(ui$sticky, "myTag")), envir = ui)
})
mod <- function() {
  ini({
    k <- 0.1
  })
  model({
    d/dt(A) <- -k * A
  })
}
u <- rxode2(mod)
#>  
#>  
#> ℹ parameter labels from comments are typically ignored in non-interactive mode
#> ℹ Need to run with the source intact to parse comments
rxUiDecompress(u)$myTag
#> [1] "built"
rxRemoveUiAssembled("myPkg:tag")
# }