Skip to contents

Package developers register a function called with the ui at the start of a ui solve, before parameter loaders run. Use it to rehydrate transient C-side state from serializable ui slots (so a ui saved to disk and reloaded in a fresh session solves correctly). The hook must be cheap and a no-op for models it does not own.

Usage

rxRegisterUiPrep(name, fn)

rxRemoveUiPrep(name)

Arguments

name

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

fn

Function of one argument (the rxUi being solved). Return value is ignored; errors are downgraded to a warning so a buggy hook cannot break unrelated solves.

Value

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

Examples

# \donttest{
mod <- function() {
  ini({
    k <- 0.1
  })
  model({
    d/dt(A) <- -k * A
  })
}
seen <- new.env()
seen$n <- 0L
rxRegisterUiPrep("myPkg:count", function(ui) seen$n <- seen$n + 1L)
s <- rxSolve(mod, et(amt = 100) |> et(0:4))
#>  
#>  
#> ℹ parameter labels from comments are typically ignored in non-interactive mode
#> ℹ Need to run with the source intact to parse comments
#>  
#>  
seen$n
#> [1] 1
rxRemoveUiPrep("myPkg:count")
# }