Skip to content

Commit

Permalink
Merge pull request #97 from InsightRX/RXR-2092-add-tinf-to-sc
Browse files Browse the repository at this point in the history
add t_inf to sc doses in new_regimen
  • Loading branch information
JordanBrooks33 committed Jun 10, 2024
2 parents 4ff83f8 + 8c43c2d commit bffdc74
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Authors@R: c(
person("Jasmine", "Hughes", email = "[email protected]", role = "aut"),
person("Dominic", "Tong", email = "[email protected]", role = "aut"),
person("Kara", "Woo", email = "[email protected]", role = c("aut")),
person("Jordan", "Brooks", email = "[email protected]", role = "aut"),
person("InsightRX", role = c("cph", "fnd")))
Depends: R (>= 3.0.2)
Imports: Rcpp (>= 0.12.9), BH, data.table, stringr, MASS,
Expand Down
16 changes: 11 additions & 5 deletions R/new_regimen.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,16 @@ new_regimen <- function(
if (any(reg$type == "covariate")) {
stop("'covariate' is a protected type and cannot be used for doses.")
}
if(any(type == "infusion") && (is.null(t_inf) || length(t_inf) == 0)) {
reg$t_inf = 1
} else if (any(is.na(t_inf))) {
t_inf[is.na(t_inf)] <- 1
if (is.null(t_inf) || length(t_inf) == 0) {
reg$t_inf <- rep(NA_real_, length(reg$type))
}
if (any(is.na(reg$t_inf))) {
# impute using standard values for each dose type
impute_t_inf <- c(infusion = 1, sc = 1/60, im = 1/60, oral = 0, bolus = 0)
idx <- which(is.na(reg$t_inf))
reg$t_inf[idx] <- impute_t_inf[reg$type[idx]]
# set unrecognized types to 1
reg$t_inf[is.na(reg$t_inf)] <- 1
}
}
if(ss) {
Expand Down Expand Up @@ -121,7 +127,7 @@ new_regimen <- function(
if(length(reg$type) != length(reg$dose_times)) {
reg$type <- rep(reg$type[1], length(reg$dose_times))
}
if(any(reg$type == "infusion")) {
if(any(reg$type %in% c("infusion", "sc", "im"))) {
if(any(reg$t_inf == 0)) {
reg$t_inf[reg$t_inf == 0] <- 1/60
reg$rate[reg$t_inf == 0] <- 60
Expand Down
48 changes: 48 additions & 0 deletions tests/testthat/test_new_regimen.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,51 @@ test_that("new_regimen can take arbitrary values for `type`", {
test_that("do not creat regimens of `type` 'covariate'", {
expect_error(new_regimen(100, times = 0, type = "covariate"))
})

test_that("sc doses accept an infusion length argument'", {
reg1 <- new_regimen(
amt = 100,
times = c(0, 12, 24, 36, 48),
type = "sc",
t_inf = 30/60
)
expect_equal(reg1$t_inf, rep(0.5,5))
})

test_that("t_inf imputed correctly", {
reg1 <- new_regimen(
amt = 100,
times = c(0, 12, 24, 36, 48, 60, 72, 84),
type = c("sc", "infusion", "im", "sc", "infusion", "im","bolus","oral")
)
reg2 <- new_regimen(
amt = 100,
times = c(0, 12, 24, 36, 48, 60, 72, 84),
type = c("sc", "infusion", "im", "sc", "infusion", "im","bolus","oral"),
t_inf = c(2/60, 2.5, 3/60, NA, NA, NA, NA, NA)
)
reg3 <- new_regimen(
amt = 100,
times = c(0, 12, 24, 36, 48, 60, 72, 84),
type = c("sc", "infusion", "im", "sc", "infusion", "im","bolus","oral"),
t_inf = numeric(0)
)
reg4 <- new_regimen(
amt = 100,
times = c(0, 12, 24, 36, 48, 60, 72, 84),
type = c("sc", "infusion", "im", "sc", "infusion", "im","bolus","oral"),
t_inf = NULL
)
reg5 <- new_regimen(
amt = 100,
times = c(0, 12, 24, 36),
type = c("sc", "infusion", "im", "unknown_drug_type"),
t_inf = c(2/60, 2.5, 3/60, NA)
)
expect_equal(reg1$t_inf, c(1/60, 1, 1/60, 1/60, 1, 1/60, 0, 0))
expect_equal(reg2$t_inf, c(2/60, 2.5, 3/60, 1/60, 1, 1/60, 0, 0))
expect_equal(reg3$t_inf, c(1/60, 1, 1/60, 1/60, 1, 1/60, 0, 0))
expect_equal(reg4$t_inf, c(1/60, 1, 1/60, 1/60, 1, 1/60, 0, 0))
expect_equal(reg5$t_inf, c(2/60, 2.5, 3/60, 1))
})

0 comments on commit bffdc74

Please sign in to comment.