From e4b32e6c7a2ca09a29b37bed2766451363bca2d5 Mon Sep 17 00:00:00 2001 From: BFalquet Date: Tue, 18 Jun 2024 19:12:05 +0200 Subject: [PATCH 1/7] report_null as method --- DESCRIPTION | 1 + NAMESPACE | 2 +- NEWS.md | 1 + R/ael01_nollt.R | 18 +------ R/chevron_tlg-S4class.R | 7 +-- R/report_null.R | 87 ++++++++++++++++++++++++++++++ R/rtables_utils.R | 37 ------------- R/utils.R | 22 -------- _pkgdown.yaml | 1 + man/ael01_nollt.Rd | 9 ---- man/chevron_tlg-class.Rd | 6 +-- man/report_null.Rd | 38 +++++++++---- man/std_postprocess.Rd | 22 +++----- tests/testthat/test-default_tlg.R | 2 +- tests/testthat/test-empty_report.R | 4 +- 15 files changed, 136 insertions(+), 121 deletions(-) create mode 100644 R/report_null.R diff --git a/DESCRIPTION b/DESCRIPTION index 4d23396220..2a168170d8 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -81,6 +81,7 @@ LazyData: true Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.1 Collate: + 'report_null.R' 'utils.R' 'chevron_tlg-S4class.R' 'ael01_nollt.R' diff --git a/NAMESPACE b/NAMESPACE index 67212398e9..cd00e518ff 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -171,7 +171,6 @@ export(mng01) export(mng01_main) export(mng01_pre) export(nocoding) -export(null_listing) export(null_report) export(outcome_rule) export(pdt01) @@ -210,6 +209,7 @@ export(rspt01_pre) export(run) export(script_funs) export(set_section_div) +export(std_postprocess) export(ttet01) export(ttet01_main) export(ttet01_post) diff --git a/NEWS.md b/NEWS.md index 7e07fa8fd9..be745211e3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ * Add `AEL02`, `AEL03` templates. * Modify the post processing of `MHT01` to allow multiple `row_split_var`. +* Export the `std_postprocessing` function to simplify the post processing. # chevron 0.2.6 diff --git a/R/ael01_nollt.R b/R/ael01_nollt.R index a11f3a04d8..d3ba55213b 100644 --- a/R/ael01_nollt.R +++ b/R/ael01_nollt.R @@ -45,21 +45,6 @@ ael01_nollt_pre <- function(adam_db, adam_db } -#' @describeIn ael01_nollt Postprocessing -#' -#' @inheritParams gen_args -#' @returns the postprocessing function returns an `rlistings` object or an `ElementaryTable` (null report). -#' -ael01_nollt_post <- function(tlg, ...) { - if (is(tlg, "list")) { - if (length(tlg) == 0) tlg <- null_report - } else { - if (nrow(tlg) == 0) tlg <- null_report - } - - tlg -} - #' `AEL01_NOLLT` Listing 1 (Default) Glossary of Preferred Terms and Investigator-Specified Terms. #' #' @include chevron_tlg-S4class.R @@ -69,6 +54,5 @@ ael01_nollt_post <- function(tlg, ...) { #' run(ael01_nollt, syn_data) ael01_nollt <- chevron_l( main = ael01_nollt_main, - preprocess = ael01_nollt_pre, - postprocess = ael01_nollt_post + preprocess = ael01_nollt_pre ) diff --git a/R/chevron_tlg-S4class.R b/R/chevron_tlg-S4class.R index 29496bbed9..ac02566e49 100644 --- a/R/chevron_tlg-S4class.R +++ b/R/chevron_tlg-S4class.R @@ -1,4 +1,5 @@ #' @include utils.R +#' @include report_null.R # Chevron_tlg ---- @@ -141,7 +142,7 @@ methods::setValidity("chevron_simple", function(object) { #' chevron_t <- function(main = function(adam_db, ...) build_table(basic_table(), adam_db[[1]]), preprocess = function(adam_db, ...) adam_db, - postprocess = report_null, + postprocess = std_postprocess, ...) { res <- .chevron_t( main = main, @@ -166,7 +167,7 @@ chevron_t <- function(main = function(adam_db, ...) build_table(basic_table(), a #' chevron_l <- function(main = function(adam_db, ...) data.frame(), preprocess = function(adam_db, ...) adam_db, - postprocess = function(tlg, ...) tlg, + postprocess = std_postprocess, ...) { res <- .chevron_l( main = main, @@ -195,7 +196,7 @@ chevron_l <- function(main = function(adam_db, ...) data.frame(), #' chevron_g <- function(main = function(adam_db, ...) ggplot2::ggplot(), preprocess = function(adam_db, ...) adam_db, - postprocess = function(tlg, ...) tlg, + postprocess = std_postprocess, ...) { res <- .chevron_g( main = main, diff --git a/R/report_null.R b/R/report_null.R new file mode 100644 index 0000000000..6e7f968ac2 --- /dev/null +++ b/R/report_null.R @@ -0,0 +1,87 @@ +#' Creates `NULL` Report +#' +#' @param tlg to convert to null report. +#' @param ind (`integer`) indentation for the outputs of class `VTableTree`. +#' @param ... not used. +#' +#' @rdname report_null +#' @name report_null +#' +#' @returns the `tlg` object or a `NULL` report if the `tlg` is `NULL`, is a `TableTree` with 0 rows, is a `listing_df` +#' with 0 rows or is a `list` with 0 elements. +#' +#' @export +#' @examples +#' report_null(NULL) +setGeneric("report_null", function(tlg, ...) { + standardGeneric("report_null") +}) + +#' @rdname report_null +setMethod("report_null", "NULL", function(tlg, ind = 2L, ...) { + res <- null_report + table_inset(res) <- ind + res +}) + +#' @rdname report_null +setMethod("report_null", "VTableTree", function(tlg, ind = 2L, ...) { + res <- if (nrow(tlg) == 0L || count_children(tlg) == 0) { + null_report + } else { + tlg + } + + table_inset(res) <- ind + res +}) + +#' @rdname report_null +setMethod("report_null", "listing_df", function(tlg, ind = 2L, ...) { + if (nrow(tlg) == 0L) { + res <- null_report + table_inset(res) <- ind + res + } else { + tlg + } +}) + +#' @rdname report_null +setMethod("report_null", "list", function(tlg, ...) { + if (length(tlg) == 0) { + res <- null_report + table_inset(res) <- ind + res + } else { + tlg + } +}) + +#' @rdname report_null +setMethod("report_null", "ANY", function(tlg, ...) { + tlg +}) + +#' @export +#' @rdname report_null +null_report <- rtables::rtable( + header = "", + rrow("", "Null Report: No observations met the reporting criteria for inclusion in this output.") +) + +#' Standard Post Processing +#' +#' @param tlg to convert to null report. +#' @param ind (`integer`) indentation for the outputs of class `VTableTree`. +#' @param ... not used. +#' +#' @export +#' @returns a post processed `tlg` or a `NULL` report. +#' +std_postprocess <- function(tlg, ind = 2L, ...) { + assert_int(ind, lower = 0L) + + res <- report_null(tlg, ind = ind) + res +} diff --git a/R/rtables_utils.R b/R/rtables_utils.R index 8b254fe371..8f26656264 100644 --- a/R/rtables_utils.R +++ b/R/rtables_utils.R @@ -353,28 +353,6 @@ ifneeded_split_col <- function(lyt, var, ...) { } } -#' Create a Null Report -#' -#' @rdname report_null -#' @aliases null_report -#' @param tlg (`TableTree`) object. -#' @param ... not used. Important to be used directly as post processing function. -#' -#' @export -#' -#' @returns original `TableTree` or a null report if no observation are found in the table. -report_null <- function(tlg, ...) { - assert_true(is.null(tlg) || rtables::is_rtable(tlg)) - - if (is.null(tlg) || nrow(tlg) == 0L) { - return(null_report) - } - if (count_children(tlg) == 0) { - return(null_report) - } - tlg -} - #' Count Children #' #' @keywords internal @@ -390,21 +368,6 @@ count_children <- function(x) { )) } -#' @export -#' @rdname report_null -null_report <- rtables::rtable( - header = "", - rrow("", "Null Report: No observations met the reporting criteria for inclusion in this output.") -) - -#' @export -#' @rdname report_null -null_listing <- rlistings::as_listing( - df = data.frame(x = formatters::with_label( - "Null Report: No observations met the reporting criteria for inclusion in this output.", "" - )) -) - has_overall_col <- function(lbl_overall) { !is.null(lbl_overall) && !identical(lbl_overall, "") } diff --git a/R/utils.R b/R/utils.R index 3c6e223635..0d415c6336 100755 --- a/R/utils.R +++ b/R/utils.R @@ -34,28 +34,6 @@ smart_prune <- function(tlg) { res } -#' Standard post processing -#' -#' @param tlg (`TableTree`) object. -#' @param ind (`integer`) the indentation of the table. -#' @param ... not used at the moment. -#' -#' @note Standard post processing includes: -#' * `NULL` report creation if necessary -#' * indentation -#' -#' @returns a post-processed `tlg`. -#' -#' @keywords internal -std_postprocess <- function(tlg, ind = 2L, ...) { - assert_int(ind, lower = 0L) - - res <- report_null(tlg) - table_inset(res) <- ind - - res -} - #' Standard Main Listing Function #' #' @inheritParams gen_args diff --git a/_pkgdown.yaml b/_pkgdown.yaml index 6f1892c2a6..802d337b1d 100644 --- a/_pkgdown.yaml +++ b/_pkgdown.yaml @@ -115,6 +115,7 @@ reference: - assert_valid_variable - create_id_listings - report_null + - std_postprocessing - smart_prune - var_labels_for - format_date diff --git a/man/ael01_nollt.Rd b/man/ael01_nollt.Rd index ce9269a84c..a73252fb9d 100644 --- a/man/ael01_nollt.Rd +++ b/man/ael01_nollt.Rd @@ -4,7 +4,6 @@ \name{ael01_nollt_main} \alias{ael01_nollt_main} \alias{ael01_nollt_pre} -\alias{ael01_nollt_post} \alias{ael01_nollt} \title{\code{AEL01_NOLLT} Listing 1 (Default) Glossary of Preferred Terms and Investigator-Specified Terms.} \format{ @@ -28,8 +27,6 @@ ael01_nollt_pre( ... ) -ael01_nollt_post(tlg, ...) - ael01_nollt } \arguments{ @@ -45,15 +42,11 @@ Key columns allow you to group repeat occurrences.} \item{split_into_pages_by_var}{(\code{character} or \code{NULL}) the name of the variable to split the listing by.} \item{...}{additional arguments passed to \code{\link[rlistings:listings]{rlistings::as_listing}}.} - -\item{tlg}{(\code{TableTree}, \code{Listing} or \code{ggplot}) object typically produced by a \code{main} function.} } \value{ the main function returns an \code{rlistings} or a \code{list} object. the preprocessing function returns a \code{list} of \code{data.frame}. - -the postprocessing function returns an \code{rlistings} object or an \code{ElementaryTable} (null report). } \description{ \code{AEL01_NOLLT} Listing 1 (Default) Glossary of Preferred Terms and Investigator-Specified Terms. @@ -72,8 +65,6 @@ the postprocessing function returns an \code{rlistings} object or an \code{Eleme \item \code{ael01_nollt_pre()}: Preprocessing -\item \code{ael01_nollt_post()}: Postprocessing - }} \note{ \itemize{ diff --git a/man/chevron_tlg-class.Rd b/man/chevron_tlg-class.Rd index ee1d8a0013..16682e133c 100644 --- a/man/chevron_tlg-class.Rd +++ b/man/chevron_tlg-class.Rd @@ -24,21 +24,21 @@ chevron_t( main = function(adam_db, ...) build_table(basic_table(), adam_db[[1]]), preprocess = function(adam_db, ...) adam_db, - postprocess = report_null, + postprocess = std_postprocess, ... ) chevron_l( main = function(adam_db, ...) data.frame(), preprocess = function(adam_db, ...) adam_db, - postprocess = function(tlg, ...) tlg, + postprocess = std_postprocess, ... ) chevron_g( main = function(adam_db, ...) ggplot2::ggplot(), preprocess = function(adam_db, ...) adam_db, - postprocess = function(tlg, ...) tlg, + postprocess = std_postprocess, ... ) diff --git a/man/report_null.Rd b/man/report_null.Rd index 96ece9dbb0..4785f88dca 100644 --- a/man/report_null.Rd +++ b/man/report_null.Rd @@ -1,32 +1,48 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/rtables_utils.R +% Please edit documentation in R/report_null.R \docType{data} \name{report_null} \alias{report_null} +\alias{report_null,NULL-method} +\alias{report_null,VTableTree-method} +\alias{report_null,listing_df-method} +\alias{report_null,list-method} +\alias{report_null,ANY-method} \alias{null_report} -\alias{null_listing} -\title{Create a Null Report} +\title{Creates \code{NULL} Report} \format{ An object of class \code{ElementaryTable} with 1 rows and 1 columns. - -An object of class \code{listing_df} (inherits from \code{tbl_df}, \code{tbl}, \code{data.frame}) with 1 rows and 1 columns. } \usage{ report_null(tlg, ...) -null_report +\S4method{report_null}{NULL}(tlg, ind = 2L, ...) + +\S4method{report_null}{VTableTree}(tlg, ind = 2L, ...) + +\S4method{report_null}{listing_df}(tlg, ind = 2L, ...) + +\S4method{report_null}{list}(tlg, ...) -null_listing +\S4method{report_null}{ANY}(tlg, ...) + +null_report } \arguments{ -\item{tlg}{(\code{TableTree}) object.} +\item{tlg}{to convert to null report.} -\item{...}{not used. Important to be used directly as post processing function.} +\item{...}{not used.} + +\item{ind}{(\code{integer}) indentation for the outputs of class \code{VTableTree}.} } \value{ -original \code{TableTree} or a null report if no observation are found in the table. +the \code{tlg} object or a \code{NULL} report if the \code{tlg} is \code{NULL}, is a \code{TableTree} with 0 rows, is a \code{listing_df} +with 0 rows or is a \code{list} with 0 elements. } \description{ -Create a Null Report +Creates \code{NULL} Report +} +\examples{ +report_null(NULL) } \keyword{datasets} diff --git a/man/std_postprocess.Rd b/man/std_postprocess.Rd index ead1d57ecf..f7032f9792 100644 --- a/man/std_postprocess.Rd +++ b/man/std_postprocess.Rd @@ -1,29 +1,21 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R +% Please edit documentation in R/report_null.R \name{std_postprocess} \alias{std_postprocess} -\title{Standard post processing} +\title{Standard Post Processing} \usage{ std_postprocess(tlg, ind = 2L, ...) } \arguments{ -\item{tlg}{(\code{TableTree}) object.} +\item{tlg}{to convert to null report.} -\item{ind}{(\code{integer}) the indentation of the table.} +\item{ind}{(\code{integer}) indentation for the outputs of class \code{VTableTree}.} -\item{...}{not used at the moment.} +\item{...}{not used.} } \value{ -a post-processed \code{tlg}. +a post processed \code{tlg} or a \code{NULL} report. } \description{ -Standard post processing +Standard Post Processing } -\note{ -Standard post processing includes: -\itemize{ -\item \code{NULL} report creation if necessary -\item indentation -} -} -\keyword{internal} diff --git a/tests/testthat/test-default_tlg.R b/tests/testthat/test-default_tlg.R index adc4d718dc..2b39b7c659 100644 --- a/tests/testthat/test-default_tlg.R +++ b/tests/testthat/test-default_tlg.R @@ -1,7 +1,7 @@ test_that("ael01_nollt function with default argument value return expected result with test data", { pre_data <- ael01_nollt_pre(syn_data) raw_res <- ael01_nollt_main(pre_data) - res <- ael01_nollt_post(raw_res) + res <- std_postprocess(raw_res) expect_snapshot(cat(export_as_txt(res, lpp = 100))) }) diff --git a/tests/testthat/test-empty_report.R b/tests/testthat/test-empty_report.R index cf5b018526..03176b11ea 100644 --- a/tests/testthat/test-empty_report.R +++ b/tests/testthat/test-empty_report.R @@ -11,11 +11,11 @@ test_that("tlg functions return null reports when domain table is empty", { rrow("", "Null Report: No observations met the reporting criteria for inclusion in this output.") ) + rtables::table_inset(empty_report) <- 2L + res <- run(ael01_nollt, dat_empty) expect_identical(res, empty_report) - rtables::table_inset(empty_report) <- 2L - res <- run(aet01, dat_empty, prune_0 = TRUE) expect_identical(res, empty_report) From 78c64562dfa8a0d0f53bfe205201b88431e00e26 Mon Sep 17 00:00:00 2001 From: BFalquet Date: Wed, 19 Jun 2024 11:09:12 +0200 Subject: [PATCH 2/7] remove std_posprocessing --- NAMESPACE | 1 - NEWS.md | 2 +- R/aet01.R | 2 +- R/aet01_aesi.R | 2 +- R/aet02.R | 2 +- R/aet03.R | 2 +- R/aet04.R | 2 +- R/aet05.R | 2 +- R/aet10.R | 2 +- R/cfbt01.R | 2 +- R/chevron_tlg-S4class.R | 6 ++-- R/cmt01a.R | 2 +- R/coxt01.R | 2 +- R/dmt01.R | 2 +- R/dst01.R | 2 +- R/dtht01.R | 2 +- R/egt02.R | 2 +- R/egt03.R | 2 +- R/egt05_qtcat.R | 2 +- R/ext01.R | 2 +- R/lbt04.R | 2 +- R/lbt05.R | 2 +- R/lbt06.R | 2 +- R/lbt07.R | 2 +- R/lbt14.R | 2 +- R/mht01.R | 2 +- R/pdt01.R | 2 +- R/pdt02.R | 2 +- R/report_null.R | 18 +----------- R/rmpt01.R | 2 +- R/rmpt06.R | 2 +- R/rspt01.R | 2 +- R/ttet01.R | 2 +- R/vst02.R | 2 +- _pkgdown.yaml | 1 - man/chevron_tlg-class.Rd | 6 ++-- man/report_null.Rd | 2 +- man/std_postprocess.Rd | 21 ------------- tests/testthat/_snaps/lbt06.md | 2 +- tests/testthat/test-default_tlg.R | 2 +- tests/testthat/test-lbt06.R | 4 +-- tests/testthat/test-report_null.R | 49 +++++++++++++++++++++++++++++++ 42 files changed, 92 insertions(+), 82 deletions(-) delete mode 100644 man/std_postprocess.Rd create mode 100644 tests/testthat/test-report_null.R diff --git a/NAMESPACE b/NAMESPACE index cd00e518ff..2f3941f88f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -209,7 +209,6 @@ export(rspt01_pre) export(run) export(script_funs) export(set_section_div) -export(std_postprocess) export(ttet01) export(ttet01_main) export(ttet01_post) diff --git a/NEWS.md b/NEWS.md index be745211e3..2681da8f76 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,7 @@ * Add `AEL02`, `AEL03` templates. * Modify the post processing of `MHT01` to allow multiple `row_split_var`. -* Export the `std_postprocessing` function to simplify the post processing. +* Improve the `report_null` to facilitate the creation of null report. # chevron 0.2.6 diff --git a/R/aet01.R b/R/aet01.R index 87c84635e5..c282b87329 100644 --- a/R/aet01.R +++ b/R/aet01.R @@ -171,7 +171,7 @@ aet01_post <- function(tlg, prune_0 = FALSE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - std_postprocess(tlg) + report_null(tlg) } #' `AET01` Table 1 (Default) Overview of Deaths and Adverse Events Summary Table 1. diff --git a/R/aet01_aesi.R b/R/aet01_aesi.R index 3bf12c911e..884354ea5d 100644 --- a/R/aet01_aesi.R +++ b/R/aet01_aesi.R @@ -213,7 +213,7 @@ aet01_aesi_post <- function(tlg, prune_0 = FALSE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - std_postprocess(tlg) + report_null(tlg) } #' `AET01_AESI` Table 1 (Default) Adverse Event of Special Interest Summary Table. diff --git a/R/aet02.R b/R/aet02.R index daa801566e..f25eb6e997 100644 --- a/R/aet02.R +++ b/R/aet02.R @@ -105,7 +105,7 @@ aet02_post <- function(tlg, row_split_var = "AEBODSYS", prune_0 = TRUE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - std_postprocess(tlg) + report_null(tlg) } #' `AET02` Table 1 (Default) Adverse Events by System Organ Class and Preferred Term Table 1. diff --git a/R/aet03.R b/R/aet03.R index 194b47fb4d..cea3001485 100644 --- a/R/aet03.R +++ b/R/aet03.R @@ -138,7 +138,7 @@ aet03_post <- function(tlg, prune_0 = TRUE, ...) { scorefun = cont_n_allcols ) if (prune_0) tlg <- trim_rows(tlg) - std_postprocess(tlg) + report_null(tlg) } #' `AET03` Table 1 (Default) Advert Events by Greatest Intensity Table 1. diff --git a/R/aet04.R b/R/aet04.R index 9f67fe2b16..e75c1e1f08 100644 --- a/R/aet04.R +++ b/R/aet04.R @@ -156,7 +156,7 @@ aet04_post <- function(tlg, prune_0 = TRUE, ...) { tlg <- tlg %>% tlg_sort_by_vars(c("AEBODSYS", "AEDECOD"), score_all_sum, decreasing = TRUE) if (prune_0) tlg <- trim_rows(tlg) - std_postprocess(tlg) + report_null(tlg) } #' `AET04` Table 1 (Default) Adverse Events by Highest `NCI` `CTACAE` `AE` Grade Table 1. diff --git a/R/aet05.R b/R/aet05.R index 6f19184b52..7656755e00 100644 --- a/R/aet05.R +++ b/R/aet05.R @@ -115,7 +115,7 @@ aet05_post <- function(tlg, prune_0 = FALSE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - std_postprocess(tlg) + report_null(tlg) } #' `AET05` Table 1 (Default) Adverse Event Rate Adjusted for Patient-Years at Risk - First Occurrence. diff --git a/R/aet10.R b/R/aet10.R index fa53f7427d..7180844d1f 100644 --- a/R/aet10.R +++ b/R/aet10.R @@ -99,7 +99,7 @@ aet10_post <- function(tlg, atleast = 0.05, ...) { ) ) - std_postprocess(tlg_prune) + report_null(tlg_prune) } #' `AET10` Table 1 (Default) Most Common (xx%) Adverse Events Preferred Terms Table 1. diff --git a/R/cfbt01.R b/R/cfbt01.R index f963239ad0..6d2ec5e1c6 100644 --- a/R/cfbt01.R +++ b/R/cfbt01.R @@ -204,7 +204,7 @@ cfbt01_post <- function(tlg, prune_0 = TRUE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - std_postprocess(tlg) + report_null(tlg) } #' `CFBT01` Change from Baseline By Visit Table. diff --git a/R/chevron_tlg-S4class.R b/R/chevron_tlg-S4class.R index ac02566e49..4a26fbdb8b 100644 --- a/R/chevron_tlg-S4class.R +++ b/R/chevron_tlg-S4class.R @@ -142,7 +142,7 @@ methods::setValidity("chevron_simple", function(object) { #' chevron_t <- function(main = function(adam_db, ...) build_table(basic_table(), adam_db[[1]]), preprocess = function(adam_db, ...) adam_db, - postprocess = std_postprocess, + postprocess = report_null, ...) { res <- .chevron_t( main = main, @@ -167,7 +167,7 @@ chevron_t <- function(main = function(adam_db, ...) build_table(basic_table(), a #' chevron_l <- function(main = function(adam_db, ...) data.frame(), preprocess = function(adam_db, ...) adam_db, - postprocess = std_postprocess, + postprocess = report_null, ...) { res <- .chevron_l( main = main, @@ -196,7 +196,7 @@ chevron_l <- function(main = function(adam_db, ...) data.frame(), #' chevron_g <- function(main = function(adam_db, ...) ggplot2::ggplot(), preprocess = function(adam_db, ...) adam_db, - postprocess = std_postprocess, + postprocess = report_null, ...) { res <- .chevron_g( main = main, diff --git a/R/cmt01a.R b/R/cmt01a.R index 5b7673aa05..06870f9220 100644 --- a/R/cmt01a.R +++ b/R/cmt01a.R @@ -122,7 +122,7 @@ cmt01a_post <- function( if (prune_0) { tlg <- smart_prune(tlg) } - std_postprocess(tlg) + report_null(tlg) } #' `CMT01A` Concomitant Medication by Medication Class and Preferred Name. diff --git a/R/coxt01.R b/R/coxt01.R index 153f1b293e..03ac491a63 100644 --- a/R/coxt01.R +++ b/R/coxt01.R @@ -129,7 +129,7 @@ coxt01_post <- function(tlg, prune_0 = FALSE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - std_postprocess(tlg) + report_null(tlg) } #' `COXT01` (Default) Cox Regression Model Table. diff --git a/R/dmt01.R b/R/dmt01.R index 48e8cd5617..91699c0a02 100644 --- a/R/dmt01.R +++ b/R/dmt01.R @@ -115,7 +115,7 @@ dmt01_post <- function(tlg, prune_0 = TRUE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - std_postprocess(tlg) + report_null(tlg) } #' `DMT01` Table 1 (Default) Demographics and Baseline Characteristics Table 1. diff --git a/R/dst01.R b/R/dst01.R index b87b6a4f49..cfbec26815 100755 --- a/R/dst01.R +++ b/R/dst01.R @@ -170,7 +170,7 @@ dst01_post <- function(tlg, prune_0 = TRUE, ...) { tlg <- tlg %>% smart_prune() } - std_postprocess(tlg) + report_null(tlg) } #' DST01 Table 1 (Default) Patient Disposition Table 1. diff --git a/R/dtht01.R b/R/dtht01.R index 7ccc1b5ca1..22d7659b9c 100755 --- a/R/dtht01.R +++ b/R/dtht01.R @@ -180,7 +180,7 @@ dtht01_post <- function(tlg, prune_0 = TRUE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - std_postprocess(tlg) + report_null(tlg) } #' `DTHT01` Table 1 (Default) Death Table. diff --git a/R/egt02.R b/R/egt02.R index e687659989..d1c7d58e26 100644 --- a/R/egt02.R +++ b/R/egt02.R @@ -97,7 +97,7 @@ egt02_pre <- function(adam_db, ...) { #' @export #' egt02_post <- function(tlg, ...) { - std_postprocess(tlg) + report_null(tlg) } #' `EGT02` ECG Abnormalities Table. diff --git a/R/egt03.R b/R/egt03.R index 03c9be000e..a7b2ea6f1a 100755 --- a/R/egt03.R +++ b/R/egt03.R @@ -156,7 +156,7 @@ egt03_pre <- function(adam_db, ...) { egt03_post <- function(tlg, prune_0 = FALSE, ...) { if (prune_0) tlg <- smart_prune(tlg) - std_postprocess(tlg) + report_null(tlg) } #' `EGT03` Shift Table of ECG Interval Data - Baseline versus Minimum or Maximum Post-Baseline. diff --git a/R/egt05_qtcat.R b/R/egt05_qtcat.R index c2d3f31833..b31b81f4c7 100644 --- a/R/egt05_qtcat.R +++ b/R/egt05_qtcat.R @@ -160,7 +160,7 @@ egt05_qtcat_pre <- function(adam_db, ...) { #' egt05_qtcat_post <- function(tlg, prune_0 = TRUE, ...) { if (prune_0) tlg <- smart_prune(tlg) - std_postprocess(tlg) + report_null(tlg) } #' `EGT05_QTCAT` ECG Actual Values and Changes from Baseline by Visit Table. diff --git a/R/ext01.R b/R/ext01.R index a58b2296b9..dcce77c6c0 100755 --- a/R/ext01.R +++ b/R/ext01.R @@ -135,7 +135,7 @@ ext01_pre <- function(adam_db, #' ext01_post <- function(tlg, prune_0 = TRUE, ...) { if (prune_0) tlg <- smart_prune(tlg) - std_postprocess(tlg) + report_null(tlg) } #' `EXT01` Exposure Summary Table. diff --git a/R/lbt04.R b/R/lbt04.R index 084d427299..81e78e2b2b 100644 --- a/R/lbt04.R +++ b/R/lbt04.R @@ -163,7 +163,7 @@ lbt04_pre <- function(adam_db, ...) { #' @export #' lbt04_post <- function(tlg, ...) { - std_postprocess(tlg) + report_null(tlg) } #' `LBT04` Laboratory Abnormalities Not Present at Baseline Table. diff --git a/R/lbt05.R b/R/lbt05.R index 4a03a3e757..097f2aa4c0 100755 --- a/R/lbt05.R +++ b/R/lbt05.R @@ -130,7 +130,7 @@ lbt05_post <- function(tlg, prune_0 = FALSE, ...) { } } - std_postprocess(tlg) + report_null(tlg) } #' `LBT05` Table 1 (Default) Laboratory Abnormalities with Single and Replicated Marked. diff --git a/R/lbt06.R b/R/lbt06.R index eb51e1e352..8f61b3d7ab 100644 --- a/R/lbt06.R +++ b/R/lbt06.R @@ -141,7 +141,7 @@ lbt06_post <- function(tlg, prune_0 = FALSE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - std_postprocess(tlg) + report_null(tlg) } #' `LBT06` Table 1 (Default) Laboratory Abnormalities by Visit and Baseline Status Table 1. diff --git a/R/lbt07.R b/R/lbt07.R index dc35759cf0..3454f29a5d 100755 --- a/R/lbt07.R +++ b/R/lbt07.R @@ -166,7 +166,7 @@ lbt07_post <- function(tlg, prune_0 = TRUE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - std_postprocess(tlg) + report_null(tlg) } #' `LBT07` Table 1 (Default) Laboratory Test Results and Change from Baseline by Visit. diff --git a/R/lbt14.R b/R/lbt14.R index 4924500b55..03b40f22ba 100755 --- a/R/lbt14.R +++ b/R/lbt14.R @@ -138,7 +138,7 @@ lbt14_pre <- function(adam_db, #' lbt14_post <- function(tlg, prune_0 = TRUE, ...) { if (prune_0) tlg <- tlg %>% trim_rows() - std_postprocess(tlg) + report_null(tlg) } #' `LBT14` Laboratory Test Results Shift Table – Highest `NCI-CTCAE` Grade Post-Baseline by diff --git a/R/mht01.R b/R/mht01.R index 7cbe7540c3..5649be3c41 100644 --- a/R/mht01.R +++ b/R/mht01.R @@ -118,7 +118,7 @@ mht01_post <- function(tlg, row_split_var = "MHBODSYS", prune_0 = TRUE, ...) { scorefun = score_occurrences ) - std_postprocess(tbl_sorted) + report_null(tbl_sorted) } #' `MHT01` Medical History Table. diff --git a/R/pdt01.R b/R/pdt01.R index 7672e598e0..13a2155ef6 100755 --- a/R/pdt01.R +++ b/R/pdt01.R @@ -131,7 +131,7 @@ pdt01_post <- function(tlg, prune_0 = TRUE, dvcode_var = "DVDECOD", dvterm_var = scorefun = score_occurrences ) - std_postprocess(tbl_sorted) + report_null(tbl_sorted) } #' `pdt01` Major Protocol Deviations Table. diff --git a/R/pdt02.R b/R/pdt02.R index acf7e7ed78..f8700e0fb5 100755 --- a/R/pdt02.R +++ b/R/pdt02.R @@ -139,7 +139,7 @@ pdt02_post <- function(tlg, prune_0 = TRUE, dvreas_var = "DVREAS", dvterm_var = scorefun = score_occurrences ) - std_postprocess(tbl_sorted) + report_null(tbl_sorted) } #' `pdt02` Major Protocol Deviations Related to Epidemic/Pandemic Table. diff --git a/R/report_null.R b/R/report_null.R index 6e7f968ac2..107f4e4042 100644 --- a/R/report_null.R +++ b/R/report_null.R @@ -48,7 +48,7 @@ setMethod("report_null", "listing_df", function(tlg, ind = 2L, ...) { }) #' @rdname report_null -setMethod("report_null", "list", function(tlg, ...) { +setMethod("report_null", "list", function(tlg, ind = 2L, ...) { if (length(tlg) == 0) { res <- null_report table_inset(res) <- ind @@ -69,19 +69,3 @@ null_report <- rtables::rtable( header = "", rrow("", "Null Report: No observations met the reporting criteria for inclusion in this output.") ) - -#' Standard Post Processing -#' -#' @param tlg to convert to null report. -#' @param ind (`integer`) indentation for the outputs of class `VTableTree`. -#' @param ... not used. -#' -#' @export -#' @returns a post processed `tlg` or a `NULL` report. -#' -std_postprocess <- function(tlg, ind = 2L, ...) { - assert_int(ind, lower = 0L) - - res <- report_null(tlg, ind = ind) - res -} diff --git a/R/rmpt01.R b/R/rmpt01.R index 64a935e51d..41acd84da7 100644 --- a/R/rmpt01.R +++ b/R/rmpt01.R @@ -131,7 +131,7 @@ rmpt01_post <- function(tlg, prune_0 = FALSE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - std_postprocess(tlg) + report_null(tlg) } #' `RMPT01`Duration of Exposure for Risk Management Plan Table. diff --git a/R/rmpt06.R b/R/rmpt06.R index feda7163b7..f153e0851e 100644 --- a/R/rmpt06.R +++ b/R/rmpt06.R @@ -210,7 +210,7 @@ rmpt06_post <- function(tlg, prune_0 = FALSE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - std_postprocess(tlg) + report_null(tlg) } #' `RMPT06` Table 1 (Default) Seriousness, Outcomes, Severity, Frequency with 95% CI for Risk Management Plan. diff --git a/R/rspt01.R b/R/rspt01.R index 78ef8899b9..b1a2648a73 100644 --- a/R/rspt01.R +++ b/R/rspt01.R @@ -156,7 +156,7 @@ rspt01_post <- function(tlg, prune_0 = TRUE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - std_postprocess(tlg) + report_null(tlg) } #' `RSPT01` Binary Outcomes Summary. diff --git a/R/ttet01.R b/R/ttet01.R index 46b83d2444..a2c22c5b3b 100644 --- a/R/ttet01.R +++ b/R/ttet01.R @@ -202,7 +202,7 @@ ttet01_post <- function(tlg, prune_0 = TRUE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - std_postprocess(tlg) + report_null(tlg) } #' `TTET01` Binary Outcomes Summary. diff --git a/R/vst02.R b/R/vst02.R index 0104d27971..9a8cf7e2ef 100644 --- a/R/vst02.R +++ b/R/vst02.R @@ -108,7 +108,7 @@ vst02_post <- function(tlg, prune_0 = FALSE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - std_postprocess(tlg) + report_null(tlg) } #' `VST02` Vital Sign Abnormalities Table. diff --git a/_pkgdown.yaml b/_pkgdown.yaml index 802d337b1d..6f1892c2a6 100644 --- a/_pkgdown.yaml +++ b/_pkgdown.yaml @@ -115,7 +115,6 @@ reference: - assert_valid_variable - create_id_listings - report_null - - std_postprocessing - smart_prune - var_labels_for - format_date diff --git a/man/chevron_tlg-class.Rd b/man/chevron_tlg-class.Rd index 16682e133c..c06f16158b 100644 --- a/man/chevron_tlg-class.Rd +++ b/man/chevron_tlg-class.Rd @@ -24,21 +24,21 @@ chevron_t( main = function(adam_db, ...) build_table(basic_table(), adam_db[[1]]), preprocess = function(adam_db, ...) adam_db, - postprocess = std_postprocess, + postprocess = report_null, ... ) chevron_l( main = function(adam_db, ...) data.frame(), preprocess = function(adam_db, ...) adam_db, - postprocess = std_postprocess, + postprocess = report_null, ... ) chevron_g( main = function(adam_db, ...) ggplot2::ggplot(), preprocess = function(adam_db, ...) adam_db, - postprocess = std_postprocess, + postprocess = report_null, ... ) diff --git a/man/report_null.Rd b/man/report_null.Rd index 4785f88dca..d7cb121a6c 100644 --- a/man/report_null.Rd +++ b/man/report_null.Rd @@ -22,7 +22,7 @@ report_null(tlg, ...) \S4method{report_null}{listing_df}(tlg, ind = 2L, ...) -\S4method{report_null}{list}(tlg, ...) +\S4method{report_null}{list}(tlg, ind = 2L, ...) \S4method{report_null}{ANY}(tlg, ...) diff --git a/man/std_postprocess.Rd b/man/std_postprocess.Rd deleted file mode 100644 index f7032f9792..0000000000 --- a/man/std_postprocess.Rd +++ /dev/null @@ -1,21 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/report_null.R -\name{std_postprocess} -\alias{std_postprocess} -\title{Standard Post Processing} -\usage{ -std_postprocess(tlg, ind = 2L, ...) -} -\arguments{ -\item{tlg}{to convert to null report.} - -\item{ind}{(\code{integer}) indentation for the outputs of class \code{VTableTree}.} - -\item{...}{not used.} -} -\value{ -a post processed \code{tlg} or a \code{NULL} report. -} -\description{ -Standard Post Processing -} diff --git a/tests/testthat/_snaps/lbt06.md b/tests/testthat/_snaps/lbt06.md index 261e4fa475..cb3f75be2f 100644 --- a/tests/testthat/_snaps/lbt06.md +++ b/tests/testthat/_snaps/lbt06.md @@ -1,7 +1,7 @@ # lbt06 can handle some NA values Code - cat(export_as_txt(std_postprocess(res), lpp = 100)) + cat(export_as_txt(res, lpp = 100)) Output Parameter: Alanine Aminotransferase Measurement diff --git a/tests/testthat/test-default_tlg.R b/tests/testthat/test-default_tlg.R index 2b39b7c659..f2d4af2347 100644 --- a/tests/testthat/test-default_tlg.R +++ b/tests/testthat/test-default_tlg.R @@ -1,7 +1,7 @@ test_that("ael01_nollt function with default argument value return expected result with test data", { pre_data <- ael01_nollt_pre(syn_data) raw_res <- ael01_nollt_main(pre_data) - res <- std_postprocess(raw_res) + res <- report_null(raw_res) expect_snapshot(cat(export_as_txt(res, lpp = 100))) }) diff --git a/tests/testthat/test-lbt06.R b/tests/testthat/test-lbt06.R index 3f8f11fab3..42ef2270d3 100644 --- a/tests/testthat/test-lbt06.R +++ b/tests/testthat/test-lbt06.R @@ -16,8 +16,8 @@ test_that("lbt06 can handle some NA values", { proc_data$adlb[1:4, c("ANRIND", "BNRIND")] <- NA df_pre <- lbt06_pre(proc_data) tlg <- lbt06_main(df_pre) - res <- smart_prune(tlg) - expect_snapshot(cat(export_as_txt(std_postprocess(res), lpp = 100))) + res <- lbt06_post(tlg, prune_0 = TRUE) + expect_snapshot(cat(export_as_txt(res, lpp = 100))) }) test_that("lbt06 fails on incomplete data", { diff --git a/tests/testthat/test-report_null.R b/tests/testthat/test-report_null.R new file mode 100644 index 0000000000..cd009a5093 --- /dev/null +++ b/tests/testthat/test-report_null.R @@ -0,0 +1,49 @@ +# report_null ---- + +test_that("report_null works as expected with `NULL`", { + expect_silent(res <- report_null(NULL)) + rep <- null_report + rtables::table_inset(rep) <- 2L + expect_identical(res, rep) +}) + +test_that("report_null works as expected with `VTableTree`", { + + lyt <- basic_table() %>% analyze("Species") + tab <- build_table(lyt, iris) + rtables::table_inset(tab) <- 2L + expect_identical(tab, report_null(tab)) + + tab <- build_table(basic_table(), data.frame()) + expect_silent(res <- report_null(tab)) + rep <- null_report + rtables::table_inset(rep) <- 2L + expect_identical(res, rep) +}) + +test_that("report_null works as expected with `listing_df`", { + lst <- rlistings::as_listing(iris, "Species", "Sepal.Length") + expect_identical(lst, report_null(lst)) + + lst <- rlistings::as_listing(iris[NULL, ], "Species", "Sepal.Length") + expect_silent(lst <- report_null(lst)) + rep <- null_report + rtables::table_inset(rep) <- 2L + expect_identical(lst, rep) +}) + +test_that("report_null works as expected with `list`", { + lst <- rlistings::as_listing(iris, "Species", "Sepal.Length", split_into_pages_by_var = "Species") + expect_identical(lst, report_null(lst)) + + lst <- rlistings::as_listing(iris[NULL, ], "Species", "Sepal.Length", split_into_pages_by_var = "Species") + expect_silent(lst <- report_null(lst)) + rep <- null_report + rtables::table_inset(rep) <- 2L + expect_identical(lst, rep) +}) + +test_that("report_null works as expected with by default", { + expect_silent(int <- report_null(1L)) + expect_identical(int, 1L) +}) From d2eda97f2565a0563ad272c981ff207aceb941bd Mon Sep 17 00:00:00 2001 From: BFalquet Date: Wed, 19 Jun 2024 14:11:26 +0200 Subject: [PATCH 3/7] styler --- tests/testthat/test-report_null.R | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testthat/test-report_null.R b/tests/testthat/test-report_null.R index cd009a5093..72f85a141b 100644 --- a/tests/testthat/test-report_null.R +++ b/tests/testthat/test-report_null.R @@ -8,7 +8,6 @@ test_that("report_null works as expected with `NULL`", { }) test_that("report_null works as expected with `VTableTree`", { - lyt <- basic_table() %>% analyze("Species") tab <- build_table(lyt, iris) rtables::table_inset(tab) <- 2L From 7be8252db2f9ac5c8aed9f5438dd0e0247b8aa15 Mon Sep 17 00:00:00 2001 From: b_falquet <64274616+BFalquet@users.noreply.github.com> Date: Thu, 20 Jun 2024 15:04:08 +0200 Subject: [PATCH 4/7] Apply suggestions from code review reviewer's suggestion Co-authored-by: Davide Garolini Signed-off-by: b_falquet <64274616+BFalquet@users.noreply.github.com> --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 2681da8f76..e948bc6b3b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,7 @@ * Add `AEL02`, `AEL03` templates. * Modify the post processing of `MHT01` to allow multiple `row_split_var`. -* Improve the `report_null` to facilitate the creation of null report. +* Improve the `report_null` to facilitate the creation of null reports. # chevron 0.2.6 From 6beca6899327715147e1c8b989a4ac119cec5436 Mon Sep 17 00:00:00 2001 From: BFalquet Date: Thu, 20 Jun 2024 15:43:31 +0200 Subject: [PATCH 5/7] add inset in null report --- R/report_null.R | 3 ++- tests/testthat/test-report_null.R | 18 +++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/R/report_null.R b/R/report_null.R index 107f4e4042..e672ab26b1 100644 --- a/R/report_null.R +++ b/R/report_null.R @@ -67,5 +67,6 @@ setMethod("report_null", "ANY", function(tlg, ...) { #' @rdname report_null null_report <- rtables::rtable( header = "", - rrow("", "Null Report: No observations met the reporting criteria for inclusion in this output.") + rrow("", "Null Report: No observations met the reporting criteria for inclusion in this output."), + inset = 2L ) diff --git a/tests/testthat/test-report_null.R b/tests/testthat/test-report_null.R index 72f85a141b..f55e935e0e 100644 --- a/tests/testthat/test-report_null.R +++ b/tests/testthat/test-report_null.R @@ -2,9 +2,7 @@ test_that("report_null works as expected with `NULL`", { expect_silent(res <- report_null(NULL)) - rep <- null_report - rtables::table_inset(rep) <- 2L - expect_identical(res, rep) + expect_identical(res, null_report) }) test_that("report_null works as expected with `VTableTree`", { @@ -15,9 +13,7 @@ test_that("report_null works as expected with `VTableTree`", { tab <- build_table(basic_table(), data.frame()) expect_silent(res <- report_null(tab)) - rep <- null_report - rtables::table_inset(rep) <- 2L - expect_identical(res, rep) + expect_identical(res, null_report) }) test_that("report_null works as expected with `listing_df`", { @@ -26,9 +22,7 @@ test_that("report_null works as expected with `listing_df`", { lst <- rlistings::as_listing(iris[NULL, ], "Species", "Sepal.Length") expect_silent(lst <- report_null(lst)) - rep <- null_report - rtables::table_inset(rep) <- 2L - expect_identical(lst, rep) + expect_identical(lst, null_report) }) test_that("report_null works as expected with `list`", { @@ -36,10 +30,8 @@ test_that("report_null works as expected with `list`", { expect_identical(lst, report_null(lst)) lst <- rlistings::as_listing(iris[NULL, ], "Species", "Sepal.Length", split_into_pages_by_var = "Species") - expect_silent(lst <- report_null(lst)) - rep <- null_report - rtables::table_inset(rep) <- 2L - expect_identical(lst, rep) + lst <- report_null(lst) + expect_identical(lst, null_report) }) test_that("report_null works as expected with by default", { From 22841cb66fac67a37ad6bca5dd8bc3178a09be57 Mon Sep 17 00:00:00 2001 From: BFalquet Date: Fri, 21 Jun 2024 14:32:14 +0200 Subject: [PATCH 6/7] reintroduce std_postprocessing --- NAMESPACE | 1 + NEWS.md | 3 ++- R/aet01.R | 2 +- R/aet01_aesi.R | 2 +- R/aet02.R | 2 +- R/aet03.R | 2 +- R/aet04.R | 2 +- R/aet05.R | 2 +- R/aet10.R | 2 +- R/cfbt01.R | 2 +- R/chevron_tlg-S4class.R | 6 +++--- R/cmt01a.R | 2 +- R/coxt01.R | 2 +- R/dmt01.R | 2 +- R/dst01.R | 2 +- R/dtht01.R | 2 +- R/egt02.R | 2 +- R/egt03.R | 2 +- R/egt05_qtcat.R | 2 +- R/ext01.R | 2 +- R/lbt04.R | 2 +- R/lbt05.R | 2 +- R/lbt06.R | 2 +- R/lbt07.R | 2 +- R/lbt14.R | 2 +- R/mht01.R | 2 +- R/pdt01.R | 2 +- R/pdt02.R | 2 +- R/report_null.R | 17 +++++++++++++++++ R/rmpt01.R | 2 +- R/rmpt06.R | 2 +- R/rspt01.R | 2 +- R/ttet01.R | 2 +- R/vst02.R | 2 +- _pkgdown.yaml | 1 + man/chevron_tlg-class.Rd | 6 +++--- man/std_postprocessing.Rd | 24 ++++++++++++++++++++++++ tests/testthat/test-default_tlg.R | 2 +- 38 files changed, 82 insertions(+), 38 deletions(-) create mode 100644 man/std_postprocessing.Rd diff --git a/NAMESPACE b/NAMESPACE index 2f3941f88f..811ca51bf6 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -209,6 +209,7 @@ export(rspt01_pre) export(run) export(script_funs) export(set_section_div) +export(std_postprocessing) export(ttet01) export(ttet01_main) export(ttet01_post) diff --git a/NEWS.md b/NEWS.md index e948bc6b3b..9790c112f4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,8 @@ * Add `AEL02`, `AEL03` templates. * Modify the post processing of `MHT01` to allow multiple `row_split_var`. -* Improve the `report_null` to facilitate the creation of null reports. +* Improve the `report_null` method to facilitate the creation of null reports +* Export the `std_postprocessing` function to simplify post processing logic. # chevron 0.2.6 diff --git a/R/aet01.R b/R/aet01.R index c282b87329..840150fc74 100644 --- a/R/aet01.R +++ b/R/aet01.R @@ -171,7 +171,7 @@ aet01_post <- function(tlg, prune_0 = FALSE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - report_null(tlg) + std_postprocessing(tlg) } #' `AET01` Table 1 (Default) Overview of Deaths and Adverse Events Summary Table 1. diff --git a/R/aet01_aesi.R b/R/aet01_aesi.R index 884354ea5d..25777c9eb6 100644 --- a/R/aet01_aesi.R +++ b/R/aet01_aesi.R @@ -213,7 +213,7 @@ aet01_aesi_post <- function(tlg, prune_0 = FALSE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - report_null(tlg) + std_postprocessing(tlg) } #' `AET01_AESI` Table 1 (Default) Adverse Event of Special Interest Summary Table. diff --git a/R/aet02.R b/R/aet02.R index f25eb6e997..0dc2f1e96b 100644 --- a/R/aet02.R +++ b/R/aet02.R @@ -105,7 +105,7 @@ aet02_post <- function(tlg, row_split_var = "AEBODSYS", prune_0 = TRUE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - report_null(tlg) + std_postprocessing(tlg) } #' `AET02` Table 1 (Default) Adverse Events by System Organ Class and Preferred Term Table 1. diff --git a/R/aet03.R b/R/aet03.R index cea3001485..4d9a63d231 100644 --- a/R/aet03.R +++ b/R/aet03.R @@ -138,7 +138,7 @@ aet03_post <- function(tlg, prune_0 = TRUE, ...) { scorefun = cont_n_allcols ) if (prune_0) tlg <- trim_rows(tlg) - report_null(tlg) + std_postprocessing(tlg) } #' `AET03` Table 1 (Default) Advert Events by Greatest Intensity Table 1. diff --git a/R/aet04.R b/R/aet04.R index e75c1e1f08..9c0f1805a0 100644 --- a/R/aet04.R +++ b/R/aet04.R @@ -156,7 +156,7 @@ aet04_post <- function(tlg, prune_0 = TRUE, ...) { tlg <- tlg %>% tlg_sort_by_vars(c("AEBODSYS", "AEDECOD"), score_all_sum, decreasing = TRUE) if (prune_0) tlg <- trim_rows(tlg) - report_null(tlg) + std_postprocessing(tlg) } #' `AET04` Table 1 (Default) Adverse Events by Highest `NCI` `CTACAE` `AE` Grade Table 1. diff --git a/R/aet05.R b/R/aet05.R index 7656755e00..21c6597748 100644 --- a/R/aet05.R +++ b/R/aet05.R @@ -115,7 +115,7 @@ aet05_post <- function(tlg, prune_0 = FALSE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - report_null(tlg) + std_postprocessing(tlg) } #' `AET05` Table 1 (Default) Adverse Event Rate Adjusted for Patient-Years at Risk - First Occurrence. diff --git a/R/aet10.R b/R/aet10.R index 7180844d1f..ab201c6586 100644 --- a/R/aet10.R +++ b/R/aet10.R @@ -99,7 +99,7 @@ aet10_post <- function(tlg, atleast = 0.05, ...) { ) ) - report_null(tlg_prune) + std_postprocessing(tlg_prune) } #' `AET10` Table 1 (Default) Most Common (xx%) Adverse Events Preferred Terms Table 1. diff --git a/R/cfbt01.R b/R/cfbt01.R index 6d2ec5e1c6..bd85840db7 100644 --- a/R/cfbt01.R +++ b/R/cfbt01.R @@ -204,7 +204,7 @@ cfbt01_post <- function(tlg, prune_0 = TRUE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - report_null(tlg) + std_postprocessing(tlg) } #' `CFBT01` Change from Baseline By Visit Table. diff --git a/R/chevron_tlg-S4class.R b/R/chevron_tlg-S4class.R index 4a26fbdb8b..29ae6d17de 100644 --- a/R/chevron_tlg-S4class.R +++ b/R/chevron_tlg-S4class.R @@ -142,7 +142,7 @@ methods::setValidity("chevron_simple", function(object) { #' chevron_t <- function(main = function(adam_db, ...) build_table(basic_table(), adam_db[[1]]), preprocess = function(adam_db, ...) adam_db, - postprocess = report_null, + postprocess = std_postprocessing, ...) { res <- .chevron_t( main = main, @@ -167,7 +167,7 @@ chevron_t <- function(main = function(adam_db, ...) build_table(basic_table(), a #' chevron_l <- function(main = function(adam_db, ...) data.frame(), preprocess = function(adam_db, ...) adam_db, - postprocess = report_null, + postprocess = std_postprocessing, ...) { res <- .chevron_l( main = main, @@ -196,7 +196,7 @@ chevron_l <- function(main = function(adam_db, ...) data.frame(), #' chevron_g <- function(main = function(adam_db, ...) ggplot2::ggplot(), preprocess = function(adam_db, ...) adam_db, - postprocess = report_null, + postprocess = std_postprocessing, ...) { res <- .chevron_g( main = main, diff --git a/R/cmt01a.R b/R/cmt01a.R index 06870f9220..7a370647be 100644 --- a/R/cmt01a.R +++ b/R/cmt01a.R @@ -122,7 +122,7 @@ cmt01a_post <- function( if (prune_0) { tlg <- smart_prune(tlg) } - report_null(tlg) + std_postprocessing(tlg) } #' `CMT01A` Concomitant Medication by Medication Class and Preferred Name. diff --git a/R/coxt01.R b/R/coxt01.R index 03ac491a63..53f8e02836 100644 --- a/R/coxt01.R +++ b/R/coxt01.R @@ -129,7 +129,7 @@ coxt01_post <- function(tlg, prune_0 = FALSE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - report_null(tlg) + std_postprocessing(tlg) } #' `COXT01` (Default) Cox Regression Model Table. diff --git a/R/dmt01.R b/R/dmt01.R index 91699c0a02..fdec8c2a70 100644 --- a/R/dmt01.R +++ b/R/dmt01.R @@ -115,7 +115,7 @@ dmt01_post <- function(tlg, prune_0 = TRUE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - report_null(tlg) + std_postprocessing(tlg) } #' `DMT01` Table 1 (Default) Demographics and Baseline Characteristics Table 1. diff --git a/R/dst01.R b/R/dst01.R index cfbec26815..705c8c35f3 100755 --- a/R/dst01.R +++ b/R/dst01.R @@ -170,7 +170,7 @@ dst01_post <- function(tlg, prune_0 = TRUE, ...) { tlg <- tlg %>% smart_prune() } - report_null(tlg) + std_postprocessing(tlg) } #' DST01 Table 1 (Default) Patient Disposition Table 1. diff --git a/R/dtht01.R b/R/dtht01.R index 22d7659b9c..7e07aae0f8 100755 --- a/R/dtht01.R +++ b/R/dtht01.R @@ -180,7 +180,7 @@ dtht01_post <- function(tlg, prune_0 = TRUE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - report_null(tlg) + std_postprocessing(tlg) } #' `DTHT01` Table 1 (Default) Death Table. diff --git a/R/egt02.R b/R/egt02.R index d1c7d58e26..6d9e68bf1c 100644 --- a/R/egt02.R +++ b/R/egt02.R @@ -97,7 +97,7 @@ egt02_pre <- function(adam_db, ...) { #' @export #' egt02_post <- function(tlg, ...) { - report_null(tlg) + std_postprocessing(tlg) } #' `EGT02` ECG Abnormalities Table. diff --git a/R/egt03.R b/R/egt03.R index a7b2ea6f1a..47be18ae46 100755 --- a/R/egt03.R +++ b/R/egt03.R @@ -156,7 +156,7 @@ egt03_pre <- function(adam_db, ...) { egt03_post <- function(tlg, prune_0 = FALSE, ...) { if (prune_0) tlg <- smart_prune(tlg) - report_null(tlg) + std_postprocessing(tlg) } #' `EGT03` Shift Table of ECG Interval Data - Baseline versus Minimum or Maximum Post-Baseline. diff --git a/R/egt05_qtcat.R b/R/egt05_qtcat.R index b31b81f4c7..d9200d271b 100644 --- a/R/egt05_qtcat.R +++ b/R/egt05_qtcat.R @@ -160,7 +160,7 @@ egt05_qtcat_pre <- function(adam_db, ...) { #' egt05_qtcat_post <- function(tlg, prune_0 = TRUE, ...) { if (prune_0) tlg <- smart_prune(tlg) - report_null(tlg) + std_postprocessing(tlg) } #' `EGT05_QTCAT` ECG Actual Values and Changes from Baseline by Visit Table. diff --git a/R/ext01.R b/R/ext01.R index dcce77c6c0..00eac8d0be 100755 --- a/R/ext01.R +++ b/R/ext01.R @@ -135,7 +135,7 @@ ext01_pre <- function(adam_db, #' ext01_post <- function(tlg, prune_0 = TRUE, ...) { if (prune_0) tlg <- smart_prune(tlg) - report_null(tlg) + std_postprocessing(tlg) } #' `EXT01` Exposure Summary Table. diff --git a/R/lbt04.R b/R/lbt04.R index 81e78e2b2b..64197a0261 100644 --- a/R/lbt04.R +++ b/R/lbt04.R @@ -163,7 +163,7 @@ lbt04_pre <- function(adam_db, ...) { #' @export #' lbt04_post <- function(tlg, ...) { - report_null(tlg) + std_postprocessing(tlg) } #' `LBT04` Laboratory Abnormalities Not Present at Baseline Table. diff --git a/R/lbt05.R b/R/lbt05.R index 097f2aa4c0..7c20ff0de1 100755 --- a/R/lbt05.R +++ b/R/lbt05.R @@ -130,7 +130,7 @@ lbt05_post <- function(tlg, prune_0 = FALSE, ...) { } } - report_null(tlg) + std_postprocessing(tlg) } #' `LBT05` Table 1 (Default) Laboratory Abnormalities with Single and Replicated Marked. diff --git a/R/lbt06.R b/R/lbt06.R index 8f61b3d7ab..13728c34a5 100644 --- a/R/lbt06.R +++ b/R/lbt06.R @@ -141,7 +141,7 @@ lbt06_post <- function(tlg, prune_0 = FALSE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - report_null(tlg) + std_postprocessing(tlg) } #' `LBT06` Table 1 (Default) Laboratory Abnormalities by Visit and Baseline Status Table 1. diff --git a/R/lbt07.R b/R/lbt07.R index 3454f29a5d..287f866a05 100755 --- a/R/lbt07.R +++ b/R/lbt07.R @@ -166,7 +166,7 @@ lbt07_post <- function(tlg, prune_0 = TRUE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - report_null(tlg) + std_postprocessing(tlg) } #' `LBT07` Table 1 (Default) Laboratory Test Results and Change from Baseline by Visit. diff --git a/R/lbt14.R b/R/lbt14.R index 03b40f22ba..1c40ca890b 100755 --- a/R/lbt14.R +++ b/R/lbt14.R @@ -138,7 +138,7 @@ lbt14_pre <- function(adam_db, #' lbt14_post <- function(tlg, prune_0 = TRUE, ...) { if (prune_0) tlg <- tlg %>% trim_rows() - report_null(tlg) + std_postprocessing(tlg) } #' `LBT14` Laboratory Test Results Shift Table – Highest `NCI-CTCAE` Grade Post-Baseline by diff --git a/R/mht01.R b/R/mht01.R index 5649be3c41..eb7e9d51b8 100644 --- a/R/mht01.R +++ b/R/mht01.R @@ -118,7 +118,7 @@ mht01_post <- function(tlg, row_split_var = "MHBODSYS", prune_0 = TRUE, ...) { scorefun = score_occurrences ) - report_null(tbl_sorted) + std_postprocessing(tbl_sorted) } #' `MHT01` Medical History Table. diff --git a/R/pdt01.R b/R/pdt01.R index 13a2155ef6..44be416f82 100755 --- a/R/pdt01.R +++ b/R/pdt01.R @@ -131,7 +131,7 @@ pdt01_post <- function(tlg, prune_0 = TRUE, dvcode_var = "DVDECOD", dvterm_var = scorefun = score_occurrences ) - report_null(tbl_sorted) + std_postprocessing(tbl_sorted) } #' `pdt01` Major Protocol Deviations Table. diff --git a/R/pdt02.R b/R/pdt02.R index f8700e0fb5..1f7dbe3759 100755 --- a/R/pdt02.R +++ b/R/pdt02.R @@ -139,7 +139,7 @@ pdt02_post <- function(tlg, prune_0 = TRUE, dvreas_var = "DVREAS", dvterm_var = scorefun = score_occurrences ) - report_null(tbl_sorted) + std_postprocessing(tbl_sorted) } #' `pdt02` Major Protocol Deviations Related to Epidemic/Pandemic Table. diff --git a/R/report_null.R b/R/report_null.R index e672ab26b1..5955f2f1b6 100644 --- a/R/report_null.R +++ b/R/report_null.R @@ -70,3 +70,20 @@ null_report <- rtables::rtable( rrow("", "Null Report: No observations met the reporting criteria for inclusion in this output."), inset = 2L ) + +#' Standard Post Processing +#' +#' @param tlg to post process. +#' @param ... additional arguments passed to [report_null]. +#' +#' @returns a processed `tlg` or a null report. +#' @export +#' @examples +#' library(rtables) +#' std_postprocessing(build_table(basic_table() |> analyze("Species"), iris), ind = 10L) +#' +std_postprocessing <- function(tlg, ...) { + + tlg <- report_null(tlg, ...) + tlg +} diff --git a/R/rmpt01.R b/R/rmpt01.R index 41acd84da7..4a3fd513fe 100644 --- a/R/rmpt01.R +++ b/R/rmpt01.R @@ -131,7 +131,7 @@ rmpt01_post <- function(tlg, prune_0 = FALSE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - report_null(tlg) + std_postprocessing(tlg) } #' `RMPT01`Duration of Exposure for Risk Management Plan Table. diff --git a/R/rmpt06.R b/R/rmpt06.R index f153e0851e..6618882f0d 100644 --- a/R/rmpt06.R +++ b/R/rmpt06.R @@ -210,7 +210,7 @@ rmpt06_post <- function(tlg, prune_0 = FALSE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - report_null(tlg) + std_postprocessing(tlg) } #' `RMPT06` Table 1 (Default) Seriousness, Outcomes, Severity, Frequency with 95% CI for Risk Management Plan. diff --git a/R/rspt01.R b/R/rspt01.R index b1a2648a73..55227293ff 100644 --- a/R/rspt01.R +++ b/R/rspt01.R @@ -156,7 +156,7 @@ rspt01_post <- function(tlg, prune_0 = TRUE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - report_null(tlg) + std_postprocessing(tlg) } #' `RSPT01` Binary Outcomes Summary. diff --git a/R/ttet01.R b/R/ttet01.R index a2c22c5b3b..6f14caf189 100644 --- a/R/ttet01.R +++ b/R/ttet01.R @@ -202,7 +202,7 @@ ttet01_post <- function(tlg, prune_0 = TRUE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - report_null(tlg) + std_postprocessing(tlg) } #' `TTET01` Binary Outcomes Summary. diff --git a/R/vst02.R b/R/vst02.R index 9a8cf7e2ef..b8db19afd1 100644 --- a/R/vst02.R +++ b/R/vst02.R @@ -108,7 +108,7 @@ vst02_post <- function(tlg, prune_0 = FALSE, ...) { if (prune_0) { tlg <- smart_prune(tlg) } - report_null(tlg) + std_postprocessing(tlg) } #' `VST02` Vital Sign Abnormalities Table. diff --git a/_pkgdown.yaml b/_pkgdown.yaml index 6f1892c2a6..802d337b1d 100644 --- a/_pkgdown.yaml +++ b/_pkgdown.yaml @@ -115,6 +115,7 @@ reference: - assert_valid_variable - create_id_listings - report_null + - std_postprocessing - smart_prune - var_labels_for - format_date diff --git a/man/chevron_tlg-class.Rd b/man/chevron_tlg-class.Rd index c06f16158b..9c13d9eaf1 100644 --- a/man/chevron_tlg-class.Rd +++ b/man/chevron_tlg-class.Rd @@ -24,21 +24,21 @@ chevron_t( main = function(adam_db, ...) build_table(basic_table(), adam_db[[1]]), preprocess = function(adam_db, ...) adam_db, - postprocess = report_null, + postprocess = std_postprocessing, ... ) chevron_l( main = function(adam_db, ...) data.frame(), preprocess = function(adam_db, ...) adam_db, - postprocess = report_null, + postprocess = std_postprocessing, ... ) chevron_g( main = function(adam_db, ...) ggplot2::ggplot(), preprocess = function(adam_db, ...) adam_db, - postprocess = report_null, + postprocess = std_postprocessing, ... ) diff --git a/man/std_postprocessing.Rd b/man/std_postprocessing.Rd new file mode 100644 index 0000000000..abdfb8fb1e --- /dev/null +++ b/man/std_postprocessing.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/report_null.R +\name{std_postprocessing} +\alias{std_postprocessing} +\title{Standard Post Processing} +\usage{ +std_postprocessing(tlg, ...) +} +\arguments{ +\item{tlg}{to post process.} + +\item{...}{additional arguments passed to \link{report_null}.} +} +\value{ +a processed \code{tlg} or a null report. +} +\description{ +Standard Post Processing +} +\examples{ +library(rtables) +std_postprocessing(build_table(basic_table() |> analyze("Species"), iris), ind = 10L) + +} diff --git a/tests/testthat/test-default_tlg.R b/tests/testthat/test-default_tlg.R index f2d4af2347..8daf060c94 100644 --- a/tests/testthat/test-default_tlg.R +++ b/tests/testthat/test-default_tlg.R @@ -1,7 +1,7 @@ test_that("ael01_nollt function with default argument value return expected result with test data", { pre_data <- ael01_nollt_pre(syn_data) raw_res <- ael01_nollt_main(pre_data) - res <- report_null(raw_res) + res <- std_postprocessing(raw_res) expect_snapshot(cat(export_as_txt(res, lpp = 100))) }) From 31952bf3468a51da1976f414100c151d74acdb01 Mon Sep 17 00:00:00 2001 From: BFalquet Date: Fri, 21 Jun 2024 15:13:24 +0200 Subject: [PATCH 7/7] styler --- R/report_null.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/report_null.R b/R/report_null.R index 5955f2f1b6..6c087fe40a 100644 --- a/R/report_null.R +++ b/R/report_null.R @@ -83,7 +83,6 @@ null_report <- rtables::rtable( #' std_postprocessing(build_table(basic_table() |> analyze("Species"), iris), ind = 10L) #' std_postprocessing <- function(tlg, ...) { - tlg <- report_null(tlg, ...) tlg }