Skip to content
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
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,10 @@ the generated intervals:

## Bug fixes

* `pk.calc.ceoi()` gives a clear error, instead of R's "the condition has
length > 1", when an interval has more than one dose row. Use a separate
interval for each infusion (@billdenney, #695).

* `pk.calc.time_above()` with `method = "lin up/log down"` now falls back to
linear interpolation on falling segments that end at a negative value
(@chenyangsu, #697). Previously such segments matched neither the log-down
Expand Down
24 changes: 22 additions & 2 deletions R/pk.calc.simple.R
Original file line number Diff line number Diff line change
Expand Up @@ -2535,11 +2535,15 @@ add.interval.col("swing",


#' Determine the concentration at the end of infusion
#'
#'
#' @details An interval with more than one dose row gives an error (class
#' `pknca_error_ceoi_multiple_doses`); use a separate interval for each
#' infusion.
#'
#' @inheritParams assert_conc_time
#' @inheritParams clean.conc.blq
#' @param duration.dose The duration for the dosing administration (typically
#' from IV infusion)
#' from IV infusion). Only one dose row is supported within an interval.
#' @returns The concentration at the end of the infusion, `NA` if
#' `duration.dose` is `NA`, or `NA` if all `time != duration.dose` or that
#' concentration is missing; an `NA` has the reason in its "exclude" attribute
Expand All @@ -2549,6 +2553,22 @@ pk.calc.ceoi <- function(conc, time, duration.dose=NA, check=TRUE) {
if (check) {
assert_conc_time(conc = conc, time = time)
}

# --- Validation: duration.dose must be a single value ---
if (length(duration.dose) > 1L) {
rlang::abort(
message = paste0(
"pk.calc.ceoi() requires a single dose duration per interval, but ",
length(duration.dose), " were supplied."
),
class = "pknca_error_ceoi_multiple_doses",
call = NULL,
body = c(
"x" = "Multiple end-of-infusion (CeOI) measures within one interval are not supported.",
"i" = "Define separate intervals so that each contains at most one infusion dose row."
)
)
}
if (is.na(duration.dose)) {
structure(NA_real_, exclude = "Dose duration is missing (or there is no dose in the interval)")
} else if (all(time != duration.dose) || is.na(conc[time == duration.dose][1])) {
Expand Down
7 changes: 6 additions & 1 deletion man/pk.calc.ceoi.Rd

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

51 changes: 41 additions & 10 deletions tests/testthat/test-pk.calc.simple.R
Original file line number Diff line number Diff line change
Expand Up @@ -787,16 +787,47 @@ test_that("pk.calc.swing", {
)
})

test_that("pk.calc.ceoi", {
expect_equal(pk.calc.ceoi(conc=0:5, time=0:5, duration.dose=1),
1,
info="Ceoi returns the concentration at the end of the dosing duration")
expect_equal(pk.calc.ceoi(conc=0:5, time=0:5, duration.dose=1.5),
structure(NA_real_, exclude = "No non-missing concentration at the end of the infusion"),
info="Ceoi returns NA if there is no measurement at the end of the dosing duration")
expect_equal(pk.calc.ceoi(conc=0:5, time=0:5, duration.dose=NA),
structure(NA_real_, exclude = "Dose duration is missing (or there is no dose in the interval)"),
info="Ceoi returns NA if there is no dosing duration")
test_that("pk.calc.ceoi gives a clear error for more than one dose row (#695)", {
expect_error(
pk.calc.ceoi(conc = 10 * (0:5), time = 0:5, duration.dose = c(1, 2)),
regexp = "single dose duration per interval",
class = "pknca_error_ceoi_multiple_doses"
)
})

test_that("pk.calc.ceoi is unchanged for a single infusion", {
expect_equal(
pk.calc.ceoi(conc = 0:5, time = 0:5, duration.dose = 1), 1,
info="Ceoi returns the concentration at the end of the dosing duration"
)
expect_equal(pk.calc.ceoi(conc = c(1, 2, 3), time = c(0, 1, 2), duration.dose = 2), 3)
expect_equal(
pk.calc.ceoi(conc = 0:5, time = 0:5, duration.dose = 1.5),
structure(NA_real_, exclude = "No non-missing concentration at the end of the infusion")
)
expect_equal(
pk.calc.ceoi(conc = c(0, 10, NA, 30), time = 0:3, duration.dose = 2),
structure(NA_real_, exclude = "No non-missing concentration at the end of the infusion")
)
expect_equal(
pk.calc.ceoi(conc = 0:5, time = 0:5, duration.dose = NA),
structure(NA_real_, exclude = "Dose duration is missing (or there is no dose in the interval)")
)
})

test_that("pk.nca() explains the ceoi error for more than one dose row (#695)", {
o_conc <- data.frame(ID = 1, time = c(0, 1, 2, 3, 4, 6), conc = c(0, 5, 8, 10, 6, 3))
o_dose <- data.frame(ID = 1, time = c(0, 1), dose = c(100, 200), duration = c(1, 2))
err <- tryCatch(
suppressMessages(pk.nca(PKNCAdata(
PKNCAconc(o_conc, conc ~ time | ID),
PKNCAdose(o_dose, dose ~ time | ID, duration = "duration"),
intervals = data.frame(start = 0, end = Inf, ceoi = TRUE)
))),
error = function(e) e
)
expect_match(conditionMessage(err), "single dose duration per interval")
expect_false(grepl("report a bug", conditionMessage(err), fixed = TRUE))
})

test_that("pk.calc.aucabove", {
Expand Down
Loading