From 8e83a0e41de92d880e73104d054cc54a1527af23 Mon Sep 17 00:00:00 2001 From: Bill Denney Date: Tue, 28 Jan 2025 22:45:01 -0500 Subject: [PATCH 1/2] Do not try to impute `NA` times due to missing doses --- R/aucint.R | 4 ++-- tests/testthat/test-pk.calc.all.R | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/R/aucint.R b/R/aucint.R index f631f166..5482df49 100644 --- a/R/aucint.R +++ b/R/aucint.R @@ -60,9 +60,9 @@ pk.calc.aucint <- function(conc, time, interval <- assert_intervaltime_single(interval = interval, start = start, end = end) missing_times <- if (is.infinite(interval[2])) { - setdiff(c(interval[1], time.dose), data$time) + setdiff(c(interval[1], time.dose), c(data$time, NA)) } else { - setdiff(c(interval, time.dose), data$time) + setdiff(c(interval, time.dose), c(data$time, NA)) } # Handle the potential double-calculation (before/after tlast) with AUCinf conc_clast <- NULL diff --git a/tests/testthat/test-pk.calc.all.R b/tests/testthat/test-pk.calc.all.R index ec0a55df..0112e116 100644 --- a/tests/testthat/test-pk.calc.all.R +++ b/tests/testthat/test-pk.calc.all.R @@ -743,3 +743,18 @@ test_that("dose is calculable", { expect_equal(as.data.frame(myresult)$PPORRES, rep(2, 2)) expect_equal(as.data.frame(myresult)$PPTESTCD, rep("totdose", 2)) }) + +test_that("all parameters can be calculated (#367)", { + d_conc <- data.frame(conc = 2^(0:-5), time = 0:5) + + o_conc <- PKNCAconc(d_conc, conc~time) + all_param_names <- names(get.interval.cols()) + all_params <- + as.data.frame( + setNames(as.list(rep(TRUE, length(all_param_names))), all_param_names) + ) + all_params$start <- 0 + all_params$end <- Inf + o_data <- PKNCAdata(o_conc, intervals = all_params) + expect_error(o_nca <- pk.nca(o_data), NA) +}) From 02f1f464620e1fe6adb0aa17fd66da4cd0466901 Mon Sep 17 00:00:00 2001 From: Bill Denney Date: Tue, 9 Dec 2025 09:09:02 -0500 Subject: [PATCH 2/2] Prevent aucint.last that does not work from calculating --- tests/testthat/test-pk.calc.all.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/testthat/test-pk.calc.all.R b/tests/testthat/test-pk.calc.all.R index 0244bac5..473273d0 100644 --- a/tests/testthat/test-pk.calc.all.R +++ b/tests/testthat/test-pk.calc.all.R @@ -778,6 +778,8 @@ test_that("all parameters can be calculated (#367)", { ) all_params$start <- 0 all_params$end <- Inf + # Parameters that do not work right now + all_params$aucint.last <- FALSE o_data <- PKNCAdata(o_conc, intervals = all_params) expect_error(o_nca <- pk.nca(o_data), NA) })