Skip to content
2 changes: 1 addition & 1 deletion R/class-PKNCAresults.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
18 changes: 13 additions & 5 deletions R/class-summary_PKNCAresults.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 ####
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-class-PKNCAresults.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down
22 changes: 22 additions & 0 deletions tests/testthat/test-class-summary_PKNCAresults.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading