Skip to content

Commit

Permalink
fix issue in test; add warning
Browse files Browse the repository at this point in the history
  • Loading branch information
roninsightrx committed Jun 24, 2024
1 parent c4bf586 commit 3887179
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
5 changes: 5 additions & 0 deletions R/sim.R
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ sim <- function (ode = NULL,
p <- parameters
}
}
if(!is.null(attr(ode, "iov")$n_bins) && attr(ode, "iov")$n_bins > 1) {
if(attr(ode, "iov")$n_bins != (length(iov_bins)-1)) {
warning("Number of IOV bins specified for model does not match supplied `iov_bins` argument. This could lead to simulation failures or erroneous output.")
}
}
if(is.null(analytical)) {
if(inherits(ode, "function") && !isTRUE(attr(ode, "cpp"))) {
stop("Sorry. Non-C++ functions are deprecated as input for ODE.")
Expand Down
50 changes: 46 additions & 4 deletions tests/testthat/test_iov.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ pars <- list(
"kappa_CL_1" = 0,
"kappa_CL_2" = 0,
"kappa_CL_3" = 0,
"kappa_CL_4" = 0,
"eta_CL" = 0,
"CL" = 5,
"V" = 50,
"KA" = 1
)

pk1 <- new_ode_model(
code = "
CL_iov = CL * exp(kappa_CL + eta_CL);
Expand All @@ -16,7 +16,7 @@ pk1 <- new_ode_model(
",
iov = list(
cv = list(CL = 0.2),
n_bins = 4
n_bins = 3
),
obs = list(cmt = 2, scale = "V"),
dose = list(cmt = 1, bioav = 1),
Expand All @@ -33,6 +33,49 @@ reg1 <- new_regimen(
)
iov_var <- 0.3 ^ 2 # 30% IOV

test_that("Throws warning when `iov_bins` length doesn't match number of specified bins", {
expect_warning({
sim(
ode = pk1,
parameters = pars,
regimen = reg1,
omega = c(
iov_var, # IOV in CL
0, iov_var,
0, 0, iov_var,
0, 0, 0, iov_var,
0, 0, 0, 0, 0.3 # IIV in CL
),
n = 1,
iov_bins = c(0, 24, 48, 72, 999), # one bin too many
omega_type = "normal",
only_obs = TRUE,
output_include = list(parameters = TRUE, variables = TRUE)
)
})
expect_warning({
expect_warning({
sim(
ode = pk1,
parameters = pars,
regimen = reg1,
omega = c(
iov_var, # IOV in CL
0, iov_var,
0, 0, iov_var,
0, 0, 0, iov_var,
0, 0, 0, 0, 0.3 # IIV in CL
),
n = 1,
iov_bins = c(0, 24, 999), # one bin too few
omega_type = "normal",
only_obs = TRUE,
output_include = list(parameters = TRUE, variables = TRUE)
)
}, "Number of IOV bins specified")
}, "subscript out of bounds")
})

test_that("IOV is added to parameters", {
skip_on_cran()
set.seed(32)
Expand Down Expand Up @@ -95,7 +138,7 @@ test_that("Change in F in 2nd bin is applied in 2nd bin and not later.", {
",
iov = list(
cv = list(F = 0.2),
n_bins = 4
n_bins = 3
),
obs = list(cmt = 2, scale = "V"),
dose = list(cmt = 1, bioav = "Fi"),
Expand Down Expand Up @@ -181,5 +224,4 @@ test_that("error is not invoked when using parameters_table", {
output_include = list(parameters = TRUE, variables = TRUE)
)
)

})

0 comments on commit 3887179

Please sign in to comment.