Skip to content

Commit 6f96c3e

Browse files
authored
Merge pull request #137 from InsightRX/RXR-3133
RXR-3133: add flexibility in how we determine infusion
2 parents b71e521 + c5908a9 commit 6f96c3e

6 files changed

Lines changed: 107 additions & 15 deletions

File tree

R/advan_create_data.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ advan_create_data <- function(
1818
covariate_model = NULL) {
1919

2020
## Set up basic structure
21+
is_bolus <- is_bolus_or_oral(regimen)
2122
data <- data.frame(
2223
ID = 1,
2324
TIME = regimen$dose_times,
2425
AMT = regimen$dose_amts,
2526
EVID = 1, DV = 0,
2627
RATE = 0,
27-
TYPE = ifelse(regimen$type == "infusion", 1, 0))
28+
TYPE = ifelse(is_bolus, 0, 1)
29+
)
2830

2931
## Add observation data points.
3032
if(!is.null(t_obs)) {
@@ -51,8 +53,8 @@ advan_create_data <- function(
5153
data[[key]] <- parameters[[key]]
5254
}
5355

54-
## Parse infusions
55-
inf_idx <- regimen$type == "infusion"
56+
## Parse infusions (assume all non-bolus doses are infusion-type)
57+
inf_idx <- !is_bolus
5658
if(any(inf_idx)) {
5759
data_idx <- data$TYPE == 1
5860
data$RATE[data_idx] <- data$AMT[data_idx] / regimen$t_inf[inf_idx]

R/create_event_table.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ create_event_table <- function(
122122
# parse list to a design (data.frame)
123123
# For boluses, oral, and covariates, set infusion time to 0. For all
124124
# other methods, assume infusion time was provided correctly
125-
is_bolus <- regimen$type %in% c("bolus", "covariate") | grepl("oral", regimen$type)
125+
is_bolus <- regimen$type %in% c("covariate") | is_bolus_or_oral(regimen)
126126
regimen$t_inf[is_bolus] <- 0
127127
dos <- data.frame(cbind(t = regimen$dose_times,
128128
dose = regimen$dose_amts,

R/new_regimen.R

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,20 @@ new_regimen <- function(
127127
if(length(reg$type) != length(reg$dose_times)) {
128128
reg$type <- rep(reg$type[1], length(reg$dose_times))
129129
}
130-
if(any(reg$type %in% c("infusion", "sc", "im"))) {
131-
if(any(reg$t_inf == 0)) {
132-
reg$t_inf[reg$t_inf == 0] <- 1/60
133-
reg$rate[reg$t_inf == 0] <- 60
130+
# set oral/bolus t_inf to zero, and non-oral/bolus t_inf to minimum 1 minute
131+
idx_bolus_oral <- is_bolus_or_oral(reg)
132+
if (!all(idx_bolus_oral)) {
133+
idx_infusion_0length <- reg$t_inf == 0 & !idx_bolus_oral
134+
if (any(idx_infusion_0length)) {
135+
reg$t_inf[idx_infusion_0length] <- 1/60
136+
reg$rate[idx_infusion_0length] <- 60
134137
}
135138
}
136-
if(any(reg$type == "bolus")) {
137-
reg$t_inf[reg$type == "bolus"] <- 0
138-
reg$rate[reg$type == "bolus"] <- 0
139-
}
140-
if(any(grepl("oral", reg$type))) {
141-
reg$t_inf[grepl("oral", reg$type)] <- 0
142-
reg$rate[grepl("oral", reg$type)] <- 0
139+
if(any(is_bolus_or_oral(reg))) {
140+
reg$t_inf[is_bolus_or_oral(reg)] <- 0
141+
reg$rate[is_bolus_or_oral(reg)] <- 0
143142
}
143+
144144
if(!is.null(cmt)) {
145145
if(length(cmt) != length(reg$dose_times)) {
146146
cmt <- rep(cmt[1], length(reg$dose_times))
@@ -160,3 +160,17 @@ new_regimen <- function(
160160
}
161161
return(reg)
162162
}
163+
164+
#' Is regimen type oral or bolus? (i.e., treat t_inf as zero)
165+
#'
166+
#' Any regimen matching exactly the string 'bolus' or containing the string
167+
#' 'oral' will return `TRUE`, otherwise `FALSE`. Bolus/oral regimens are
168+
#' generally treated as having an infusion duration of zero.
169+
#'
170+
#' @param regimen object of class "regimen"`
171+
#' @returns Returns a logical vector of length equal to the number of doses in
172+
#' the regimen
173+
174+
is_bolus_or_oral <- function(regimen) {
175+
regimen$type == "bolus" | grepl("oral", regimen$type)
176+
}

man/is_bolus_or_oral.Rd

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
3+
test_that("All 'type' should be handled as infusion unless bolus or oral", {
4+
reg1 <- new_regimen(
5+
amt = c(2400, 0, rep(1000, 5)),
6+
times = seq(0, by = 24, length.out = 7),
7+
interval = 24,
8+
type = "infusion_civ",
9+
t_inf = c(24, 24, rep(2, 5))
10+
)
11+
reg2 <- reg1
12+
reg2$type <- rep("infusion", 7)
13+
reg3 <- reg1
14+
reg3$type <- rep("bolus", 7)
15+
16+
tmp1 <- advan_create_data(
17+
parameters = list(CL = 1.72, V = 41.7, Q = 6.5, V2 = 38.4),
18+
regimen = reg1,
19+
t_obs = c(0, 120, 144)
20+
)
21+
tmp2 <- advan_create_data(
22+
parameters = list(CL = 1.72, V = 41.7, Q = 6.5, V2 = 38.4),
23+
regimen = reg2,
24+
t_obs = c(0, 120, 144)
25+
)
26+
tmp3 <- advan_create_data(
27+
parameters = list(CL = 1.72, V = 41.7, Q = 6.5, V2 = 38.4),
28+
regimen = reg3,
29+
t_obs = c(0, 120, 144)
30+
)
31+
expect_true(identical(tmp1, tmp2))
32+
expect_equal(
33+
tmp1$RATE,
34+
c(0, 100, 0, 500, 0, 500, 0, 500, 0, 0, 500, 0, 0, 500, 0)
35+
)
36+
37+
expect_false(identical(reg3, reg2))
38+
expect_equal(
39+
tmp3$RATE,
40+
rep(0, 10) # treated as a bolus dose
41+
)
42+
})

tests/testthat/test_new_regimen.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,17 @@ test_that("t_inf imputed correctly", {
121121
expect_equal(reg5$t_inf, c(2/60, 2.5, 3/60, 1))
122122
})
123123

124+
test_that("regimens of type bolus/oral are recognized as such", {
125+
expect_equal(
126+
is_bolus_or_oral(
127+
new_regimen(interval = 24, type = c("oral_x", "infusion", "sc"))
128+
),
129+
c(TRUE, FALSE, FALSE)
130+
)
131+
expect_equal(
132+
is_bolus_or_oral(
133+
new_regimen(interval = 24, type = c("bolus_unknown", "infusion", "oral"))
134+
),
135+
c(FALSE, FALSE, TRUE)
136+
)
137+
})

0 commit comments

Comments
 (0)