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

RXR-1876 fix warning infusion #105

Merged
merged 3 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
)
})
Loading