From d7c08565e0319dda7db17b864b63838eb3234e14 Mon Sep 17 00:00:00 2001 From: Gero1999 Date: Mon, 12 Jan 2026 11:41:59 +0100 Subject: [PATCH 1/4] add exclude message in half.life.R --- R/half.life.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/R/half.life.R b/R/half.life.R index 0dab3f1e..49306f3b 100644 --- a/R/half.life.R +++ b/R/half.life.R @@ -180,6 +180,10 @@ pk.calc.half.life <- function(conc, time, tmax, tlast, # as.numeric is for units handling dfK <- data[as.numeric(data$time) > as.numeric(ret$tmax), ] } + if (sd(data$log_conc, na.rm = TRUE) == 0) { + # All concentrations are the same (non-zero) value + attr(ret, "exclude") <- "No point variability in concentrations for half-life calculation" + } if (manually.selected.points) { if (nrow(data) > 0) { fit <- fit_half_life(data=data, tlast=ret$tlast, conc_units=conc_units) @@ -266,6 +270,7 @@ pk.calc.half.life <- function(conc, time, tmax, tlast, class = "pknca_halflife_too_few_points" ) } + # Drop the inputs of tmax and tlast, if given. if (!missing(tmax)) ret$tmax <- NULL From 88812001107ccc9d0ce575df2ca405b4caa4d818 Mon Sep 17 00:00:00 2001 From: Gero1999 Date: Mon, 12 Jan 2026 11:49:04 +0100 Subject: [PATCH 2/4] add direct return in flat line case --- R/half.life.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/half.life.R b/R/half.life.R index 49306f3b..0ac21718 100644 --- a/R/half.life.R +++ b/R/half.life.R @@ -183,6 +183,7 @@ pk.calc.half.life <- function(conc, time, tmax, tlast, if (sd(data$log_conc, na.rm = TRUE) == 0) { # All concentrations are the same (non-zero) value attr(ret, "exclude") <- "No point variability in concentrations for half-life calculation" + return(ret) } if (manually.selected.points) { if (nrow(data) > 0) { From 00c4d25afac3a3a173145df1380e77be51be1add Mon Sep 17 00:00:00 2001 From: Gero1999 Date: Mon, 12 Jan 2026 11:49:24 +0100 Subject: [PATCH 3/4] test: add test case for half.life calculation of a flat line --- tests/testthat/test-half.life.R | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/testthat/test-half.life.R b/tests/testthat/test-half.life.R index 202fa421..71efdd0a 100644 --- a/tests/testthat/test-half.life.R +++ b/tests/testthat/test-half.life.R @@ -506,3 +506,20 @@ test_that("get_halflife_points method (1: PKNCAdata, 2: PKNCAresults)", { info = "get_halflife_points uses lambda.z.time.last, not tlast" ) }) + +test_that("half-life has a exclude message when it cannot be calculated for flat data", { + result <- suppressMessages( + pk.calc.half.life( + conc = c(1, 1, 1, 1), + time = c(0, 1, 2, 3), + min.hl.points = 3, + allow.tmax.in.half.life = TRUE, + adj.r.squared.factor = 0.0001, + check = FALSE + ) + ) + expect_equal( + attr(result, "exclude"), + "No point variability in concentrations for half-life calculation" + ) +}) From a69150ce239f3398e9153676bd0973537091a6eb Mon Sep 17 00:00:00 2001 From: Gero1999 Date: Mon, 12 Jan 2026 11:51:33 +0100 Subject: [PATCH 4/4] add issue references (#503) --- R/half.life.R | 2 +- tests/testthat/test-half.life.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/half.life.R b/R/half.life.R index 0ac21718..0ab7aab6 100644 --- a/R/half.life.R +++ b/R/half.life.R @@ -180,8 +180,8 @@ pk.calc.half.life <- function(conc, time, tmax, tlast, # as.numeric is for units handling dfK <- data[as.numeric(data$time) > as.numeric(ret$tmax), ] } + # When all concentrations are the same (non-zero) value cannot compute half-life (#503) if (sd(data$log_conc, na.rm = TRUE) == 0) { - # All concentrations are the same (non-zero) value attr(ret, "exclude") <- "No point variability in concentrations for half-life calculation" return(ret) } diff --git a/tests/testthat/test-half.life.R b/tests/testthat/test-half.life.R index 71efdd0a..afd97d8b 100644 --- a/tests/testthat/test-half.life.R +++ b/tests/testthat/test-half.life.R @@ -507,7 +507,7 @@ test_that("get_halflife_points method (1: PKNCAdata, 2: PKNCAresults)", { ) }) -test_that("half-life has a exclude message when it cannot be calculated for flat data", { +test_that("half-life has a exclude message when it cannot be calculated for flat data (#503)", { result <- suppressMessages( pk.calc.half.life( conc = c(1, 1, 1, 1),