11  mrg::report()

When debugging model code, it is sometimes helpful to write print statements at strategic locations to see what is happening during the model run.

In this example, we are infusing a dose over 2 hours and want to check the concentration at the end of the infusion. For simplicity, we’ll just print that value to the console.

model/mrg-report-1.solv
[ pkmodel ] advan = 1

[ param ] CL = 1, V = 70

[ table ] 

if(END_OF_INFUSION) mrg::report(A1/V);
mod <- mread("model/mrg-report-1.solv")
. Building mrg-report-1_solv ... done.
dose <- ev(amt = 100, tinf = 4)

out <- mrgsim(mod, dose)
. from report 1.38852

The obvious downside to this approach is you can easily flood the console with outputs that are hard to make sense of. In that case, you can use a more controlled approach, saving each value you eventually want reported and then assigning those objects into the model environment. An example is shown here.

model/mrg-report-2.solv
[ plugin ] mrgx

[ global ] 
std::deque<double> eof;

[ pkmodel ] advan = 1

[ param ] CL = 1, V = 70

[ table ] 
if(NEWIND <= 1) eof.clear();

if(END_OF_INFUSION) eof.push_back(A1/V);

if(FINAL_ROW) {
  mrgx::assign("eof", eof, self);
}
mod <- mread("model/mrg-report-2.solv")
. Building mrg-report-2_solv ... done.
dose <- mutate(dose, ii = 24, addl = 3)

out <- mrgsim(mod, dose, end = 240, delta = 0.1)

out <- mutate_sims(out, CP = A1/mod$V)

plot(out, CP ~ time)

To pull the data from the model environment, you run:

env_get(mod, "eof")
. [1] 1.388522 2.374010 3.073451 3.569871