From 5f9b40970f97c287dac52c6f6681143ac0ae59fd Mon Sep 17 00:00:00 2001 From: Kiran Date: Wed, 8 Jul 2026 13:15:23 +0530 Subject: [PATCH 1/2] Add "start" and "end" in order to group_vars.PKNCAresults --- R/class-PKNCAresults.R | 2 +- tests/testthat/test-class-PKNCAresults.R | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/R/class-PKNCAresults.R b/R/class-PKNCAresults.R index 41dc16b1..acfcd4ec 100644 --- a/R/class-PKNCAresults.R +++ b/R/class-PKNCAresults.R @@ -398,5 +398,5 @@ getGroups.PKNCAresults <- function(object, #' from the PKNCAconc object within #' @exportS3Method dplyr::group_vars group_vars.PKNCAresults <- function(x) { - group_vars.PKNCAconc(as_PKNCAconc(x)) + c("start","end",group_vars.PKNCAconc(as_PKNCAconc(x))) } diff --git a/tests/testthat/test-class-PKNCAresults.R b/tests/testthat/test-class-PKNCAresults.R index 87e19f66..effac1d8 100644 --- a/tests/testthat/test-class-PKNCAresults.R +++ b/tests/testthat/test-class-PKNCAresults.R @@ -421,14 +421,14 @@ test_that("group_vars.PKNCAresult", { o_data_group <- PKNCAdata(o_conc_group, intervals = data.frame(start = 0, end = 1, cmax = TRUE)) suppressMessages(o_nca_group <- pk.nca(o_data_group)) - expect_equal(dplyr::group_vars(o_nca_group), "Subject") + expect_equal(dplyr::group_vars(o_nca_group), c("start", "end", "Subject")) # Check that it works without groupings as expected [empty] o_conc_nongroup <- PKNCAconc(as.data.frame(datasets::Theoph)[datasets::Theoph$Subject == 1,], conc~Time) o_data_nogroup <- PKNCAdata(o_conc_nongroup, intervals = data.frame(start = 0, end = 1, cmax = TRUE)) suppressMessages(o_nca_nogroup <- pk.nca(o_data_nogroup)) - expect_equal(dplyr::group_vars(o_nca_nogroup), character(0)) + expect_equal(dplyr::group_vars(o_nca_nogroup), c("start","end")) }) test_that("as.data.frame.PKNCAresults can filter for only requested parameters", { From 3ba01b5fdd2e8a4bb26568f32b177ec67eee3fab Mon Sep 17 00:00:00 2001 From: Kiran Date: Wed, 8 Jul 2026 15:29:05 +0530 Subject: [PATCH 2/2] Add caption_prefix to summary --- R/class-summary_PKNCAresults.R | 16 ++++++++++---- .../test-class-summary_PKNCAresults.R | 22 +++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/R/class-summary_PKNCAresults.R b/R/class-summary_PKNCAresults.R index a4ff59e7..cccb8754 100644 --- a/R/class-summary_PKNCAresults.R +++ b/R/class-summary_PKNCAresults.R @@ -63,7 +63,8 @@ summary.PKNCAresults <- function(object, ..., summarize.n.per.group = deprecated(), not.requested.string = deprecated(), not.calculated.string = deprecated(), - pretty_names = NULL) { + pretty_names = NULL, + caption_prefix = NULL) { # Process inputs #### ## Deprecated inputs #### @@ -183,7 +184,8 @@ summary.PKNCAresults <- function(object, ..., param_names = names(result_values), pretty_names = pretty_names, footnote_N = "N" %in% names(ret), - footnote_n = attr(ret, "footnote_n", exact = TRUE) + footnote_n = attr(ret, "footnote_n", exact = TRUE), + caption_prefix = caption_prefix ) attr(ret, "footnote_n") <- NULL ret_pretty <- rename_summary_PKNCAresults(data = ret, unit_list = unit_list, pretty_names = pretty_names) @@ -294,7 +296,7 @@ get_summary_PKNCAresults_count_N <- function(data, result_group, subject_col, su } # Provide a clean caption for summarized parameters -get_summary_PKNCAresults_caption <- function(param_names, pretty_names, footnote_N, footnote_n) { +get_summary_PKNCAresults_caption <- function(param_names, pretty_names, footnote_N, footnote_n, caption_prefix) { # Extract the summarization descriptions for the caption summary_descriptions <- unlist( @@ -333,7 +335,13 @@ get_summary_PKNCAresults_caption <- function(param_names, pretty_names, footnote if (footnote_n) { ret <- c(ret, "n: number of measurements included in summary") } - paste(ret, collapse = "; ") + current_caption <- paste(ret, collapse = "; ") + + if (is.null(caption_prefix)) { + current_caption + } else { + paste(caption_prefix, current_caption) + } } #' Clean up the exclusions in the object diff --git a/tests/testthat/test-class-summary_PKNCAresults.R b/tests/testthat/test-class-summary_PKNCAresults.R index 5bcd3726..69bf125b 100644 --- a/tests/testthat/test-class-summary_PKNCAresults.R +++ b/tests/testthat/test-class-summary_PKNCAresults.R @@ -307,6 +307,28 @@ test_that("print.summary_PKNCAresults works", { ) }) +test_that("print.summary_PKNCAresults supports caption_prefix", { + tmpconc <- generate.conc(2, 1, 0:24) + tmpdose <- generate.dose(tmpconc) + myconc <- PKNCAconc(tmpconc, formula = conc ~ time | treatment + ID) + mydose <- PKNCAdose(tmpdose, formula = dose ~ time | treatment + ID) + mydata <- PKNCAdata(myconc, mydose) + myresult <- pk.nca(mydata) + + expect_output( + print(summary(myresult, caption_prefix = "Summary:")), + paste( + " start end treatment N auclast cmax tmax half.life.*", + " 0 24 Trt 1 2 13.8 \\[2.51\\] . . ..*", + " 0 Inf Trt 1 2 . 0.970 \\[4.29\\] 3.00 \\[2.00, 4.00\\] 14.2 \\[2.79\\].*", + "", + "Caption: Summary: auclast, cmax, aucinf.obs: geometric mean and geometric coefficient of variation; tmax: median and range; half.life: arithmetic mean and standard deviation", + sep = "\n" + ) + ) +}) + + test_that("summary pretty_name control", { tmpconc <- generate.conc(2, 1, 0:24) tmpdose <- generate.dose(tmpconc)