Skip to content
Open
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
6 changes: 6 additions & 0 deletions R/half.life.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ 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) {
attr(ret, "exclude") <- "No point variability in concentrations for half-life calculation"
return(ret)
}
if (manually.selected.points) {
if (nrow(data) > 0) {
fit <- fit_half_life(data=data, tlast=ret$tlast, conc_units=conc_units)
Expand Down Expand Up @@ -266,6 +271,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
Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test-half.life.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 (#503)", {
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"
)
})
Loading