Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add t_inf to sc doses in new_regimen #97

Merged
merged 8 commits into from
Jun 10, 2024
26 changes: 23 additions & 3 deletions R/new_regimen.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,29 @@ new_regimen <- function(
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
reg$t_inf[reg$type=="infusion"] = 1
JordanBrooks33 marked this conversation as resolved.
Show resolved Hide resolved
} else if (any(is.na(t_inf))) {
t_inf[is.na(t_inf)] <- 1
reg$t_inf[(reg$type=="infusion" & is.na(t_inf))] <- 1
}
if(any(type == "sc") && (is.null(t_inf) || length(t_inf) == 0)) {
reg$t_inf[reg$type=="sc"] = 1/60
} else if (any(is.na(t_inf))) {
reg$t_inf[(reg$type=="sc" & is.na(reg$t_inf))] <- 1/60
}
if(any(type == "im") & (is.null(t_inf) || length(t_inf) == 0)) {
reg$t_inf[reg$type=="im"] = 1/60
} else if (any(is.na(t_inf))) {
reg$t_inf[(reg$type=="im" & is.na(reg$t_inf))] <- 1/60
}
if(any(type == "bolus") && (is.null(t_inf) || length(t_inf) == 0)) {
reg$t_inf[reg$type=="bolus"] = 0
} else if (any(is.na(t_inf))) {
reg$t_inf[(reg$type=="bolus" & is.na(reg$t_inf))] <- 0
}
if(any(type == "oral") && (is.null(t_inf) || length(t_inf) == 0)) {
reg$t_inf[reg$type=="oral"] = 0
} else if (any(is.na(t_inf))) {
reg$t_inf[(reg$type=="oral" & is.na(reg$t_inf))] <- 0
JordanBrooks33 marked this conversation as resolved.
Show resolved Hide resolved
}
}
if(ss) {
Expand Down Expand Up @@ -121,7 +141,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 == "infusion" | reg$type == "sc" | reg$type == "im")) {
JordanBrooks33 marked this conversation as resolved.
Show resolved Hide resolved
if(any(reg$t_inf == 0)) {
reg$t_inf[reg$t_inf == 0] <- 1/60
reg$rate[reg$t_inf == 0] <- 60
Expand Down
27 changes: 27 additions & 0 deletions tests/testthat/test_new_regimen.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,30 @@ 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)
)
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))
})

Loading