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 #34 from nlmixr2/33-reading-dataset-with-rate-=-2
Browse files Browse the repository at this point in the history
33 reading dataset with rate = 2
  • Loading branch information
mattfidler authored Dec 7, 2023
2 parents 62b83ed + 8df469f commit 8e579ec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/et.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1164,13 +1164,13 @@ List etImportEventTable(List inData, bool warnings = true){
show["amt"] = true;
std::vector<int> uIds;
int curevid;
for (int i = 0; i < oldEvid.size(); i++){
for (int i = 0; i < oldEvid.size(); i++) {
curevid = oldEvid[i];
// Handle missing evid
if (evidCol == -1 && methodCol == -1 && amtCol != -1){
if (oldAmt[i] != 0) curevid = 1;
}
if (curevid == 0){
if (curevid == 0) {
id.push_back(oldId[i]);
if (std::find(uIds.begin(), uIds.end(), oldId[i]) == uIds.end()){
uIds.push_back(oldId[i]);
Expand Down Expand Up @@ -1207,7 +1207,7 @@ List etImportEventTable(List inData, bool warnings = true){
ss.push_back(NA_INTEGER);
nobs++;
}
} else if (curevid <= 7){
} else if (curevid <= 7) {
id.push_back(oldId[i]);
if (std::find(uIds.begin(), uIds.end(), oldId[i]) == uIds.end()){
uIds.push_back(oldId[i]);
Expand All @@ -1221,10 +1221,11 @@ List etImportEventTable(List inData, bool warnings = true){
}
amt.push_back(oldAmt[i]);
if (curevid >= 5 && oldRate[i] != 0) stop(_("replacement/multiplication events cannot be combined with infusions"));
rate.push_back(oldRate[i]);
if (curevid >= 5 && oldDur[i] != 0) stop(_("replacement/multiplication events cannot be combined with infusions"));
dur.push_back(oldDur[i]);
if (oldRate[i] > 0) show["rate"] = true;
if (oldRate[i] < 0) show["rate"] = true;
rate.push_back(oldRate[i]);
if (oldDur[i] > 0) show["dur"] = true;
ii.push_back(oldIi[i]);
if (oldIi[i] > 0) show["ii"] = true;
Expand Down Expand Up @@ -1381,7 +1382,6 @@ List etImportEventTable(List inData, bool warnings = true){
if (uIds.size() > 1){
show["id"] = true;
}

//
RObject timeUnitInfo;
bool doTime = false;
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-et.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
test_that("et import rate=-2", {

d <- data.frame(id = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
time = c(0, 2, 12.5, 24.5, 37, 48, 60.5, 72.5, 85.3, 96.5, 108.5, 112.5),
amt = c(25, 0, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 0),
rate = c(-2, 0, -2, -2, -2, -2, -2, -2, -2, -2, -2, 0))
d2 <- as.data.frame(et(d))
expect_equal(d2$rate, c(-2, NA_real_, -2, -2, -2, -2, -2, -2, -2, -2, -2, NA_real_))


})


for (radi in c(1, 2)) {
forderForceBase(switch(radi,
TRUE,
Expand Down

0 comments on commit 8e579ec

Please sign in to comment.