Skip to contents

Replace dose the rxode2 system in the model

Usage

replace(amt, cmt = 1)

Arguments

amt

Numeric dose amount (for dose events) or 0 for observations. When rate > 0 this is interpreted as the total infusion amount and the infusion duration is amt / rate.

cmt

Integer compartment number (1-based) to which the dose is applied. Default is 1

Value

This function is only meaningful inside an rxode2 model; it returns NULL invisibly if called from R directly (after signaling an error).

Details

Behavior inside a model

replace() is evaluated at every output time point (when the solver is exactly at a scheduled event time). The pushed event is inserted into the individual's event timeline and the solver visits it now or at the specified future time.

The number of events that may be pushed per individual is limited by the maxExtra argument of rxSolve(). When maxExtra = 0 (the default) there is no limit. Exceeding the limit causes an error.

Past-time pushes (where time < t) are silently ignored and counted; a warning is issued after solving.

See also

Examples

# \donttest{
# set the central amount to 25 at t = 12
f <- function() {
  ini({
    ka <- 0.5; cl <- 1; v <- 10
  })
  model({
    mtime(at) <- 12
    d/dt(depot) <- -ka * depot
    d/dt(central) <- ka * depot - cl / v * central
    cp <- central / v
    if (t >= at && t < at + 0.5) replace(25, central)
  })
}
s <- rxSolve(f, et(amt = 100) |> et(0:24))
#>  
#>  
#> ℹ parameter labels from comments are typically ignored in non-interactive mode
#> ℹ Need to run with the source intact to parse comments
#>  
#>  
s[s$time >= 11 & s$time <= 14, ]
#>    time at       cp      depot  central
#> 12   11 12 4.109804 0.40867653 41.09804
#> 13   12 12 3.733943 0.24787470 37.33943
#> 14   12 12 2.500000 0.24787470 25.00000
#> 15   13 12 2.271336 0.15034386 22.71336
#> 16   14 12 2.060796 0.09118831 20.60796
# }