From 6da5cffd87bf44fcc33045121f4c8fb8565edbf3 Mon Sep 17 00:00:00 2001 From: Bill Denney Date: Tue, 18 Oct 2022 21:40:08 -0400 Subject: [PATCH] Allow duplicated PPSTRESU --- R/unit-support.R | 3 ++- tests/testthat/test-unit-support.R | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/R/unit-support.R b/R/unit-support.R index 67d8d48a..86cbabe4 100644 --- a/R/unit-support.R +++ b/R/unit-support.R @@ -67,7 +67,8 @@ pknca_units_table <- function(concu, doseu, amountu, timeu, conversions=data.fra } if (nrow(conversions) > 0) { stopifnot(!duplicated(conversions$PPORRESU)) - stopifnot(!duplicated(conversions$PPSTRESU)) + # PPSTRESU may be duplicated because some differing original units may + # converge (e.g. cmax.dn and vss) stopifnot(length(setdiff(names(conversions), c("PPORRESU", "PPSTRESU", "conversion_factor"))) == 0) if (!("conversion_factor" %in% names(conversions))) { if (!requireNamespace("units", quietly=TRUE)) { diff --git a/tests/testthat/test-unit-support.R b/tests/testthat/test-unit-support.R index 46e4ebeb..9eb6a90f 100644 --- a/tests/testthat/test-unit-support.R +++ b/tests/testthat/test-unit-support.R @@ -155,3 +155,15 @@ test_that("pknca_units_table treats missing, NULL, and NA the same", { dplyr::pull("PPORRESU") ))) }) + +test_that("allow duplicate PPSTRESU units", { + d_conversion <- + data.frame( + PPORRESU = c("ng/mL", "(ng/mL)/(mg/kg)", "(mg/kg)/(hr*ng/mL)", "(mg/kg)/(ng/mL)"), + PPSTRESU = c("mg/mL", "mL/kg", "mL/(h*kg)", "mL/kg") + ) + # No error for consistent volume conversion + expect_silent( + pknca_units_table(concu = "ng/mL", doseu = "mg/kg", timeu = "hr", conversions = d_conversion) + ) +})