11test_that(" Required column checks occur" , {
22 expect_error(
3- nm_to_regimen(
4- data.frame (EVID = 0 , AMT = 100 )
5- ),
3+ nm_to_regimen(data.frame (EVID = 0 , AMT = 100 )),
64 " TIME column is required"
75 )
86
97 expect_error(
10- nm_to_regimen(
11- data.frame (EVID = 0 , TIME = 0 )
12- ),
8+ nm_to_regimen(data.frame (EVID = 0 , TIME = 0 )),
139 " AMT column is required"
1410 )
1511
1612 expect_error(
17- nm_to_regimen(
18- data.frame (AMT = 100 , TIME = 0 )
19- ),
13+ nm_to_regimen(data.frame (AMT = 100 , TIME = 0 )),
2014 " EVID column is required"
2115 )
2216})
2317
24- test_that(" NM-style dataframe for 1 ID converted to regimen " , {
18+ test_that(" Assume infusion if no compartment but RATE given " , {
2519 pt1 <- data.frame (
2620 ID = 1 ,
2721 EVID = c(1 , 1 , 0 , 1 , 1 , 0 ),
@@ -38,10 +32,26 @@ test_that("NM-style dataframe for 1 ID converted to regimen", {
3832 expect_equal(reg1 $ type , rep(" infusion" , 4 ))
3933})
4034
41- test_that(" Bolus/oral doses handled" , {
35+ test_that(" Assume bolus if no compartment and no RATE given" , {
36+ pt1 <- data.frame (
37+ ID = 1 ,
38+ EVID = c(1 , 1 , 0 , 1 , 1 , 0 ),
39+ AMT = c(100 , 100 , 0 , 200 , 200 , 0 ),
40+ TIME = c(0 , 12 , 23 , 25 , 36 , 47 ),
41+ DV = c(0 , 0 , 5 , 0 , 0 , 12 )
42+ )
43+ reg1 <- nm_to_regimen(pt1 )
44+ expect_true(inherits(reg1 , " regimen" ))
45+ expect_equal(reg1 $ dose_amts , c(100 , 100 , 200 , 200 ))
46+ expect_equal(reg1 $ dose_times , c(0 , 12 , 25 , 36 ))
47+ expect_equal(reg1 $ type , rep(" bolus" , 4 ))
48+ })
49+
50+ test_that(" Assume bolus and no t_inf if RATE not given" , {
4251 pt2 <- data.frame (
4352 ID = 1 ,
4453 EVID = c(1 , 1 , 0 , 1 , 1 , 0 ),
54+ CMT = 1 ,
4555 AMT = c(100 , 100 , 0 , 200 , 200 , 0 ),
4656 TIME = c(0 , 12 , 23 , 25 , 36 , 47 ),
4757 DV = c(0 , 0 , 5 , 0 , 0 , 12 )
@@ -52,12 +62,14 @@ test_that("Bolus/oral doses handled", {
5262 expect_equal(reg2 $ dose_times , c(0 , 12 , 25 , 36 ))
5363 expect_equal(reg2 $ t_inf , rep(0 , 4 ))
5464 expect_equal(reg2 $ type , rep(" bolus" , 4 ))
65+ expect_equal(reg2 $ cmt , rep(1 , 4 ))
5566})
5667
5768test_that(" Multiple regimens from NONMEM-style dataset" , {
5869 nm <- data.frame (
5970 ID = c(1 , 1 , 1 , 2 , 2 , 2 ),
6071 EVID = c(1 , 1 , 0 , 1 , 1 , 0 ),
72+ CMT = c(1 , 1 , 1 , 1 , 2 , 1 ),
6173 AMT = c(100 , 100 , 0 , 200 , 200 , 0 ),
6274 TIME = c(0 , 12 , 23 , 0 , 24 , 47 ),
6375 DV = c(0 , 0 , 5 , 0 , 0 , 12 )
@@ -70,4 +82,42 @@ test_that("Multiple regimens from NONMEM-style dataset", {
7082 expect_equal(multi_regs [[2 ]]$ dose_times , c(0 , 24 ))
7183 expect_equal(multi_regs [[1 ]]$ dose_amts , c(100 , 100 ))
7284 expect_equal(multi_regs [[2 ]]$ dose_amts , c(200 , 200 ))
85+ expect_equal(multi_regs [[1 ]]$ cmt , c(1 , 1 ))
86+ expect_equal(multi_regs [[2 ]]$ cmt , c(1 , 2 ))
87+ })
88+
89+ test_that(" Doses in different compartments handled" , {
90+ pt2 <- data.frame (
91+ ID = 1 ,
92+ EVID = c(1 , 1 , 0 , 1 , 1 , 0 , 1 , 1 , 0 ),
93+ CMT = c(2 , 2 , 2 , 2 , 2 , 2 , 1 , 1 , 2 ), # last two doses are oral
94+ AMT = c(100 , 100 , 0 , 200 , 200 , 0 , 150 , 150 , 0 ),
95+ TIME = c(0 , 12 , 23 , 25 , 36 , 47 , 48 , 60 , 71 ),
96+ RATE = c(100 , 100 , 0 , 200 , 400 , 0 , 0 , 0 , 0 ),
97+ DV = c(0 , 0 , 5 , 0 , 0 , 12 , 0 , 0 , 14 )
98+ )
99+ reg2 <- nm_to_regimen(pt2 )
100+ expect_true(inherits(reg2 , " regimen" ))
101+ expect_equal(reg2 $ dose_amts , c(100 , 100 , 200 , 200 , 150 , 150 ))
102+ expect_equal(reg2 $ dose_times , c(0 , 12 , 25 , 36 , 48 , 60 ))
103+ expect_equal(reg2 $ t_inf , c(1 , 1 , 1 , 0.5 , 0 , 0 ))
104+ expect_equal(reg2 $ cmt , c(2 , 2 , 2 , 2 , 1 , 1 ))
105+ })
106+
107+ test_that(" Different rates handled correctly" , {
108+ pt2 <- data.frame (
109+ ID = 1 ,
110+ EVID = c(1 , 1 , 0 ),
111+ CMT = 2 ,
112+ AMT = c(100 , 200 , 0 ),
113+ TIME = c(0 , 6 , 23 ),
114+ RATE = c(0 , 100 , 0 ),
115+ DV = c(0 , 0 , 5 )
116+ )
117+ reg2 <- nm_to_regimen(pt2 )
118+ expect_true(inherits(reg2 , " regimen" ))
119+ expect_equal(reg2 $ dose_amts , c(100 , 200 ))
120+ expect_equal(reg2 $ dose_times , c(0 , 6 ))
121+ expect_equal(reg2 $ t_inf , c(0 , 2 ))
122+ expect_equal(reg2 $ cmt , c(2 , 2 ))
73123})
0 commit comments