Skip to content

Commit

Permalink
add informative error message to facilitate debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
jasmineirx committed Jun 10, 2024
1 parent 9dcb9a4 commit 2700f07
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ License: MIT + file LICENSE
URL: https://github.com/InsightRX/PKPDsim,
https://insightrx.github.io/PKPDsim/
LazyData: TRUE
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Config/testthat/edition: 3
Config/Needs/website: tidyverse, nlmixr2
Encoding: UTF-8
Expand Down
3 changes: 1 addition & 2 deletions R/PKPDsim-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
#'
#' Simulate regimens for PKPD models defined by ODE systems
#'
#' @docType package
#' @name PKPDsim-package
#' @author Ron Keizer \email{ronkeizer@@gmail.com}
#' @importFrom utils packageVersion tail
#' @importFrom stats aggregate qnorm quantile reshape rnorm
#' @importFrom magrittr `%>%`
#' @keywords internal
NULL
"_PACKAGE"
7 changes: 7 additions & 0 deletions R/create_event_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ create_event_table <- function(

} else if (!is.null(model) && !is.null(attr(model, "cmt_mapping"))) {
cmt_mapping <- attr(model, "cmt_mapping")
if (!all(regimen$type %in% names(cmt_mapping))) {
stop(
"Unrecognized regimen type. Define '",
setdiff(regimen$type, names(cmt_mapping)),
"' in model md field `cmt_mapping`"
)
}
regimen$dose_cmt <- vapply(regimen$type, function(x) cmt_mapping[[x]], FUN.VALUE = numeric(1), USE.NAMES = FALSE)

} else {
Expand Down
9 changes: 9 additions & 0 deletions man/PKPDsim-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions tests/testthat/test_create_event_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,27 @@ test_that("simulatenous doses in different cmts do not remove infusion stops", {
expect_true(all((reg$dose_amts/reg$t_inf) %in% res$rate)) # rates are right
})

test_that("useful cmt_mapping mismatch error is thrown", {
reg <- new_regimen(
amt = 100,
times = c(0, 12, 24),
t_inf = 0,
type = rep("oral", 3)
)
model <- mod_2cmt_iv
attr(model, "cmt_mapping") <- list(infusion = 1, bolus = 1) # not oral
expect_error(
create_event_table(
regimen = reg,
t_obs = 36,
covariates = list(WT = new_covariate(value = c(50, 55), times = c(0, 20))),
model = model
),
"Unrecognized regimen type. Define 'oral' in model md field `cmt_mapping`",
fixed = TRUE
)
})

test_that("sc, im are considered to have t_inf = 0", {
reg1 <- new_regimen(
amt = c(100, 100),
Expand Down

0 comments on commit 2700f07

Please sign in to comment.