Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #88 from nlmixr2/87-tad-calculation-inconsistent
Browse files Browse the repository at this point in the history
Fix zero dose + evid=2 to not be counted as dose
  • Loading branch information
mattfidler authored Feb 7, 2024
2 parents 8249e25 + c3d8fcf commit cfeb768
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: rxode2parse
Title: Parsing and Code Generation Functions for 'rxode2'
Version: 2.0.18
Version: 2.0.18.9000
Authors@R: c(
person("Matthew L.", "Fidler", , "matthew.fidler@gmail.com", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-8538-6691")),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# rxode2parse (development version)

* Added a evid suffix of 60 for cases where evid=2 adds an on event

# rxode2parse 2.0.18

* Removed linear compartment solutions with gradients from rxode2parse
Expand Down
9 changes: 8 additions & 1 deletion inst/include/rxode2parseHandleEvid.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ extern "C" {
// xx = 30, Turn off compartment
// xx = 40, Steady state constant infusion
// xx = 50, Phantom event, used for transit compartments
// xx = 60, Dose that does not track as a dose turn on system
// Steady state events need a II data item > 0
#define EVID0_REGULAR 1
#define EVID0_RATEADJ 2
Expand All @@ -110,7 +111,7 @@ extern "C" {
#define EVID0_OFF 30
#define EVID0_SSINF 40
#define EVID0_PHANTOM 50

#define EVID0_ONDOSE 60

static inline void getWh(int evid, int *wh, int *cmt, int *wh100, int *whI, int *wh0){
*wh = evid;
Expand Down Expand Up @@ -229,6 +230,12 @@ static inline int handleTlastInlineUpateDosingInformation(rx_solving_options_ind
}
break;
}
if (ind->wh0 == EVID0_ONDOSE) {
// evid=2 can add zero dose to turn on a compartment;
// therefore if the current dose is zero and the next evid = 2
// don't treat it as a new dose.
return 0;
}
return 1;
}

Expand Down
8 changes: 4 additions & 4 deletions src/etTran.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ List etTransParse(List inData, List mv, bool addCmt=false,
else caddl = inAddl[i];
if (IntegerVector::is_na(caddl)) caddl = 0;
// EVID flag
if (evidCol == -1){
if (evidCol == -1) {
// Missing EVID
if (rateI == 0 && (ISNA(camt) || camt == 0.0)){
cevid = 0;
Expand Down Expand Up @@ -1252,7 +1252,7 @@ List etTransParse(List inData, List mv, bool addCmt=false,
cevid=0;
}
}
switch(cevid){
switch(cevid) {
case 0:
// Observation
nobs++;
Expand Down Expand Up @@ -1417,10 +1417,10 @@ List etTransParse(List inData, List mv, bool addCmt=false,
ndose++;
// + cmt needs to turn on cmts.
// This gives a zero dose to cmt
if (cmtCol != -1 && cmt > 0 && cmt <= baseSize){
if (cmtCol != -1 && cmt > 0 && cmt <= baseSize) {
// Turn on state with dose
id.push_back(cid);
evid.push_back(cevid);
evid.push_back(cevid-flg+60);
cmtF.push_back(cmt);
time.push_back(ctime);
amt.push_back(0.0);
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-etTrans.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ d/dt(blood) = a*intestine - b*blood
class = "data.frame",
row.names = c(NA,-6L))
skip_on_cran()

expect_warning(expect_false(any(is.na(etTransParse(et, mod)$TIME))))
})

Expand Down Expand Up @@ -139,7 +139,7 @@ d/dt(blood) = a*intestine - b*blood
evid = c(1L, 2L, 2L)),
class = "data.frame",
row.names = c(NA, -3L))

test_that("error for negative non ODE compartments", {
expect_error(etTransParse(et, mod, keepDosingOnly = TRUE))
et$cmt <- factor(et$cmt)
Expand Down Expand Up @@ -534,7 +534,7 @@ d/dt(blood) = a*intestine - b*blood
})

test_that("dat3 has evid w/amt 0", {
expect_equal(dat3$EVID, c(101L, 2L, 0L, 0L, 0L, 101L, 2L, 0L, 0L, 0L))
expect_equal(dat3$EVID, c(160L, 2L, 0L, 0L, 0L, 160L, 2L, 0L, 0L, 0L))
expect_equal(dat3$AMT, c(0, NA, NA, NA, NA, 0, NA, NA, NA, NA))
})

Expand Down

0 comments on commit cfeb768

Please sign in to comment.