diff --git a/R/fda-table_32.R b/R/fda-table_32.R index d1be1b89..254eb820 100644 --- a/R/fda-table_32.R +++ b/R/fda-table_32.R @@ -42,7 +42,7 @@ make_table_32 <- function(df, tbl_summary( by = arm_var, statistic = list(all_categorical() ~ "{n} ({p}%)"), - digits = everything() ~ c(0, 1), + digits = list(all_continuous() ~ c(0, 1), all_categorical() ~ c(0, 1)), missing = "no" ) %>% modify_header(label ~ paste0("**Diastolic Blood Pressure (", avalu, ")**")) %>% diff --git a/R/fda-table_33.R b/R/fda-table_33.R index 5eb9f4cb..714087a6 100644 --- a/R/fda-table_33.R +++ b/R/fda-table_33.R @@ -43,7 +43,7 @@ make_table_33 <- function(df, tbl_summary( by = arm_var, statistic = list(all_categorical() ~ "{n} ({p}%)"), - digits = everything() ~ c(0, 1), + digits = list(all_continuous() ~ c(0, 1), all_categorical() ~ c(0, 1)), missing = "no" ) |> modify_header(label ~ paste0("**Diastolic Blood Pressure (", avalu, ")**")) |> diff --git a/tests/testthat/_snaps/fda-table_32.md b/tests/testthat/_snaps/fda-table_32.md index b508d58b..b3acee60 100644 --- a/tests/testthat/_snaps/fda-table_32.md +++ b/tests/testthat/_snaps/fda-table_32.md @@ -97,6 +97,31 @@ Output +--- + + Code + res + Output + Table 32. Percentage of Patients With Maximum Diastolic Blood Pressure by Category + of Blood Pressure Postbaseline, Safety Population, Pooled Analysis + + ——————————————————————————————————————————————————————————————————————————————————— + Total + Diastolic Blood Pressure A: Drug X C: Combination B: Placebo Population + (Pa) (N=134) (N=132) (N=134) (N=400) + ——————————————————————————————————————————————————————————————————————————————————— + <60 0 0 0 0 + >60 134 (100%) 132 (100%) 134 (100%) 400 (100%) + >90 134 (100%) 131 (99.2%) 134 (100%) 399 (99.8%) + >110 123 (91.8%) 107 (81.1%) 111 (82.8%) 341 (85.2%) + >=120 88 (65.7%) 76 (57.6%) 70 (52.2%) 234 (58.5%) + ——————————————————————————————————————————————————————————————————————————————————— + + Source: [include Applicant source, datasets and/or software tools used]. + + Abbreviations: CI, confidence interval; n, number of patients with indicated blood pressure; + N, number of patients in treatment arm with available blood pressure data + # Table 32 generation missing values and ADSL Code @@ -136,3 +161,30 @@ Output +# Table 32 generation works with pruned rows + + Code + res + Output + Diastolic Blood Pressure A: Drug X C: Combination B: Placebo + (Pa) (N=134) (N=132) (N=134) + ————————————————————————————————————————————————————————————————————— + >60 134 (100%) 132 (100%) 134 (100%) + >90 134 (100%) 131 (99.2%) 134 (100%) + >110 123 (91.8%) 107 (81.1%) 111 (82.8%) + >=120 88 (65.7%) 76 (57.6%) 70 (52.2%) + +# Table 32 generation works with risk difference column + + Code + res + Output + Diastolic Blood Pressure A: Drug X C: Combination B: Placebo Risk Difference (%) (95% CI) + (Pa) (N=134) (N=132) (N=134) (N=268) + ———————————————————————————————————————————————————————————————————————————————————————————————————— + <60 0 0 0 0.0 (0.0 - 0.0) + >60 134 (100%) 132 (100%) 134 (100%) 0.0 (0.0 - 0.0) + >90 134 (100%) 131 (99.2%) 134 (100%) 0.0 (0.0 - 0.0) + >110 123 (91.8%) 107 (81.1%) 111 (82.8%) -9.0 (-16.9 - -1.1) + >=120 88 (65.7%) 76 (57.6%) 70 (52.2%) -13.4 (-25.1 - -1.8) + diff --git a/tests/testthat/_snaps/fda-table_33.md b/tests/testthat/_snaps/fda-table_33.md index 1c9034c3..1235c70c 100644 --- a/tests/testthat/_snaps/fda-table_33.md +++ b/tests/testthat/_snaps/fda-table_33.md @@ -1,88 +1,101 @@ # Table 33 generation works with default values Code - res + as.data.frame(res$table) Output - $table - Blood Pressure A: Drug X B: Placebo C: Combination - (Pa) (N=134) (N=134) (N=132) - ———————————————————————————————————————————————————————— - SBP <90 9 (6.7%) 24 (17.9%) 12 (9.1%) - DBP <60 10 (7.5%) 13 (9.7%) 14 (10.6%) - - $ard - Message - {cards} data frame: 52 x 11 + variable var_type row_type var_label label stat_1 stat_2 stat_3 + 1 SBP90 dichotomous label SBP <90 SBP <90 9 (6.7%) 24 (17.9%) 12 (9.1%) + 2 DBP60 dichotomous label DBP <60 DBP <60 10 (7.5%) 13 (9.7%) 14 (10.6%) + +--- + + Code + res$ard Output - group1 group1_level variable variable_level stat_name stat_label stat - 1 ARM A: Drug X SBP90 FALSE n n 125 - 2 ARM A: Drug X SBP90 FALSE N N 134 - 3 ARM A: Drug X SBP90 FALSE p % 0.933 - 4 ARM A: Drug X SBP90 TRUE n n 9 - 5 ARM A: Drug X SBP90 TRUE N N 134 - 6 ARM A: Drug X SBP90 TRUE p % 0.067 - 7 ARM B: Place… SBP90 FALSE n n 110 - 8 ARM B: Place… SBP90 FALSE N N 134 - 9 ARM B: Place… SBP90 FALSE p % 0.821 - 10 ARM B: Place… SBP90 TRUE n n 24 + $tbl_summary + Message + {cards} data frame: 65 x 12 + Output + group1 group1_level variable variable_level stat_name stat_label stat gts_column + 1 ARM A: Drug X SBP90 TRUE n n 9 stat_1 + 2 ARM A: Drug X SBP90 TRUE N N 134 stat_1 + 3 ARM A: Drug X SBP90 TRUE p % 0.067 stat_1 + 4 ARM B: Place… SBP90 TRUE n n 24 stat_2 + 5 ARM B: Place… SBP90 TRUE N N 134 stat_2 + 6 ARM B: Place… SBP90 TRUE p % 0.179 stat_2 + 7 ARM C: Combi… SBP90 TRUE n n 12 stat_3 + 8 ARM C: Combi… SBP90 TRUE N N 132 stat_3 + 9 ARM C: Combi… SBP90 TRUE p % 0.091 stat_3 + 10 ARM A: Drug X DBP60 TRUE n n 10 stat_1 Message - i 42 more rows + i 55 more rows i Use `print(n = ...)` to see more rows i 4 more variables: context, fmt_fn, warning, error Output ---- +# Table 33 generation works with custom values Code - res2 + as.data.frame(res$table) Output - Blood Pressure A: Drug X B: Placebo C: Combination - (Pa) (N=134) (N=134) (N=132) - ———————————————————————————————————————————————————————— - SBP <90 9 (6.7%) 24 (17.9%) 12 (9.1%) - DBP <60 10 (7.5%) 13 (9.7%) 14 (10.6%) + variable var_type row_type var_label label stat_1 stat_2 stat_3 stat_0 + 1 SBP90 dichotomous label SBP <90 SBP <90 9 (6.7%) 24 (17.9%) 12 (9.1%) 45 (11.3%) + 2 DBP60 dichotomous label DBP <60 DBP <60 10 (7.5%) 13 (9.7%) 14 (10.6%) 37 (9.3%) --- Code - res3 + res$ard + Output + $tbl_summary + Message + {cards} data frame: 65 x 12 + Output + group1 group1_level variable variable_level stat_name stat_label stat gts_column + 1 ARM A: Drug X SBP90 TRUE n n 9 stat_1 + 2 ARM A: Drug X SBP90 TRUE N N 134 stat_1 + 3 ARM A: Drug X SBP90 TRUE p % 0.067 stat_1 + 4 ARM B: Place… SBP90 TRUE n n 24 stat_2 + 5 ARM B: Place… SBP90 TRUE N N 134 stat_2 + 6 ARM B: Place… SBP90 TRUE p % 0.179 stat_2 + 7 ARM C: Combi… SBP90 TRUE n n 12 stat_3 + 8 ARM C: Combi… SBP90 TRUE N N 132 stat_3 + 9 ARM C: Combi… SBP90 TRUE p % 0.091 stat_3 + 10 ARM A: Drug X DBP60 TRUE n n 10 stat_1 Message - {cards} data frame: 52 x 11 + i 55 more rows + i Use `print(n = ...)` to see more rows + i 4 more variables: context, fmt_fn, warning, error Output - group1 group1_level variable variable_level stat_name stat_label stat - 1 ARM A: Drug X SBP90 FALSE n n 125 - 2 ARM A: Drug X SBP90 FALSE N N 134 - 3 ARM A: Drug X SBP90 FALSE p % 0.933 - 4 ARM A: Drug X SBP90 TRUE n n 9 - 5 ARM A: Drug X SBP90 TRUE N N 134 - 6 ARM A: Drug X SBP90 TRUE p % 0.067 - 7 ARM B: Place… SBP90 FALSE n n 110 - 8 ARM B: Place… SBP90 FALSE N N 134 - 9 ARM B: Place… SBP90 FALSE p % 0.821 - 10 ARM B: Place… SBP90 TRUE n n 24 + + $add_overall Message - i 42 more rows + {cards} data frame: 21 x 10 + Output + variable variable_level stat_name stat_label stat gts_column + 1 SBP90 TRUE n n 45 stat_0 + 2 SBP90 TRUE N N 400 stat_0 + 3 SBP90 TRUE p % 0.113 stat_0 + 4 DBP60 TRUE n n 37 stat_0 + 5 DBP60 TRUE N N 400 stat_0 + 6 DBP60 TRUE p % 0.093 stat_0 + 7 SBP90 label Variable… SBP <90 + 8 SBP90 class Variable… logical + 9 DBP60 label Variable… DBP <60 + 10 DBP60 class Variable… logical + Message + i 11 more rows i Use `print(n = ...)` to see more rows i 4 more variables: context, fmt_fn, warning, error - ---- - - Code - res Output - # A tibble: 2 x 8 - variable var_type row_type var_label label stat_1 stat_2 stat_3 - - 1 SBP90 dichotomous label SBP <90 SBP <90 9 (6.7%) 24 (17.9~ 12 (9~ - 2 DBP60 dichotomous label DBP <60 DBP <60 10 (7.5%) 13 (9.7%) 14 (1~ + -# Table 33 generation works with custom values +--- Code res Output - $table Table 33. Percentage of Patients With Maximum Diastolic Blood Pressure by Category of Blood Pressure Postbaseline, Safety Population, Pooled Analysis @@ -99,161 +112,62 @@ Abbreviations: CI, confidence interval; n, number of patients with indicated blood pressure; N, number of patients in treatment arm with available blood pressure data - - $ard - Message - {cards} data frame: 52 x 11 - Output - group1 group1_level variable variable_level stat_name stat_label stat - 1 ARM A: Drug X SBP90 FALSE n n 125 - 2 ARM A: Drug X SBP90 FALSE N N 134 - 3 ARM A: Drug X SBP90 FALSE p % 0.933 - 4 ARM A: Drug X SBP90 TRUE n n 9 - 5 ARM A: Drug X SBP90 TRUE N N 134 - 6 ARM A: Drug X SBP90 TRUE p % 0.067 - 7 ARM B: Place… SBP90 FALSE n n 110 - 8 ARM B: Place… SBP90 FALSE N N 134 - 9 ARM B: Place… SBP90 FALSE p % 0.821 - 10 ARM B: Place… SBP90 TRUE n n 24 - Message - i 42 more rows - i Use `print(n = ...)` to see more rows - i 4 more variables: context, fmt_fn, warning, error - Output - ---- +# Table 33 generation missing values and ADSL Code - res + as.data.frame(res$table) Output - # A tibble: 2 x 9 - variable var_type row_type var_label label stat_1 stat_2 stat_3 stat_0 - - 1 SBP90 dichotomous label SBP <90 SBP <~ 9 (6.~ 24 (1~ 12 (9~ 45 (1~ - 2 DBP60 dichotomous label DBP <60 DBP <~ 10 (7~ 13 (9~ 14 (1~ 37 (9~ + variable var_type row_type var_label label stat_1 stat_2 stat_3 + 1 SBP90 dichotomous label SBP <90 SBP <90 9 (6.7%) 21 (15.7%) 11 (8.3%) + 2 DBP60 dichotomous label DBP <60 DBP <60 10 (7.5%) 13 (9.7%) 13 (9.8%) --- Code - res + res$ard Output - $table - Table 33. Percentage of Patients With Maximum Diastolic Blood Pressure by Category - of Blood Pressure Postbaseline, Safety Population, Pooled Analysis - - ————————————————————————————————————————————————————————————————————— - Total - Blood Pressure A: Drug X B: Placebo C: Combination Population - (Pa) (N=134) (N=134) (N=132) (N=400) - ————————————————————————————————————————————————————————————————————— - SBP <90 9 (6.7%) 24 (17.9%) 12 (9.1%) 45 (11.2%) - DBP <60 10 (7.5%) 13 (9.7%) 14 (10.6%) 37 (9.2%) - ————————————————————————————————————————————————————————————————————— - - Source: [include Applicant source, datasets and/or software tools used]. - - Abbreviations: CI, confidence interval; n, number of patients with indicated blood pressure; - N, number of patients in treatment arm with available blood pressure data - - $ard + $tbl_summary Message - {cards} data frame: 52 x 11 - Output - group1 group1_level variable variable_level stat_name stat_label stat - 1 ARM A: Drug X SBP90 FALSE n n 125 - 2 ARM A: Drug X SBP90 FALSE N N 134 - 3 ARM A: Drug X SBP90 FALSE p % 0.933 - 4 ARM A: Drug X SBP90 TRUE n n 9 - 5 ARM A: Drug X SBP90 TRUE N N 134 - 6 ARM A: Drug X SBP90 TRUE p % 0.067 - 7 ARM B: Place… SBP90 FALSE n n 110 - 8 ARM B: Place… SBP90 FALSE N N 134 - 9 ARM B: Place… SBP90 FALSE p % 0.821 - 10 ARM B: Place… SBP90 TRUE n n 24 + {cards} data frame: 65 x 12 + Output + group1 group1_level variable variable_level stat_name stat_label stat gts_column + 1 ARM A: Drug X SBP90 TRUE n n 9 stat_1 + 2 ARM A: Drug X SBP90 TRUE N N 134 stat_1 + 3 ARM A: Drug X SBP90 TRUE p % 0.067 stat_1 + 4 ARM B: Place… SBP90 TRUE n n 21 stat_2 + 5 ARM B: Place… SBP90 TRUE N N 134 stat_2 + 6 ARM B: Place… SBP90 TRUE p % 0.157 stat_2 + 7 ARM C: Combi… SBP90 TRUE n n 11 stat_3 + 8 ARM C: Combi… SBP90 TRUE N N 132 stat_3 + 9 ARM C: Combi… SBP90 TRUE p % 0.083 stat_3 + 10 ARM A: Drug X DBP60 TRUE n n 10 stat_1 Message - i 42 more rows + i 55 more rows i Use `print(n = ...)` to see more rows i 4 more variables: context, fmt_fn, warning, error Output -# Table 33 generation missing values and ADSL - - Code - res - Output - # A tibble: 2 x 9 - variable var_type row_type var_label label stat_1 stat_2 stat_3 stat_0 - - 1 SBP90 dichotomous label SBP <90 SBP <~ 9 (6.~ 21 (1~ 11 (8~ 41 (1~ - 2 DBP60 dichotomous label DBP <60 DBP <~ 10 (7~ 13 (9~ 13 (9~ 36 (9~ - # Table 33 generation works with pruned rows Code res Output - $table Blood Pressure A: Drug X B: Placebo C: Combination (Pa) (N=134) (N=134) (N=132) ———————————————————————————————————————————————————————— SBP <90 9 (6.7%) 24 (17.9%) 12 (9.1%) DBP <60 10 (7.5%) 13 (9.7%) 14 (10.6%) - - $ard - Message - {cards} data frame: 52 x 11 - Output - group1 group1_level variable variable_level stat_name stat_label stat - 1 ARM A: Drug X SBP90 FALSE n n 125 - 2 ARM A: Drug X SBP90 FALSE N N 134 - 3 ARM A: Drug X SBP90 FALSE p % 0.933 - 4 ARM A: Drug X SBP90 TRUE n n 9 - 5 ARM A: Drug X SBP90 TRUE N N 134 - 6 ARM A: Drug X SBP90 TRUE p % 0.067 - 7 ARM B: Place… SBP90 FALSE n n 110 - 8 ARM B: Place… SBP90 FALSE N N 134 - 9 ARM B: Place… SBP90 FALSE p % 0.821 - 10 ARM B: Place… SBP90 TRUE n n 24 - Message - i 42 more rows - i Use `print(n = ...)` to see more rows - i 4 more variables: context, fmt_fn, warning, error - Output - # Table 33 generation works with risk difference column Code res Output - $table Blood Pressure A: Drug X B: Placebo C: Combination Risk Difference (%) (95% CI) (Pa) (N=134) (N=134) (N=132) (N=268) ——————————————————————————————————————————————————————————————————————————————————————— SBP <90 9 (6.7%) 24 (17.9%) 12 (9.1%) 11.2 (3.4 - 18.9) DBP <60 10 (7.5%) 13 (9.7%) 14 (10.6%) 2.2 (-4.5 - 8.9) - - $ard - Message - {cards} data frame: 52 x 11 - Output - group1 group1_level variable variable_level stat_name stat_label stat - 1 ARM A: Drug X SBP90 FALSE n n 125 - 2 ARM A: Drug X SBP90 FALSE N N 134 - 3 ARM A: Drug X SBP90 FALSE p % 0.933 - 4 ARM A: Drug X SBP90 TRUE n n 9 - 5 ARM A: Drug X SBP90 TRUE N N 134 - 6 ARM A: Drug X SBP90 TRUE p % 0.067 - 7 ARM B: Place… SBP90 FALSE n n 110 - 8 ARM B: Place… SBP90 FALSE N N 134 - 9 ARM B: Place… SBP90 FALSE p % 0.821 - 10 ARM B: Place… SBP90 TRUE n n 24 - Message - i 42 more rows - i Use `print(n = ...)` to see more rows - i 4 more variables: context, fmt_fn, warning, error - Output - diff --git a/tests/testthat/test-fda-table_32.R b/tests/testthat/test-fda-table_32.R index d8f1822f..c62e0598 100644 --- a/tests/testthat/test-fda-table_32.R +++ b/tests/testthat/test-fda-table_32.R @@ -10,15 +10,15 @@ advs_missing <- advs_missing |> # gtsummary ----- test_that("Table 32 generation works with default values", { - withr::local_options(list(width = 120)) + withr::local_options(list(width = 150)) - result <- make_table_32(advs) + expect_warning(result <- make_table_32(advs)) res <- expect_silent(result) expect_snapshot(res$table |> as.data.frame()) expect_snapshot(res$ard) # no ARD - result2 <- make_table_32(advs, return_ard = FALSE) + expect_warning(result2 <- make_table_32(advs, return_ard = FALSE)) res2 <- expect_silent(result2) expect_identical(res$table, res2) @@ -27,13 +27,13 @@ test_that("Table 32 generation works with default values", { test_that("Table 32 generation works with custom values", { withr::local_options(list(width = 120)) - result <- make_table_32(advs, adsl, lbl_overall = "Overall") + expect_warning(result <- make_table_32(advs, adsl, lbl_overall = "Overall")) res <- expect_silent(result) expect_snapshot(res$table |> as.data.frame()) expect_snapshot(res$ard) # no ARD - result2 <- make_table_32(advs, adsl, return_ard = FALSE) + expect_warning(result2 <- make_table_32(advs, adsl, return_ard = FALSE)) res2 <- expect_silent(result2) expect_identical(res$table, res2) @@ -42,13 +42,13 @@ test_that("Table 32 generation works with custom values", { test_that("Table 32 generation missing values and ADSL", { withr::local_options(list(width = 120)) - result <- make_table_32(advs_missing, adsl) + expect_warning(expect_warning(result <- make_table_32(advs_missing, adsl))) res <- expect_silent(result) expect_snapshot(res$table |> as.data.frame()) expect_snapshot(res$ard) # no ARD - result2 <- make_table_32(advs, return_ard = FALSE) + expect_warning(result2 <- make_table_32(advs, return_ard = FALSE)) res2 <- expect_silent(result2) expect_identical(res$table, res2) diff --git a/tests/testthat/test-fda-table_33.R b/tests/testthat/test-fda-table_33.R index 520c6c34..4ad30d5a 100644 --- a/tests/testthat/test-fda-table_33.R +++ b/tests/testthat/test-fda-table_33.R @@ -12,13 +12,13 @@ advs_missing <- advs_missing %>% test_that("Table 33 generation works with default values", { withr::local_options(list(width = 120)) - result <- make_table_33(advs) + expect_warning(result <- make_table_33(advs)) res <- expect_silent(result) expect_snapshot(res$table |> as.data.frame()) expect_snapshot(res$ard) # no ARD - result2 <- make_table_33(advs, return_ard = FALSE) + expect_warning(result2 <- make_table_33(advs, return_ard = FALSE)) res2 <- expect_silent(result2) expect_identical(res$table, res2) @@ -27,13 +27,13 @@ test_that("Table 33 generation works with default values", { test_that("Table 33 generation works with custom values", { withr::local_options(list(width = 120)) - result <- make_table_33(advs, adsl, lbl_overall = "Overall") + expect_warning(result <- make_table_33(advs, adsl, lbl_overall = "Overall")) res <- expect_silent(result) expect_snapshot(res$table |> as.data.frame()) expect_snapshot(res$ard) # no ARD - result2 <- make_table_33(advs, adsl, return_ard = FALSE) + expect_warning(result2 <- make_table_33(advs, adsl, return_ard = FALSE)) res2 <- expect_silent(result2) expect_identical(res$table, res2) @@ -42,7 +42,7 @@ test_that("Table 33 generation works with custom values", { test_that("Table 33 generation missing values and ADSL", { withr::local_options(list(width = 120)) - result <- make_table_33(advs_missing, adsl) + expect_warning(result <- make_table_33(advs_missing, adsl)) res <- expect_silent(result) expect_snapshot(res$table |> as.data.frame()) expect_snapshot(res$ard) @@ -58,11 +58,10 @@ test_that("Table 33 generation missing values and ADSL", { # rtables ----- test_that("Table 33 generation works with custom values", { - result <- make_table_33( + result <- make_table_33_rtables( advs, adsl, - table_engine = "rtables", - subset = (PARAMCD %in% c("DIABP", "SYSBP") & AVISITN >= 1), + subset = "PARAMCD %in% c('DIABP', 'SYSBP') & AVISITN >= 1", lbl_overall = "Total\nPopulation", annotations = list( title = paste( @@ -82,11 +81,10 @@ test_that("Table 33 generation works with custom values", { }) test_that("Table 33 generation works with pruned rows", { - result <- make_table_33( + result <- make_table_33_rtables( advs, adsl, prune_0 = TRUE, - table_engine = "rtables", subset = "PARAMCD %in% c('DIABP', 'SYSBP') & AVISITN >= 1" ) @@ -96,11 +94,10 @@ test_that("Table 33 generation works with pruned rows", { test_that("Table 33 generation works with risk difference column", { risk_diff <- list(arm_x = "B: Placebo", arm_y = "A: Drug X") - result <- make_table_33( + result <- make_table_33_rtables( advs, adsl, risk_diff = risk_diff, - table_engine = "rtables", subset = "PARAMCD %in% c('DIABP', 'SYSBP') & AVISITN >= 1" )