diff --git a/NEWS.md b/NEWS.md index 1fe466c..ff1e464 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,7 @@ the inclusion of IV NCA parameters and additional specifications of the dosing including dose amount and route. # PKNCA 0.11.0.9000 + * PKNCA will now give an error when there are unexpected interval columns. The `keep_interval_cols` option can be used to mitigate this error. * PKNCA will now make verifications on the `intervals` object within the @@ -17,6 +18,7 @@ the dosing including dose amount and route. error. (#298) * Removed native pipes (`|>`) so that PKNCA will work with older versions of R (#304). +* Missing dosing times to `pk.calc.c0()` will not cause an error (#344) # PKNCA 0.11.0 diff --git a/R/pk.calc.c0.R b/R/pk.calc.c0.R index c39064e..7ea77ba 100644 --- a/R/pk.calc.c0.R +++ b/R/pk.calc.c0.R @@ -24,11 +24,15 @@ pk.calc.c0 <- function(conc, time, time.dose=0, if (check) { assert_conc_time(conc = conc, time = time) } - if (length(time.dose) != 1) + if (length(time.dose) != 1) { stop("time.dose must be a scalar") - if (!is.numeric(time.dose) | is.factor(time.dose)) + } else if (!is.numeric(time.dose) | is.factor(time.dose)) { stop("time.dose must be a number") - if (time.dose > max(time)) { + } + if (is.na(time.dose)) { + warning("time.dose is NA") + return(NA) + } else if (time.dose > max(time)) { warning("time.dose is after all available data") return(NA) } diff --git a/tests/testthat/test-pk.calc.c0.R b/tests/testthat/test-pk.calc.c0.R index adf1146..da0720d 100644 --- a/tests/testthat/test-pk.calc.c0.R +++ b/tests/testthat/test-pk.calc.c0.R @@ -11,6 +11,10 @@ test_that("pk.calc.c0", { expect_error(pk.calc.c0(5:1, 0:4, method="blah"), regexp="should be one of", info="method must be valid") + expect_warning( + pk.calc.c0(conc = 0:3, time = 0:3, time.dose = NA_real_), + regexp = "time.dose is NA" + ) expect_warning(pk.calc.c0(5:1, 0:4, time.dose=30), regexp="time.dose is after all available data")