diff --git a/src/genModelVars.h b/src/genModelVars.h index 3f7d29821..df76543fe 100644 --- a/src/genModelVars.h +++ b/src/genModelVars.h @@ -268,7 +268,7 @@ static inline SEXP sortStateVectors(SEXP ordS) { int cur = tb.didx[i]; int prop = tb.dprop[i]; int pass = 0; - if (tb.linCmt){ + if (tb.linCmt) { if (tb.hasDepotCmt == 1 && !strcmp("depot", tb.ss.line[tb.di[i]])){ pass = 1; } else if ((tb.hasCentralCmt == 1 || tb.hasDepotCmt == 1) && diff --git a/src/parseFunsDosing.h b/src/parseFunsDosing.h index d33fc66d6..01b9700aa 100644 --- a/src/parseFunsDosing.h +++ b/src/parseFunsDosing.h @@ -57,21 +57,25 @@ static inline int handleFunctionTadSingleStateCcode(transFunctions *tf,char *v2) sAppend(&sb, "_%s1(", tf->v); sAppend(&sbDt, "_%s1(", tf->v); if (new_de(v2, 0)){ - // cannot be lhs statements in tad style assignments - // also cannot be from anywhere - // temporarily turn off that this is a function - // This is not a function - int fn = tb.fn; - tb.fn = 0; - // this is NOT an assignment - nodeInfo ni2; - niReset(&ni2); - char *name = tf->v; - ni2.assignment = 0; - ni2.ini = 0; - add_de(ni2, name, v2, 0, 0); - // turn back on that this is a function - tb.fn = fn; + if (!strcmp("depot", v2)) { + tb.hasDepot = 1; + aAppendN("_DEPOT_)", 8); + return 1; + } else if (!strcmp("central", v2)) { + tb.hasCentral = 1; + aAppendN("_CENTRAL_)", 10); + return 1; + } else { + // cannot be lhs statements in tad style assignments + // also cannot be from anywhere + // temporarily turn off that this is a function + // This is not a function + int fn = tb.fn; + tb.fn = 0; + add_de(tf->ni, tf->name, v2, 0, 0); + // turn back on that this is a function + tb.fn = fn; + } } else { new_or_ith(v2); } diff --git a/tests/testthat/test-tad.R b/tests/testthat/test-tad.R index 36352568f..be8ccd3e0 100644 --- a/tests/testthat/test-tad.R +++ b/tests/testthat/test-tad.R @@ -546,9 +546,33 @@ rxTest({ }) } - mod2 <- mod2() + expect_error(mod2()) - mod2$simulationModel + mod2 <- function() { + ini({ + ## Table 3 from Savic 2007 + cl <- 17.2 # (L/hr) + vc <- 45.1 # L + ka <- 0.38 # 1/hr + mtt <- 1.37 # hr + f2 <-0.5 # Fraction of 1st Order portion + n <- 20.1 + }) + model({ + k <- cl/vc + bio <- 1-f2 + ktr = (n+1)/mtt + ## note that lgammafn is the same as lgamma in R. + d/dt(depot1) = exp(log(bio*podo(depot1))+ + log(ktr)+n*log(ktr*tad(depot1))- + ktr*tad(depot1)-lgammafn(n+1))-ka*depot1 + d/dt(depot2) <- -ka*depot2 + f(depot2) <-f2 + d/dt(cen) <- ka*depot1 + ka*depot2-k*cen + }) + } + + mod2 <- mod2() }) })