Skip to content

Commit

Permalink
Merge pull request #105 from InsightRX/RXR-1876-warning-infusion
Browse files Browse the repository at this point in the history
RXR-1876 fix warning infusion
  • Loading branch information
roninsightrx authored Jul 9, 2024
2 parents 1de20fb + 82c079d commit 420bbf1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
12 changes: 6 additions & 6 deletions R/regimen_to_nm.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ regimen_to_nm <- function(
suppressWarnings(
bioav_dose <- as.numeric(bioav[dose_cmt])
)
if(!any(is.na(bioav_dose))) {
if(!all(bioav_dose == 1)) {
dat$RATE <- dat$RATE * bioav_dose
message("Recalculating infusion rates to reflect bioavailability for infusion.")
if(any(is.na(bioav_dose))) {
if(any(is.na(bioav_dose) & reg$t_inf > 0)) { # only warn when it actually concerns an infusion
warning("For compartments where bioavailability is specified as model parameter and not as a number, any infusion rates are not corrected for bioavailability.")
}
} else {
warning("Bioavailability not specified correctly, cannot correct infusion rates.")
bioav_dose[is.na(bioav_dose)] <- 1
}
dat$RATE <- dat$RATE * bioav_dose
message("Recalculating infusion rates to reflect bioavailability for infusion.")
}
}
if(!is.null(t_obs)) {
Expand Down
33 changes: 32 additions & 1 deletion tests/testthat/test_regimen_to_nm.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test_that("regimen with infusion correctly recalculates rates when bioavailabili
t_obs = c(1, 2, 3),
bioav = "F1"
),
"Bioavailability not specified correctly"
"For compartments where bioavailability is specified"
)
expected_cols <- c(
"ID",
Expand Down Expand Up @@ -95,3 +95,34 @@ test_that("rate is calculated for any regimen with an infusion length", {
expect_equal(c$RATE, c(0, 0, 0, 0, 0, 10, 20, 0))
})

test_that("throws warning when bioav specified as model parameter and need to convert RATE, but not when not needed", {
a <- new_regimen(
amt = 10,
time = c(1, 2, 3, 4),
t_inf = c(0, 0, 1, 1),
type = c("oral", "oral", "infusion", "infusion")
)
expect_message({
b <- regimen_to_nm(
a,
dose_cmt = c(1, 1, 2, 2),
t_obs = c(1, 2, 3),
bioav = c("Fi", 1)
)
}, "Recalculating infusion rates")
a2 <- new_regimen(
amt = 10,
time = c(1, 2, 3, 4),
t_inf = c(1, 1, 1, 1), # now an infusion in the sc compartment and infusion lengths are >0, should throw warning!
type = c("sc", "sc", "infusion", "infusion")
)
expect_warning(
regimen_to_nm(
a2,
dose_cmt = c(1, 1, 2, 2),
t_obs = c(1, 2, 3),
bioav = c("Fi", 1)
),
"For compartments where bioavailability is specified"
)
})

0 comments on commit 420bbf1

Please sign in to comment.