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 #42 from nlmixr2/41-importing-dataset-crashes-r
Browse files Browse the repository at this point in the history
Add crashing import
  • Loading branch information
mattfidler authored Apr 7, 2024
2 parents 9d90d77 + b1c5f2c commit a5a1c1c
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/et.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,25 +494,28 @@ List etSort(List& curEt){
IntegerVector tmpI, tmpI2;
CharacterVector tmpC, tmpC2;
NumericVector tmpN, tmpN2;
int ii = 0;
for (j = newEt.size(); j--;){
ii = 0;
for (i = 0; i < (int)time.size(); i++){
if (ISNA(time[i])) continue;
if (rxIsNum(curEt[j])) {
if (i == 0) newEt[j] = NumericVector(newSize);
tmpN=newEt[j];
tmpN2 = curEt[j];
tmpN[i] = tmpN2[idx[i]];
tmpN[ii] = tmpN2[idx[i]];
} else if (rxIsInt(curEt[j])) {
if (i == 0) newEt[j] = IntegerVector(newSize);
tmpI=newEt[j];
tmpI2 = curEt[j];
tmpI[i] = tmpI2[idx[i]];
tmpI[ii] = tmpI2[idx[i]];
} else if (rxIsChar(curEt[j])){
if (i == 0) newEt[j] = CharacterVector(newSize);
tmpC=newEt[j];
tmpC2 = curEt[j];
tmpC[i] = tmpC2[idx[i]];
tmpC[ii] = tmpC2[idx[i]];
}
ii++;
}
}
newEt.attr("class") = clone(asCv(curEt.attr("class"), "class"));
Expand Down
165 changes: 165 additions & 0 deletions tests/testthat/test-et.R
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ test_that("Ad issue #23", {
})

test_that("test import with NA time", {

e <- et()

expect_warning(e$importEventTable(data.frame(
Expand All @@ -661,4 +662,168 @@ test_that("test import with NA time", {
DOSE = 300,
COVAR = 1
)))

})


test_that("another import", {

e <- et()

expect_warning(e$importEventTable(data.frame(ID = c("A131", "A131", "A131", "A131", "A131",
"A131", "A131", "A131", "A131", "A131", "A131", "A131", "A131",
"A131", "A131", "A131", "A131", "A131", "A131", "A131", "A131",
"A131", "A131", "A131", "A131", "A131", "A131", "A131", "A131",
"A131", "A131", "A131", "A131", "A131", "A131", "A131", "A131",
"A131", "A131", "A131", "A131", "A131", "A131", "A131", "A131",
"A131", "A131", "A131", "A131", "A131", "A131", "A131", "A131",
"A131", "A131", "A131", "A131", "A131", "A131", "A131", "A131",
"A131", "A131", "A131", "A131", "A131", "A131", "A131", "A131",
"A131", "A131", "A131", "A131", "A131", "A131", "A131", "A131",
"A131", "A131", "A131", "A131", "A131", "A131", "A131", "A131",
"A131", "A131", "A131", "A131", "A131", "A131", "A131", "A131",
"A131", "A131", "A131", "A131", "A132", "A132", "A132", "A132",
"A132", "A132", "A132", "A132", "A132", "A132", "A132", "A132",
"A132", "A132", "A132", "A132", "A132", "A132", "A132", "A132",
"A132", "A132", "A132", "A132", "A132", "A132", "A132", "A132",
"A132", "A132", "A132", "A132", "A132", "A132", "A132", "A132",
"A132", "A132", "A132", "A132", "A133", "A133", "A133", "A133",
"A133", "A133", "A133", "A133", "A133", "A133", "A133", "A133",
"A133", "A133", "A133", "A133", "A133", "A133", "A133", "A133",
"A133", "A133", "A133", "A133", "A133", "A133", "A133", "A133",
"A133", "A133", "A133", "A133", "A133", "A133", "A133", "A133",
"A133", "A133", "A133", "A134", "A134", "A134", "A134", "A134",
"A134", "A134", "A134", "A134", "A134", "A134", "A135", "A135",
"A135", "A135", "A135", "A135", "A135", "A135", "A135", "A135",
"A135", "A135", "A135", "A135", "A135", "A135", "A135", "A135",
"A135", "A135", "A135", "A135", "A135", "A135", "A135", "A135",
"A135", "A135", "A135", "A135", "A135"),
TIME = c(0, 0, 1.3,
1.883333333, 2.766666667, 4.85, 6.883333333, 7.816666667, 23.81666667,
47.81666667, 71.81666667, 95.81666667, 166.2, 166.2, 190.2, 214.2,
238.2, 262.2, 332.3333333, 332.3333333, 332.95, 333.5333333,
334.5333333, 336.5333333, 338.5333333, 339.45, 355.45, 379.45,
403.45, 427.45, 504.3166667, 504.3166667, 528.3166667, 552.3166667,
576.3166667, 672.3166667, 696.3166667, 720.3166667, 744.3166667,
840.3166667, 864.3166667, 888.3166667, 909.5333333, 909.5333333,
910.3666667, 910.8166667, 911.7, 913.45, 915.4, 917, 1009.783333,
1009.783333, 1012.3, 1034.3, 1058.3, 1082.3, 1178.3, 1202.3,
1226.3, 1250.3, 2016.1, 2016.1, 2040.1, 2064.1, 2088.1, 2184.1,
2208.1, 2232.1, 2256.1, 2352.1, 2376.1, 2400.1, 2424.1, 2522.1,
2522.1, 2522.45, 2544.45, 2568.45, 2592.45, 2688.45, 2712.45,
2736.45, 2760.45, 2856.45, 2880.45, 2904.45, 2928.45, 3025.8,
3025.8, 3028.266667, 3050.266667, 3074.266667, 3098.266667, 3194.266667,
3218.266667, 3242.266667, 3266.266667, 0, 0, 0.85, 24.35, 48.35,
72.35, 96.35, 336.35, 360.35, 384.35, 408.35, 432.35, 500.7,
500.7, 503.0166667, 525.0166667, 549.0166667, 573.0166667, 597.0166667,
666.1333333, 666.1333333, 666.9833333, 667.4833333, 668.4833333,
669.9833333, 672.0333333, 673.7, 689.7, 713.7, 737.7, 761.7,
833.7, 881.7, 905.7, 1001.7, 1025.7, 1049.7, 1082.816667, 1082.816667,
1085.7, 0, 0, 1.616666667, 2.033333333, 2.866666667, 4.866666667,
6.283333333, 24.28333333, 170.2833333, 170.2833333, 194.2833333,
218.2833333, 242.2833333, 261.6833333, 333.1666667, 357.1666667,
381.1666667, 405.1666667, 429.1666667, 505.35, 505.35, 508.3333333,
530.3333333, 554.3333333, 578.3333333, 595.4, 595.4, 596.9333333,
666.9333333, 690.9333333, 714.9333333, 738.9333333, NA, NA, NA,
NA, NA, NA, NA, 0, 0, 1.133333333, 1.716666667, 2.633333333,
4.416666667, 6.216666667, 24.21666667, 48.21666667, 72.21666667,
96.21666667, 0, 0, 0.9666666667, 1.466666667, 2.266666667, 4.35,
6.016666667, 24.01666667, 48.01666667, 168.0166667, 192.0166667,
216.0166667, 240.0166667, 264.0166667, 336.0166667, 360.0166667,
384.0166667, 408.0166667, 432.0166667, 503.3, 503.3, 505.9, 527.9,
551.9, 575.9, 599.9, 1175.566667, 1175.566667, 1178, 1200, 1224
),
CMT = c("central", "depot", "central", "central", "central",
"central", "central", "central", "depot", "depot", "depot", "depot",
"central", "depot", "depot", "depot", "depot", "depot", "central",
"depot", "central", "central", "central", "central", "central",
"central", "depot", "depot", "depot", "depot", "central", "depot",
"depot", "depot", "depot", "depot", "depot", "depot", "depot",
"depot", "depot", "depot", "central", "depot", "central", "central",
"central", "central", "central", "central", "central", "depot",
"central", "depot", "depot", "depot", "depot", "depot", "depot",
"depot", "central", "depot", "depot", "depot", "depot", "depot",
"depot", "depot", "depot", "depot", "depot", "depot", "depot",
"central", "depot", "central", "depot", "depot", "depot", "depot",
"depot", "depot", "depot", "depot", "depot", "depot", "depot",
"central", "depot", "central", "depot", "depot", "depot", "depot",
"depot", "depot", "depot", "central", "depot", "central", "depot",
"depot", "depot", "depot", "depot", "depot", "depot", "depot",
"depot", "central", "depot", "central", "depot", "depot", "depot",
"depot", "central", "depot", "central", "central", "central",
"central", "central", "central", "depot", "depot", "depot", "depot",
"depot", "depot", "depot", "depot", "depot", "depot", "central",
"depot", "central", "central", "depot", "central", "central",
"central", "central", "central", "depot", "central", "depot",
"depot", "depot", "depot", "depot", "depot", "depot", "depot",
"depot", "depot", "central", "depot", "central", "depot", "depot",
"depot", "central", "depot", "central", "depot", "depot", "depot",
"depot", "central", "central", "central", "central", "central",
"central", "central", "central", "depot", "central", "central",
"central", "central", "central", "depot", "depot", "depot", "depot",
"central", "depot", "central", "central", "central", "central",
"central", "depot", "depot", "depot", "depot", "depot", "depot",
"depot", "depot", "depot", "depot", "depot", "depot", "central",
"depot", "central", "depot", "depot", "depot", "depot", "central",
"depot", "central", "depot", "depot"),
AMT = c(NA, 400, NA, NA,
NA, NA, NA, NA, 400, 400, 400, 400, NA, 400, 400, 400, 400, 400,
NA, 400, NA, NA, NA, NA, NA, NA, 400, 400, 400, 400, NA, 400,
400, 400, 400, 400, 400, 400, 400, 400, 400, 400, NA, 400, NA,
NA, NA, NA, NA, NA, NA, 400, NA, 400, 400, 400, 400, 400, 400,
400, NA, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400,
400, NA, 400, NA, 400, 400, 400, 400, 400, 400, 400, 400, 400,
400, 400, NA, 400, NA, 400, 400, 400, 400, 400, 400, 400, NA,
500, NA, 500, 500, 500, 500, 450, 450, 450, 450, 450, NA, 450,
NA, 450, 450, 450, 450, NA, 450, NA, NA, NA, NA, NA, NA, 450,
450, 450, 450, 450, 450, 450, 450, 450, 450, NA, 450, NA, NA,
350, NA, NA, NA, NA, NA, 350, NA, 300, 300, 300, 300, 300, 300,
300, 300, 300, 300, NA, 300, NA, 300, 300, 300, NA, 300, NA,
300, 300, 300, 300, NA, NA, NA, NA, NA, NA, NA, NA, 350, NA,
NA, NA, NA, NA, 350, 350, 350, 350, NA, 400, NA, NA, NA, NA,
NA, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400,
NA, 400, NA, 400, 400, 400, 400, NA, 400, NA, 400, 400),
DOSE = c(0,
400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400,
400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400,
400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400,
400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400,
400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400,
400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400,
400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400,
400, 400, 400, 400, 400, 0, 500, 500, 500, 500, 500, 500, 450,
450, 450, 450, 450, 450, 450, 450, 450, 450, 450, 450, 450, 450,
450, 450, 450, 450, 450, 450, 450, 450, 450, 450, 450, 450, 450,
450, 450, 450, 450, 450, 450, 0, 350, 350, 350, 350, 350, 350,
350, 350, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300,
300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300, 300,
300, 300, 300, 300, 300, 300, 0, 350, 350, 350, 350, 350, 350,
350, 350, 350, 350, 0, 400, 400, 400, 400, 400, 400, 400, 400,
400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400,
400, 400, 400, 400, 400, 400, 400, 400, 400),
EVID = c(0, 1,
0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0,
0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1,
0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1,
1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0,
0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0,
0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1,
1, 0, 1, 0, 1, 1),
COVAR = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
)))

})

0 comments on commit a5a1c1c

Please sign in to comment.