diff --git a/R/class-PKNCAresults.R b/R/class-PKNCAresults.R index e83f2dfb..685c93c8 100644 --- a/R/class-PKNCAresults.R +++ b/R/class-PKNCAresults.R @@ -138,5 +138,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/R/class-summary_PKNCAresults.R b/R/class-summary_PKNCAresults.R index a4ff59e7..9626e07b 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,11 +335,17 @@ 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 -#' +#' #' @param object The PKNCAresults object to clean #' @returns The results data.frame with exclusions set to `NA` #' @noRd diff --git a/tests/testthat/test-class-PKNCAresults.R b/tests/testthat/test-class-PKNCAresults.R index 09faa6b1..137f865b 100644 --- a/tests/testthat/test-class-PKNCAresults.R +++ b/tests/testthat/test-class-PKNCAresults.R @@ -411,14 +411,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", { 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)