When a model comes from a call, like
rxode2(nlmixr2lib::readModelDb("PK_1cmt")), the text of the call is a poor
model name; the function that produced the model knows a better one. This
is dispatched on the name of the called function, so a
rxModelName.readModelDb() method names every model readModelDb()
produces. Without a method the call is named by its own (deparsed) text.
Details
A method is given the call as x and the call's arguments in ..., matched
to the argument names of the function being called whenever that function
can be found. The arguments are unevaluated: one a method does not look at
is never evaluated, and one it does look at is evaluated again, in the frame
the call came from, so a method should only read arguments that are cheap to
evaluate. A method that cannot name the model should return NULL;
anything that is not a single non-empty string is ignored the same way.
See also
Other Model names:
rxModelNameFromExpr(),
rxModelNameLhs()
Examples
# a function that creates models from a database of them:
readMyModelDb <- function(name) {
# ...look `name` up and return the model function...
function() {
ini({a <- 1})
model({b <- a})
}
}
# names the model for the database entry it came from
rxModelName.readMyModelDb <- function(x, ...) {
list(...)$name
}
registerS3method("rxModelName", "readMyModelDb", rxModelName.readMyModelDb)
rxode2(readMyModelDb("one.cmt"))$modelName
#>
#>
#> ℹ parameter labels from comments are typically ignored in non-interactive mode
#> ℹ Need to run with the source intact to parse comments
#> [1] "one.cmt"
