diff --git a/NEWS.md b/NEWS.md index 8663744533..b61088199b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,7 @@ * Updated `tm_a_mmrm` column name when no treatment is selected from "all obs" to "All Patients". * Added a subtitle to `tm_g_ci` with visit name. * Added subtitles and footnotes to `tm_a_mmrm` tables and plots. +* Added a title and parameter category subtitle to `tm_t_exposure`, cleaned up labels. ### Bug fixes diff --git a/R/tm_t_exposure.R b/R/tm_t_exposure.R index a2b44bac26..6669a0152e 100644 --- a/R/tm_t_exposure.R +++ b/R/tm_t_exposure.R @@ -77,7 +77,9 @@ template_exposure <- function(parentname, parsed_basic_table_args <- teal.widgets::parse_basic_table_args( teal.widgets::resolve_basic_table_args( user_table = basic_table_args, - module_table = teal.widgets::basic_table_args(main_footer = paste0("* Patient time is the sum of ", paramcd_label)) + module_table = teal.widgets::basic_table_args( + main_footer = paste0("* Patient Time is the sum of ", paramcd_label) + ) ) ) @@ -122,9 +124,10 @@ template_exposure <- function(parentname, summarize_patients_exposure_in_cols( var = aval_var, col_split = TRUE, .labels = c( - n_patients = "Patient time*", + n_patients = "Number of Patients", sum_exposure = paste("Sum of", paramcd, sprintf("(%s)", avalu_var)) - ) + ), + custom_label = "Total Number of Patients and Patient Time*" ), env = list( aval_var = aval_var, @@ -577,6 +580,9 @@ srv_t_exposure <- function(id, input_paramcd_label <- as.character(paramcd_map[paramcd_map[1] == input_paramcd, 2]) } + basic_table_args$title <- "Duration of Exposure Table" + basic_table_args$subtitles <- paste("Parameter Category:", anl_m$filter_info$parcat[[1]]$selected[[1]]) + my_calls <- template_exposure( parentname = "ANL_ADSL", dataname = "ANL", diff --git a/tests/testthat/test-tm_t_exposure.R b/tests/testthat/test-tm_t_exposure.R index ddccbf4eb2..f3580c44a5 100644 --- a/tests/testthat/test-tm_t_exposure.R +++ b/tests/testthat/test-tm_t_exposure.R @@ -19,25 +19,25 @@ testthat::test_that("template_exposure generates correct expressions with defaul }), layout_prep = quote(split_fun <- drop_split_levels), layout = quote( - lyt <- rtables::basic_table(main_footer = "* Patient time is the sum of TDURD") %>% + lyt <- rtables::basic_table(main_footer = "* Patient Time is the sum of TDURD") %>% rtables::split_cols_by("SEX") %>% rtables::add_colcounts() %>% summarize_patients_exposure_in_cols( - var = "AVAL", - col_split = TRUE, - .labels = c( - n_patients = "Patient time*", - sum_exposure = paste("Sum of", "TDURD", sprintf("(%s)", "Days")) - ) + var = "AVAL", col_split = TRUE, + .labels = c(n_patients = "Number of Patients", sum_exposure = paste( + "Sum of", + "TDURD", sprintf("(%s)", "Days") + )), custom_label = "Total Number of Patients and Patient Time*" ) %>% - rtables::split_rows_by( - "RACE", - label_pos = "topleft", - split_fun = split_fun, + rtables::split_rows_by("RACE", + label_pos = "topleft", split_fun = split_fun, split_label = formatters::var_labels(adex["RACE"], fill = TRUE), nested = FALSE ) %>% - summarize_patients_exposure_in_cols(var = "AVAL", col_split = FALSE) + summarize_patients_exposure_in_cols( + var = "AVAL", + col_split = FALSE + ) ), table = quote({ result <- rtables::build_table(lyt = lyt, df = anl, alt_counts_df = adsl) @@ -68,25 +68,26 @@ testthat::test_that("template_exposure generates correct expressions with custom }), layout_prep = quote(split_fun <- drop_split_levels), layout = quote( - lyt <- rtables::basic_table(main_footer = "* Patient time is the sum of myTDURD") %>% + lyt <- rtables::basic_table(main_footer = "* Patient Time is the sum of myTDURD") %>% rtables::split_cols_by("SEX") %>% rtables::add_colcounts() %>% summarize_patients_exposure_in_cols( - var = "myAVAL", - col_split = TRUE, - .labels = c( - n_patients = "Patient time*", - sum_exposure = paste("Sum of", "myTDURD", sprintf("(%s)", "Days")) - ) + var = "myAVAL", col_split = TRUE, + .labels = c(n_patients = "Number of Patients", sum_exposure = paste( + "Sum of", + "myTDURD", sprintf("(%s)", "Days") + )), custom_label = "Total Number of Patients and Patient Time*" ) %>% - rtables::split_rows_by( - "myRACE", - label_pos = "topleft", - split_fun = split_fun, - split_label = formatters::var_labels(myadex["myRACE"], fill = TRUE), - nested = FALSE + rtables::split_rows_by("myRACE", + label_pos = "topleft", split_fun = split_fun, + split_label = formatters::var_labels(myadex["myRACE"], + fill = TRUE + ), nested = FALSE ) %>% - summarize_patients_exposure_in_cols(var = "myAVAL", col_split = FALSE) + summarize_patients_exposure_in_cols( + var = "myAVAL", + col_split = FALSE + ) ), table = quote({ result <- rtables::build_table(lyt = lyt, df = anl, alt_counts_df = myadsl) @@ -118,25 +119,25 @@ testthat::test_that("template_exposure generates correct expressions with paramc }), layout_prep = quote(split_fun <- drop_split_levels), layout = quote( - lyt <- rtables::basic_table(main_footer = "* Patient time is the sum of Total Duration (Days)") %>% + lyt <- rtables::basic_table(main_footer = "* Patient Time is the sum of Total Duration (Days)") %>% rtables::split_cols_by("SEX") %>% rtables::add_colcounts() %>% summarize_patients_exposure_in_cols( - var = "AVAL", - col_split = TRUE, - .labels = c( - n_patients = "Patient time*", - sum_exposure = paste("Sum of", "TDURD", sprintf("(%s)", "Days")) - ) + var = "AVAL", col_split = TRUE, + .labels = c(n_patients = "Number of Patients", sum_exposure = paste( + "Sum of", + "TDURD", sprintf("(%s)", "Days") + )), custom_label = "Total Number of Patients and Patient Time*" ) %>% - rtables::split_rows_by( - "RACE", - label_pos = "topleft", - split_fun = split_fun, + rtables::split_rows_by("RACE", + label_pos = "topleft", split_fun = split_fun, split_label = formatters::var_labels(adex["RACE"], fill = TRUE), nested = FALSE ) %>% - summarize_patients_exposure_in_cols(var = "AVAL", col_split = FALSE) + summarize_patients_exposure_in_cols( + var = "AVAL", + col_split = FALSE + ) ), table = quote({ result <- rtables::build_table(lyt = lyt, df = anl, alt_counts_df = adsl)