diff --git a/src/et.cpp b/src/et.cpp index a0316c4..849d329 100644 --- a/src/et.cpp +++ b/src/et.cpp @@ -1164,13 +1164,13 @@ List etImportEventTable(List inData, bool warnings = true){ show["amt"] = true; std::vector 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]); @@ -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]); @@ -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; @@ -1381,7 +1382,6 @@ List etImportEventTable(List inData, bool warnings = true){ if (uIds.size() > 1){ show["id"] = true; } - // RObject timeUnitInfo; bool doTime = false; diff --git a/tests/testthat/test-et.R b/tests/testthat/test-et.R index 823dc0a..c87fe72 100644 --- a/tests/testthat/test-et.R +++ b/tests/testthat/test-et.R @@ -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,