From be0c230e37f656b8716077e499ccd01393130b38 Mon Sep 17 00:00:00 2001 From: munoztd0 Date: Tue, 3 Mar 2026 15:32:11 +0100 Subject: [PATCH 1/5] update: new tern feature branch with change to the default format of a statistics of lsmean to 3 decimal place --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index b8ee074e..c5d8de51 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -53,7 +53,7 @@ Remotes: insightsengineering/formatters@main, insightsengineering/rlistings@main, insightsengineering/rtables@main, - insightsengineering/tern@main, + munoztd0/tern@jnj_templates_2_tern_change_default_decimals, pharmaverse/pharmaverseadam@main, johnsonandjohnson/pharmaverseadamjnj@main, johnsonandjohnson/pharmaversesdtmjnj@main From c81189a524510ef7b0b0f72806fd8bb9d81b4b5e Mon Sep 17 00:00:00 2001 From: munoztd0 Date: Thu, 5 Mar 2026 10:42:17 +0100 Subject: [PATCH 2/5] update: remove tern default n formats --- tests/testthat/source_code/tpk01a.R | 1 + tests/testthat/source_code/tpk02.R | 1 + tests/testthat/source_code/tsidem01.R | 12 +++++++++--- tests/testthat/source_code/tsids01.R | 5 +++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/testthat/source_code/tpk01a.R b/tests/testthat/source_code/tpk01a.R index 144f4178..799353ab 100644 --- a/tests/testthat/source_code/tpk01a.R +++ b/tests/testthat/source_code/tpk01a.R @@ -134,6 +134,7 @@ lyt <- basic_table() |> quantiles = "Interquartile range" ), .formats = c( + n = jjcsformat_xx("xx"), mean_sd = jjcsformat_xx("xx.xx (xx.xx)"), median = jjcsformat_xx("xx.xx"), geom_mean = jjcsformat_xx("xx.xx"), diff --git a/tests/testthat/source_code/tpk02.R b/tests/testthat/source_code/tpk02.R index 91d3bb39..43651a04 100644 --- a/tests/testthat/source_code/tpk02.R +++ b/tests/testthat/source_code/tpk02.R @@ -137,6 +137,7 @@ for (i in seq_along(trt_grps)) { quantiles = "Interquartile range" ), .formats = c( + n = jjcsformat_xx("xx"), mean_sd = jjcsformat_xx("xx.xx (xx.xx)"), median = jjcsformat_xx("xx.xx"), geom_mean = jjcsformat_xx("xx.xx"), diff --git a/tests/testthat/source_code/tsidem01.R b/tests/testthat/source_code/tsidem01.R index 66c99753..bb9ce26b 100644 --- a/tests/testthat/source_code/tsidem01.R +++ b/tests/testthat/source_code/tsidem01.R @@ -231,7 +231,9 @@ lyt <- basic_table( extra_args = list( .stats = c("n", "mean_sd", "median", "range", "count_fraction"), .labels = c("n" = "N", "range" = "Min, max"), - .formats = c(P1_precision, "count_fraction" = jjcsformat_count_fraction), + .formats = c(P1_precision, + n = jjcsformat_xx("xx"), + "count_fraction" = jjcsformat_count_fraction), .indent_mods = c( "n" = 0L, "mean_sd" = 1L, @@ -262,7 +264,9 @@ lyt <- basic_table( extra_args = list( .stats = c("n", "mean_sd", "median", "range", "count_fraction"), .labels = c("n" = "N", "range" = "Min, max"), - .formats = c(P2a_precision, "count_fraction" = jjcsformat_count_fraction), + .formats = c(P2a_precision, + n = jjcsformat_xx("xx"), + "count_fraction" = jjcsformat_count_fraction), .indent_mods = c( "n" = 0L, "mean_sd" = 1L, @@ -280,7 +284,9 @@ lyt <- basic_table( extra_args = list( .stats = c("n", "mean_sd", "median", "range", "count_fraction"), .labels = c("n" = "N", "range" = "Min, max"), - .formats = c(P2b_precision, "count_fraction" = jjcsformat_count_fraction), + .formats = c(P2b_precision, + n = jjcsformat_xx("xx"), + "count_fraction" = jjcsformat_count_fraction), .indent_mods = c( "n" = 0L, "mean_sd" = 1L, diff --git a/tests/testthat/source_code/tsids01.R b/tests/testthat/source_code/tsids01.R index d81caf47..8b649cbc 100644 --- a/tests/testthat/source_code/tsids01.R +++ b/tests/testthat/source_code/tsids01.R @@ -24,7 +24,7 @@ ############################################################################### library(envsetup) -library(tern) +#library(tern) library(dplyr) library(rtables) library(junco) @@ -97,7 +97,8 @@ lyt <- basic_table( var = "USUBJID", flag_variables = c("RESCRNFL"), nested = FALSE, - .stats = "count" + .stats = "count", + .formats = c("count" = jjcsformat_xx("xx")) ) %>% count_patients_with_flags( var = "USUBJID", From 3e3b72f34536a4a61d375b972ca7193db82054a8 Mon Sep 17 00:00:00 2001 From: munoztd0 Date: Thu, 5 Mar 2026 11:27:38 +0100 Subject: [PATCH 3/5] update: remove tern default n formats --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index c5d8de51..e1f16c55 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -53,7 +53,7 @@ Remotes: insightsengineering/formatters@main, insightsengineering/rlistings@main, insightsengineering/rtables@main, - munoztd0/tern@jnj_templates_2_tern_change_default_decimals, + munoztd0/tern@tern_defaults_junco, pharmaverse/pharmaverseadam@main, johnsonandjohnson/pharmaverseadamjnj@main, johnsonandjohnson/pharmaversesdtmjnj@main From 27cfe4be0980a5f481c7614107db31759cb54515 Mon Sep 17 00:00:00 2001 From: munoztd0 Date: Thu, 5 Mar 2026 11:30:05 +0100 Subject: [PATCH 4/5] update: remove Roche's test for making it simpler --- tests/testthat/test-char-support.R | 115 ---- tests/testthat/test-listing_adal02.R | 112 ---- tests/testthat/test-listing_ael01.R | 21 - tests/testthat/test-listing_ael01_nollt.R | 24 - tests/testthat/test-listing_ael02.R | 61 --- tests/testthat/test-listing_ael02_ed.R | 78 --- tests/testthat/test-listing_ael03.R | 74 --- tests/testthat/test-listing_ael04.R | 31 -- tests/testthat/test-listing_cml01.R | 42 -- tests/testthat/test-listing_cml02a_gl.R | 20 - tests/testthat/test-listing_cml02b_gl.R | 23 - tests/testthat/test-listing_dsl01.R | 32 -- tests/testthat/test-listing_dsl02.R | 34 -- tests/testthat/test-listing_dsur4.R | 23 - tests/testthat/test-listing_egl01.R | 62 --- tests/testthat/test-listing_exl01.R | 30 -- tests/testthat/test-listing_lbl01.R | 53 -- tests/testthat/test-listing_lbl01_rls.R | 59 --- tests/testthat/test-listing_lbl02a.R | 51 -- tests/testthat/test-listing_lbl02a_rls.R | 80 --- tests/testthat/test-listing_lbl02b.R | 57 -- tests/testthat/test-listing_mhl01.R | 34 -- tests/testthat/test-listing_oncl01.R | 62 --- tests/testthat/test-listing_pkcl01.R | 57 -- tests/testthat/test-listing_pkcl02.R | 63 --- tests/testthat/test-listing_pkpl01.R | 39 -- tests/testthat/test-listing_pkpl02.R | 38 -- tests/testthat/test-listing_pkpl04.R | 53 -- tests/testthat/test-listing_vsl01.R | 84 --- tests/testthat/test-pagination_listing.R | 157 ------ tests/testthat/test-pagination_table.R | 218 -------- tests/testthat/test-table_adat03.R | 73 --- tests/testthat/test-table_aet01.R | 311 ----------- tests/testthat/test-table_aet01_aesi.R | 551 ------------------- tests/testthat/test-table_aet02.R | 612 ---------------------- tests/testthat/test-table_aet02_smq.R | 92 ---- tests/testthat/test-table_aet03.R | 104 ---- tests/testthat/test-table_aet04.R | 533 ------------------- tests/testthat/test-table_aet04_pi.R | 319 ----------- tests/testthat/test-table_aet05.R | 54 -- tests/testthat/test-table_aet05_all.R | 48 -- tests/testthat/test-table_aet06.R | 194 ------- tests/testthat/test-table_aet06_smq.R | 161 ------ tests/testthat/test-table_aet07.R | 79 --- tests/testthat/test-table_aet09.R | 104 ---- tests/testthat/test-table_aet09_smq.R | 130 ----- tests/testthat/test-table_aet10.R | 24 - tests/testthat/test-table_aovt01.R | 73 --- tests/testthat/test-table_aovt02.R | 43 -- tests/testthat/test-table_aovt03.R | 45 -- tests/testthat/test-table_cfbt01.R | 65 --- tests/testthat/test-table_cmht01.R | 123 ----- tests/testthat/test-table_cmt01.R | 136 ----- tests/testthat/test-table_cmt01a.R | 194 ------- tests/testthat/test-table_cmt01b.R | 220 -------- tests/testthat/test-table_cmt02_pt.R | 43 -- tests/testthat/test-table_coxt01.R | 98 ---- tests/testthat/test-table_coxt02.R | 49 -- tests/testthat/test-table_disclosures.R | 212 -------- tests/testthat/test-table_dmt01.R | 170 ------ tests/testthat/test-table_dort01.R | 245 --------- tests/testthat/test-table_dst01.R | 90 ---- tests/testthat/test-table_dtht01.R | 159 ------ tests/testthat/test-table_egt01.R | 55 -- tests/testthat/test-table_egt02.R | 56 -- tests/testthat/test-table_egt03.R | 124 ----- tests/testthat/test-table_egt04.R | 61 --- tests/testthat/test-table_egt05_qtcat.R | 89 ---- tests/testthat/test-table_ent.R | 80 --- tests/testthat/test-table_eudrat01.R | 78 --- tests/testthat/test-table_eudrat02.R | 45 -- tests/testthat/test-table_ext01.R | 179 ------- tests/testthat/test-table_jnj_tbl1.R | 56 -- tests/testthat/test-table_lbt01.R | 56 -- tests/testthat/test-table_lbt02.R | 19 - tests/testthat/test-table_lbt03.R | 30 -- tests/testthat/test-table_lbt04.R | 35 -- tests/testthat/test-table_lbt05.R | 132 ----- tests/testthat/test-table_lbt06.R | 33 -- tests/testthat/test-table_lbt07.R | 88 ---- tests/testthat/test-table_lbt08.R | 44 -- tests/testthat/test-table_lbt09.R | 132 ----- tests/testthat/test-table_lbt10.R | 111 ---- tests/testthat/test-table_lbt10_bl.R | 70 --- tests/testthat/test-table_lbt11.R | 136 ----- tests/testthat/test-table_lbt11_bl.R | 111 ---- tests/testthat/test-table_lbt12.R | 65 --- tests/testthat/test-table_lbt12_bl.R | 65 --- tests/testthat/test-table_lbt13.R | 369 ------------- tests/testthat/test-table_lbt14.R | 275 ---------- tests/testthat/test-table_lbt15.R | 90 ---- tests/testthat/test-table_lgrt02.R | 131 ----- tests/testthat/test-table_mht01.R | 131 ----- tests/testthat/test-table_onct05.R | 123 ----- tests/testthat/test-table_pdt01.R | 41 -- tests/testthat/test-table_pdt02.R | 44 -- tests/testthat/test-table_pkct01.R | 143 ----- tests/testthat/test-table_pkpt02.R | 45 -- tests/testthat/test-table_pkpt03.R | 70 --- tests/testthat/test-table_pkpt04.R | 42 -- tests/testthat/test-table_pkpt05.R | 66 --- tests/testthat/test-table_pkpt06.R | 62 --- tests/testthat/test-table_pkpt07.R | 89 ---- tests/testthat/test-table_ratet01.R | 106 ---- tests/testthat/test-table_rmpt01.R | 59 --- tests/testthat/test-table_rmpt03.R | 92 ---- tests/testthat/test-table_rmpt04.R | 51 -- tests/testthat/test-table_rmpt05.R | 50 -- tests/testthat/test-table_rmpt06.R | 278 ---------- tests/testthat/test-table_rspt01.R | 253 --------- tests/testthat/test-table_ttet01.R | 441 ---------------- tests/testthat/test-table_vst01.R | 101 ---- tests/testthat/test-table_vst02.R | 52 -- 113 files changed, 12395 deletions(-) delete mode 100644 tests/testthat/test-char-support.R delete mode 100644 tests/testthat/test-listing_adal02.R delete mode 100644 tests/testthat/test-listing_ael01.R delete mode 100644 tests/testthat/test-listing_ael01_nollt.R delete mode 100644 tests/testthat/test-listing_ael02.R delete mode 100644 tests/testthat/test-listing_ael02_ed.R delete mode 100644 tests/testthat/test-listing_ael03.R delete mode 100644 tests/testthat/test-listing_ael04.R delete mode 100644 tests/testthat/test-listing_cml01.R delete mode 100644 tests/testthat/test-listing_cml02a_gl.R delete mode 100644 tests/testthat/test-listing_cml02b_gl.R delete mode 100644 tests/testthat/test-listing_dsl01.R delete mode 100644 tests/testthat/test-listing_dsl02.R delete mode 100644 tests/testthat/test-listing_dsur4.R delete mode 100644 tests/testthat/test-listing_egl01.R delete mode 100644 tests/testthat/test-listing_exl01.R delete mode 100644 tests/testthat/test-listing_lbl01.R delete mode 100644 tests/testthat/test-listing_lbl01_rls.R delete mode 100644 tests/testthat/test-listing_lbl02a.R delete mode 100644 tests/testthat/test-listing_lbl02a_rls.R delete mode 100644 tests/testthat/test-listing_lbl02b.R delete mode 100644 tests/testthat/test-listing_mhl01.R delete mode 100644 tests/testthat/test-listing_oncl01.R delete mode 100644 tests/testthat/test-listing_pkcl01.R delete mode 100644 tests/testthat/test-listing_pkcl02.R delete mode 100644 tests/testthat/test-listing_pkpl01.R delete mode 100644 tests/testthat/test-listing_pkpl02.R delete mode 100644 tests/testthat/test-listing_pkpl04.R delete mode 100644 tests/testthat/test-listing_vsl01.R delete mode 100644 tests/testthat/test-pagination_listing.R delete mode 100644 tests/testthat/test-pagination_table.R delete mode 100644 tests/testthat/test-table_adat03.R delete mode 100644 tests/testthat/test-table_aet01.R delete mode 100644 tests/testthat/test-table_aet01_aesi.R delete mode 100644 tests/testthat/test-table_aet02.R delete mode 100644 tests/testthat/test-table_aet02_smq.R delete mode 100644 tests/testthat/test-table_aet03.R delete mode 100644 tests/testthat/test-table_aet04.R delete mode 100644 tests/testthat/test-table_aet04_pi.R delete mode 100644 tests/testthat/test-table_aet05.R delete mode 100644 tests/testthat/test-table_aet05_all.R delete mode 100644 tests/testthat/test-table_aet06.R delete mode 100644 tests/testthat/test-table_aet06_smq.R delete mode 100644 tests/testthat/test-table_aet07.R delete mode 100644 tests/testthat/test-table_aet09.R delete mode 100644 tests/testthat/test-table_aet09_smq.R delete mode 100644 tests/testthat/test-table_aet10.R delete mode 100644 tests/testthat/test-table_aovt01.R delete mode 100644 tests/testthat/test-table_aovt02.R delete mode 100644 tests/testthat/test-table_aovt03.R delete mode 100644 tests/testthat/test-table_cfbt01.R delete mode 100644 tests/testthat/test-table_cmht01.R delete mode 100644 tests/testthat/test-table_cmt01.R delete mode 100644 tests/testthat/test-table_cmt01a.R delete mode 100644 tests/testthat/test-table_cmt01b.R delete mode 100644 tests/testthat/test-table_cmt02_pt.R delete mode 100644 tests/testthat/test-table_coxt01.R delete mode 100644 tests/testthat/test-table_coxt02.R delete mode 100644 tests/testthat/test-table_disclosures.R delete mode 100644 tests/testthat/test-table_dmt01.R delete mode 100644 tests/testthat/test-table_dort01.R delete mode 100644 tests/testthat/test-table_dst01.R delete mode 100644 tests/testthat/test-table_dtht01.R delete mode 100644 tests/testthat/test-table_egt01.R delete mode 100644 tests/testthat/test-table_egt02.R delete mode 100644 tests/testthat/test-table_egt03.R delete mode 100644 tests/testthat/test-table_egt04.R delete mode 100644 tests/testthat/test-table_egt05_qtcat.R delete mode 100644 tests/testthat/test-table_ent.R delete mode 100644 tests/testthat/test-table_eudrat01.R delete mode 100644 tests/testthat/test-table_eudrat02.R delete mode 100644 tests/testthat/test-table_ext01.R delete mode 100644 tests/testthat/test-table_jnj_tbl1.R delete mode 100644 tests/testthat/test-table_lbt01.R delete mode 100644 tests/testthat/test-table_lbt02.R delete mode 100644 tests/testthat/test-table_lbt03.R delete mode 100644 tests/testthat/test-table_lbt04.R delete mode 100644 tests/testthat/test-table_lbt05.R delete mode 100644 tests/testthat/test-table_lbt06.R delete mode 100644 tests/testthat/test-table_lbt07.R delete mode 100644 tests/testthat/test-table_lbt08.R delete mode 100644 tests/testthat/test-table_lbt09.R delete mode 100644 tests/testthat/test-table_lbt10.R delete mode 100644 tests/testthat/test-table_lbt10_bl.R delete mode 100644 tests/testthat/test-table_lbt11.R delete mode 100644 tests/testthat/test-table_lbt11_bl.R delete mode 100644 tests/testthat/test-table_lbt12.R delete mode 100644 tests/testthat/test-table_lbt12_bl.R delete mode 100644 tests/testthat/test-table_lbt13.R delete mode 100644 tests/testthat/test-table_lbt14.R delete mode 100644 tests/testthat/test-table_lbt15.R delete mode 100644 tests/testthat/test-table_lgrt02.R delete mode 100644 tests/testthat/test-table_mht01.R delete mode 100644 tests/testthat/test-table_onct05.R delete mode 100644 tests/testthat/test-table_pdt01.R delete mode 100644 tests/testthat/test-table_pdt02.R delete mode 100644 tests/testthat/test-table_pkct01.R delete mode 100644 tests/testthat/test-table_pkpt02.R delete mode 100644 tests/testthat/test-table_pkpt03.R delete mode 100644 tests/testthat/test-table_pkpt04.R delete mode 100644 tests/testthat/test-table_pkpt05.R delete mode 100644 tests/testthat/test-table_pkpt06.R delete mode 100644 tests/testthat/test-table_pkpt07.R delete mode 100644 tests/testthat/test-table_ratet01.R delete mode 100644 tests/testthat/test-table_rmpt01.R delete mode 100644 tests/testthat/test-table_rmpt03.R delete mode 100644 tests/testthat/test-table_rmpt04.R delete mode 100644 tests/testthat/test-table_rmpt05.R delete mode 100644 tests/testthat/test-table_rmpt06.R delete mode 100644 tests/testthat/test-table_rspt01.R delete mode 100644 tests/testthat/test-table_ttet01.R delete mode 100644 tests/testthat/test-table_vst01.R delete mode 100644 tests/testthat/test-table_vst02.R diff --git a/tests/testthat/test-char-support.R b/tests/testthat/test-char-support.R deleted file mode 100644 index 677be703..00000000 --- a/tests/testthat/test-char-support.R +++ /dev/null @@ -1,115 +0,0 @@ -adsl <- random.cdisc.data::cadsl -adeg <- random.cdisc.data::cadeg - -################################################################################ -# Define script level parameters: -################################################################################ -adsl_f <- adsl |> - select(USUBJID, ACTARM) - -# Note: We keep only post-baseline for analysis. -adeg_f <- adeg |> - filter(AVISIT %in% levels(adeg$AVISIT)[1:3]) |> - filter(PARAM %in% c("Heart Rate", "QT Duration", "RR Duration")) |> - var_relabel( - PARAM = "Assessment", - ANRIND = "Abnormality" - ) |> - select(USUBJID, AVISIT, PARAM, PARAMCD, ANRIND, ACTARM) |> - mutate(PARCAT = case_when( - PARAMCD == "QT" ~ "QT", - TRUE ~ "Other" - )) |> - mutate(ANRIND2 = paste(ANRIND, PARAMCD)) |> - mutate(ANRIND3 = paste(ANRIND, PARAM)) - -# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels. -adsl_f <- df_explicit_na(adsl_f) -adeg_f <- df_explicit_na(adeg_f) - -adeg_f_1 <- adeg_f |> - filter(PARAMCD != "QT") |> - mutate(CRITDIR = "Direction 1") |> - mutate(ANRIND23 = ANRIND2) - -adeg_f_2 <- adeg_f |> - mutate(CRITDIR = "Direction 2") |> - mutate(ANRIND23 = ANRIND3) - -adeg_f <- rbind(adeg_f_1, adeg_f_2) - - -### mapping dataframe -uniq_adeg <- unique(adeg_f |> select(PARCAT, PARAMCD, CRITDIR, ANRIND23)) -mapdf <- uniq_adeg |> - arrange(PARCAT, PARAMCD, CRITDIR, ANRIND23) |> - mutate(across(where(is.factor), as.character)) - -### 3 versions of dataset -### CRITDIR not factor, all visits have available data for all PARAMCD -adeg_f1 <- adeg_f - -### CRITDIR not factor, not all visits available data for all PARAMCD -### exclude QT from screening - this will generate the problem in 6.11 -adeg_f <- adeg_f |> - filter(!(AVISIT == "SCREENING" & PARAMCD == "QT")) - -### CRITDIR factor, not all visits available data -adeg_f2 <- adeg_f -### also part of the issue -adeg_f2$CRITDIR <- factor(adeg_f2$CRITDIR) - - -################################################################################ -# Define layout and build table: -################################################################################ - - -lyt <- basic_table( - show_colcounts = TRUE, - colcount_format = "N=xx" -) |> - split_cols_by("ACTARM") |> - split_rows_by("AVISIT", - label_pos = "topleft", - section_div = " ", - split_fun = drop_split_levels, - split_label = "Time Point", - child_labels = "visible" - ) |> - split_rows_by("PARAMCD", - split_label = "Test", - label_pos = "topleft", - indent_mod = 1L, - child_labels = "visible", - split_fun = trim_levels_to_map(mapdf) - ) |> - split_rows_by("CRITDIR", - split_label = "Direction", - label_pos = "topleft", - indent_mod = 1L, - child_labels = "visible", - split_fun = trim_levels_to_map(mapdf) - ) |> - analyze(c("ANRIND23"), - a_summary, - extra_args = list(.stats = "count_fraction"), - show_labels = "hidden", - indent_mod = 1L - ) - -testthat::test_that("CRITDIR is factor, and one PARAMCD is not available on all AVISITS", { - res <- testthat::expect_silent(build_table(lyt, adeg_f2, alt_counts_df = adsl_f)) - testthat::expect_snapshot(res) -}) - - -testthat::test_that("CRITDIR is not factor, and all PARAMCD available on all AVISITS", { - res <- testthat::expect_silent(build_table(lyt, adeg_f1, alt_counts_df = adsl_f)) - testthat::expect_snapshot(res) -}) - -testthat::test_that("CRITDIR is not factor, and one PARAMCD is not available on all AVISITS", { - res <- testthat::expect_silent(build_table(lyt, adeg_f, alt_counts_df = adsl_f)) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-listing_adal02.R b/tests/testthat/test-listing_adal02.R deleted file mode 100644 index ff010dfa..00000000 --- a/tests/testthat/test-listing_adal02.R +++ /dev/null @@ -1,112 +0,0 @@ -testthat::test_that("ADAL02 listing is produced correctly", { - adab <- adab_raw |> - filter(NFRLT %% 1 == 0 & NFRLT > 0) - - trt <- "A: Drug X" - drug_a <- "A: Drug X Antibody" - drugcd <- unique(adab$PARAMCD[adab$PARAM == "Antibody titer units"])[1] - min_titer <- 1.10 - - adab_x <- adab |> - filter( - ARM == trt, - PARCAT1 == drug_a, - ADPBLPFL == "Y" - ) |> - select(-PARAMCD, -AVALC, -AVALU, -ARRLT, -NRRLT) |> - unique() |> - tidyr::pivot_wider( - names_from = PARAM, - values_from = AVAL - ) |> - mutate( - VISN = factor(paste0( - VISIT, "\n(Day ", - ifelse( - NFRLT %% 1 == 0, - NFRLT, - as.character(format(round(NFRLT, 2), nsmall = 2)) - ), - ")" - )), - PTES = ifelse( - ifelse("Treatment induced ADA" %in% names(.data), `Treatment induced ADA` == 1, FALSE), - ifelse( - "Transient ADA" %in% names(.) & `Transient ADA` == 1, - "Induced (Transient)", - "Induced (Persistent)" - ), - "Enhanced" - ) - ) |> - mutate( - AVAL = paste0( - ifelse( - ifelse("ADA interpreted per sample result" %in% names(.data), - `ADA interpreted per sample result` == 0, FALSE - ), - "NEGATIVE", - ifelse( - ifelse("Antibody titer units" %in% names(.data), !is.na(`Antibody titer units`), FALSE), - ifelse( - `Antibody titer units` < min_titer, - paste0("<", format(min_titer, nsmall = 2)), - as.character(format(round(`Antibody titer units`, 2), nsmall = 2)) - ), - "---" - ) - ), - ifelse( - ifelse("NAB interpreted per sample result" %in% names(.data), - `NAB interpreted per sample result` == 1, FALSE - ), - "*", - "" - ) - ) - ) - - out <- adab_x |> - select(USUBJID, VISN, AVAL, PTES) |> - tidyr::pivot_wider( - names_from = VISN, - values_from = AVAL - ) |> - select(USUBJID, unique(adab_x$VISN[order(adab_x$NFRLT)]), PTES) - - var_labels(out) <- names(out) - - out <- out |> - var_relabel( - USUBJID = "Subject ID", - PTES = "Patient Treatment\nEmergent ADA Status" - ) - - result <- as_listing( - out, - key_cols = "USUBJID", - disp_cols = names(out), - main_title = paste0( - "Listing of Anti-", drugcd, " Antibody Data for Treatment Emergent ADA Positive Patients, PK Population", - "\nProtocol: ", unique(adab$PARCAT1)[1] - ), - subtitles = paste("\nTreatment Group:", trt), - main_footer = "Minimum reportable titer = 1.10 (example only) ---- = No sample evaluated -ADA = Anti-Drug Antibodies (is also referred to as ATA, or Anti-Therapeutic Antibodies) -Number of patients positive for Treatment Emergent ADA = the number of post-baseline evaluable patients determined to -have treatment-induced ADA or treatment-enhanced ADA during the study period. Treatment-induced ADA = a patient with -negative or missing baseline ADA result(s) and at least one positive post-baseline ADA result. -Treatment-enhanced ADA = a patient with positive ADA result at baseline who has one or more post-baseline titer -results that are at least 0.60 t.u. greater than the baseline titer result. -Transient ADA = ADA positive result detected (a) at only one post-baseline sampling timepoint (excluding last -timepoint) OR (b) at 2 or more timepoints during treatment where the first and last ADA positive samples are -separated by a period of < 16 weeks, irrespective of any negative samples in between. -Persistent ADA = ADA positive result detected (a) at the last post-baseline sampling timepoint, OR (b) at 2 or more -time points during treatment where the first and last ADA positive samples are separated by a period ≥ 16 weeks, -irrespective of any negative samples in between. -Asterisk denotes sample that tested positive for Neutralizing Antibodies." - ) |> head(50) - - testthat::expect_snapshot(result) -}) diff --git a/tests/testthat/test-listing_ael01.R b/tests/testthat/test-listing_ael01.R deleted file mode 100644 index 4eb2ea8d..00000000 --- a/tests/testthat/test-listing_ael01.R +++ /dev/null @@ -1,21 +0,0 @@ -testthat::test_that("AEL01 listing is produced correctly", { - out <- adae_raw %>% - select(AESOC, AEDECOD, AELLT, AETERM) %>% - unique() - - var_labels(out) <- c( - AESOC = "MedDRA System Organ Class", - AEDECOD = "MedDRA Preferred Term", - AELLT = "MedDRA Lowest Level Term", - AETERM = "Investigator-Specified\nAdverse Event Term" - ) - - result <- as_listing( - out, - key_cols = c("AESOC", "AEDECOD", "AELLT"), - disp_cols = names(out), - main_title = "Listing of Preferred Terms, Lowest Level Terms, and Investigator-Specified Adverse Event Terms" - ) %>% head(50) - - testthat::expect_snapshot(result) -}) diff --git a/tests/testthat/test-listing_ael01_nollt.R b/tests/testthat/test-listing_ael01_nollt.R deleted file mode 100644 index 414106c9..00000000 --- a/tests/testthat/test-listing_ael01_nollt.R +++ /dev/null @@ -1,24 +0,0 @@ -testthat::test_that("AEL01_NOLLT listing is produced correctly", { - out <- adae_raw %>% - select(AESOC, AEDECOD, AETERM) %>% - unique() - - var_labels(out) <- c( - AESOC = "MedDRA System Organ Class", - AEDECOD = "MedDRA Preferred Term", - AETERM = "Investigator-Specified\nAdverse Event Term" - ) - - result <- as_listing( - out, - key_cols = c("AESOC", "AEDECOD"), - disp_cols = names(out), - default_formatting = list( - all = fmt_config(align = "left"), - numeric = fmt_config(align = "center") - ), - main_title = "Listing of Preferred Terms and Investigator-Specified Adverse Event Terms" - ) %>% head(50) - - testthat::expect_snapshot(result) -}) diff --git a/tests/testthat/test-listing_ael02.R b/tests/testthat/test-listing_ael02.R deleted file mode 100644 index e601134f..00000000 --- a/tests/testthat/test-listing_ael02.R +++ /dev/null @@ -1,61 +0,0 @@ -testthat::test_that("AEL02 listing is produced correctly", { - out <- adae_raw %>% - mutate( - CPID = paste(SITEID, SUBJID, sep = "/"), - ASR = paste(AGE, SEX, RACE, sep = "/"), - Date_First = toupper(format(as.Date(TRTSDTM), "%d%b%Y")), - Duration = AENDY - ASTDY + 1, - Serious = ifelse(AESER == "Y", "Yes", ifelse(AESER == "N", "No", "")), - Related = ifelse(AEREL == "Y", "Yes", ifelse(AEREL == "N", "No", "")), - Outcome = case_when( - AEOUT == "FATAL" ~ 1, - AEOUT == "NOT RECOVERED/NOT RESOLVED" ~ 2, - AEOUT == "RECOVERED/RESOLVED" ~ 3, - AEOUT == "RECOVERED/RESOLVED WITH SEQUELAE" ~ 4, - AEOUT == "RECOVERING/RESOLVING" ~ 5, - AEOUT == "UNKNOWN" ~ 6 - ), - Treated = ifelse(AECONTRT == "Y", "Yes", ifelse(AECONTRT == "N", "No", "")), - Action = case_when( - AEACN == "DOSE INCREASED" ~ 1, - AEACN == "DOSE NOT CHANGED" ~ 2, - AEACN == "DOSE REDUCED" | AEACN == "DOSE RATE REDUCED" ~ 3, - AEACN == "DRUG INTERRUPTED" ~ 4, - AEACN == "DRUG WITHDRAWN" ~ 5, - AEACN == "NOT APPLICABLE" | AEACN == "NOT EVALUABLE" ~ 6, - AEACN == "UNKNOWN" ~ 7 - ) - ) %>% - select(CPID, ASR, TRT01A, AEDECOD, Date_First, ASTDY, Duration, Serious, AESEV, Related, Outcome, Treated, Action) - - var_labels(out) <- c( - CPID = "Center/Patient ID", - ASR = "Age/Sex/Race", - TRT01A = "Treatment", - AEDECOD = "Adverse\nEvent MedDRA\nPreferred Term", - Date_First = "Date of\nFirst Study\nDrug\nAdministration", - ASTDY = "Study\nDay of\nOnset", - Duration = "AE\nDuration\nin Days", - Serious = "Serious", - AESEV = "Most\nExtreme\nIntensity", - Related = "Caused by\nStudy\nDrug", - Outcome = "Outcome\n(1)", - Treated = "Treatment\nfor AE", - Action = "Action\nTaken\n(2)" - ) - - result <- as_listing( - out, - key_cols = c("TRT01A", "CPID", "ASR"), - disp_cols = names(out), - main_title = "Listing of Adverse Events", - main_footer = "(1) Outcome: 1 = fatal; 2 = not recovered/not resolved; 3 = recovered/resolved; - 4 = recovered/resolved with sequelae; 5 = recovering/resolving; 6 = unknown. -(2) Action taken with study drug: 1 = dose increased; 2 = dose not changed; 3 = dose reduced; 4 = drug interrupted; -5 = drug withdrawn; 6 = not applicable; 7 = unknown. -* Study day derived from imputed onset date. -** Duration derived from imputed onset date and/or end date." - ) %>% head(50) - - testthat::expect_snapshot(result) -}) diff --git a/tests/testthat/test-listing_ael02_ed.R b/tests/testthat/test-listing_ael02_ed.R deleted file mode 100644 index 51ce3d19..00000000 --- a/tests/testthat/test-listing_ael02_ed.R +++ /dev/null @@ -1,78 +0,0 @@ -testthat::test_that("AEL02_ED listing is produced correctly", { - adae_anl <- adae_raw %>% - filter(SAFFL == "Y") %>% - mutate( - DHM = as.period(LDOSEDTM %--% ASTDTM), - TMOM = minute(DHM) + ifelse(second(DHM) >= 30, 1, 0), - TMOH = hour(DHM) + ifelse(TMOM == 60, 1, 0), - TMOD = day(DHM) + ifelse(TMOH == 24, 1, 0) - ) %>% - mutate( - TMOM = TMOM %% 60, - TMOH = TMOH %% 24 - ) - - out <- adae_anl %>% - mutate( - ADURN = AENDY - ASTDY + 1, - cent_subj = paste(SITEID, SUBJID, sep = "/"), - ASR = paste(AGE, SEX, RACE, sep = "/"), - AESER_F = if_else(AESER == "Y", "Yes", "No", ""), - AEREL_F = if_else(AEREL == "Y", "Yes", "No", ""), - AECONTRT_F = if_else(AECONTRT == "Y", "Yes", "No", ""), - AEOUT_F = case_when( - AEOUT == "FATAL" ~ 1, - AEOUT == "NOT RECOVERED/NOT RESOLVED" ~ 2, - AEOUT == "RECOVERED/RESOLVED" ~ 3, - AEOUT == "RECOVERED/RESOLVED WITH SEQUELAE" ~ 4, - AEOUT == "RECOVERING/RESOLVING" ~ 5, - AEOUT == "UNKNOWN" ~ 6 - ), - AEACN_F = case_when( - AEACN == "DOSE INCREASED" ~ 1, - AEACN == "DOSE NOT CHANGED" ~ 2, - AEACN == "DOSE REDUCED" | AEACN == "DOSE RATE REDUCED" ~ 3, - AEACN == "DRUG INTERRUPTED" ~ 4, - AEACN == "DRUG WITHDRAWN" ~ 5, - AEACN == "NOT APPLICABLE" | AEACN == "NOT EVALUABLE" ~ 6, - AEACN == "UNKNOWN" ~ 7 - ) - ) %>% - select( - cent_subj, ASR, TRT01A, AEDECOD, ASTDY, TMOD, TMOH, TMOM, - ADURN, AESER_F, AESEV, AEREL_F, AEOUT_F, AECONTRT_F, AEACN_F - ) - - var_labels(out) <- c( - cent_subj = "Center/Patient ID", - ASR = "Age/Sex/Race", - TRT01A = "Treatment", - AEDECOD = "Adverse\nEvent MedDRA\nPreferred Term", - ASTDY = "Study\nDay of\nOnset", - TMOD = "Time from\nLast Dose\nto Onset\ndays", - TMOH = "Time from\nLast Dose\nto Onset\nhrs", - TMOM = "Time from\nLast Dose\nto Onset\nmins", - ADURN = "AE\nDuration\nin Days", - AESER_F = "Serious", - AESEV = "Most\nExtreme\nIntensity", - AEREL_F = "Caused by\nStudy\nDrug", - AEOUT_F = "Outcome\n(1)", - AECONTRT_F = "Treatment\nfor AE", - AEACN_F = "Action\nTaken\n(2)" - ) - - result <- as_listing( - out, - key_cols = c("TRT01A", "cent_subj", "ASR"), - disp_cols = names(out), - main_title = "Listing of Adverse Events (for early development studies)", - main_footer = "(1) Outcome: 1 = fatal; 2 = not recovered/not resolved; 3 = recovered/resolved; - 4 = recovered/resolved with sequelae; 5 = recovering/resolving; 6 = unknown. -(2) Action taken with study drug: 1 = dose increased; 2 = dose not changed; 3 = dose reduced; 4 = drug interrupted; - 5 = drug withdrawn; 6 = not applicable; 7 = unknown. -* Study day derived from imputed onset date. -** Duration derived from imputed onset date and/or end date." - ) %>% head(50) - - testthat::expect_snapshot(result) -}) diff --git a/tests/testthat/test-listing_ael03.R b/tests/testthat/test-listing_ael03.R deleted file mode 100644 index c920d70f..00000000 --- a/tests/testthat/test-listing_ael03.R +++ /dev/null @@ -1,74 +0,0 @@ -testthat::test_that("AEL03 listing is produced correctly", { - out <- adae_raw %>% - filter(AESER == "Y") %>% - mutate( - CPID = paste(SITEID, SUBJID, sep = "/"), - ASR = paste(AGE, SEX, RACE, sep = "/"), - Date_First = toupper(format(as.Date(TRTSDTM), "%d%b%Y")), - Duration = AENDY - ASTDY + 1, - Related = ifelse(AEREL == "Y", "Yes", ifelse(AEREL == "N", "No", "")), - Outcome = case_when( - AEOUT == "FATAL" ~ 1, - AEOUT == "NOT RECOVERED/NOT RESOLVED" ~ 2, - AEOUT == "RECOVERED/RESOLVED" ~ 3, - AEOUT == "RECOVERED/RESOLVED WITH SEQUELAE" ~ 4, - AEOUT == "RECOVERING/RESOLVING" ~ 5, - AEOUT == "UNKNOWN" ~ 6 - ), - Treated = ifelse(AECONTRT == "Y", "Yes", ifelse(AECONTRT == "N", "No", "")), - Action = case_when( - AEACN == "DOSE INCREASED" ~ 1, - AEACN == "DOSE NOT CHANGED" ~ 2, - AEACN == "DOSE REDUCED" | AEACN == "DOSE RATE REDUCED" ~ 3, - AEACN == "DRUG INTERRUPTED" ~ 4, - AEACN == "DRUG WITHDRAWN" ~ 5, - AEACN == "NOT APPLICABLE" | AEACN == "NOT EVALUABLE" ~ 6, - AEACN == "UNKNOWN" ~ 7 - ), - SERREAS = case_when( - AESDTH == "Y" ~ "1", - AESLIFE == "Y" ~ "2", - AESHOSP == "Y" ~ "3", - AESDISAB == "Y" ~ "4", - AESCONG == "Y" ~ "5", - AESMIE == "Y" ~ "6", - TRUE ~ " " - ) - ) %>% - select(CPID, ASR, TRT01A, AEDECOD, Date_First, ASTDY, Duration, AESEV, Related, Outcome, Treated, Action, SERREAS) - - var_labels(out) <- c( - CPID = "Center/Patient ID", - ASR = "Age/Sex/Race", - TRT01A = "Treatment", - AEDECOD = "Adverse\nEvent MedDRA\nPreferred Term", - Date_First = "Date of\nFirst Study\nDrug\nAdministration", - ASTDY = "Study\nDay of\nOnset", - Duration = "AE\nDuration\nin Days", - AESEV = "Most\nExtreme\nIntensity", - Related = "Caused by\nStudy\nDrug", - Outcome = "Outcome\n(1)", - Treated = "Treatment\nfor AE", - Action = "Action\nTaken\n(2)", - SERREAS = "Reason\nClassified\nas Serious\n(3)" - ) - - result <- as_listing( - out, - key_cols = c("TRT01A", "CPID", "ASR"), - disp_cols = names(out), - main_title = "Listing of Serious Adverse Events", - main_footer = "(1) Outcome: 1 = fatal; 2 = not recovered/not resolved; 3 = recovered/resolved; - 4 = recovered/resolved with sequelae; 5 = recovering/resolving; 6 = unknown. -(2) Action taken with study drug: 1 = dose increased; 2 = dose not changed; 3 = dose reduced; 4 = drug interrupted; - 5 = drug withdrawn; 6 = not applicable; 7 = unknown. -(3) Reason classified as serious: 1 = resulted in death; 2 = life threatening; 3 = required prolonged in patient - hospitalization; 4 = disabling; 5 = a congenital anomaly/birth defect in offspring of study subject; - 6 = does not meet any of the above serious criteria, but may jeopardize the subject, and may require medical or - surgical intervention to prevent one of the outcomes listed above. -* Study day derived from imputed onset date. -** Duration derived from imputed onset date and/or end date." - ) %>% head(50) - - testthat::expect_snapshot(result) -}) diff --git a/tests/testthat/test-listing_ael04.R b/tests/testthat/test-listing_ael04.R deleted file mode 100644 index f6102232..00000000 --- a/tests/testthat/test-listing_ael04.R +++ /dev/null @@ -1,31 +0,0 @@ -testthat::test_that("AEL04 listing is produced correctly", { - out <- adsl_raw %>% - filter(!is.na(DTHADY)) %>% - mutate( - ID = paste(SITEID, SUBJID, sep = "/"), - AGSXRC = paste(AGE, SEX, RACE, sep = "/"), - TRTSD = toupper(format(as.Date(TRTSDTM), "%d%b%Y")) - ) %>% - arrange(SUBJID) %>% - select(ID, AGSXRC, TRT01A, TRTSD, EOSDY, DTHADY, DTHCAUS, ADTHAUT) - - var_labels(out) <- c( - ID = "Center/Patient ID", - AGSXRC = "Age/Sex/Race", - TRT01A = "Treatment", - TRTSD = "Date of First\nStudy Drug\nAdministration", - EOSDY = "Day of Last\nStudy Drug\nAdministration", - DTHADY = "Day of\nDeath", - DTHCAUS = "Cause of Death", - ADTHAUT = "Autopsy\nPerformed?" - ) - - result <- as_listing( - out, - key_cols = c("TRT01A", "ID"), - disp_cols = names(out), - main_title = "Listing of Patient Deaths" - ) %>% head(50) - - testthat::expect_snapshot(result) -}) diff --git a/tests/testthat/test-listing_cml01.R b/tests/testthat/test-listing_cml01.R deleted file mode 100644 index 07f94380..00000000 --- a/tests/testthat/test-listing_cml01.R +++ /dev/null @@ -1,42 +0,0 @@ -testthat::test_that("CML01 listing is produced correctly", { - out <- adcm_pharmaverse %>% - filter(!is.na(CMDECOD)) %>% - mutate( - ID = paste(SITEID, SUBJID, sep = "/"), - AGSXRC = paste(AGE, SEX, RACE, sep = "/"), - TRTSD = toupper(format(as.Date(TRTSDTM), "%d%b%Y")), - CMASTD = toupper(format(as.Date(ASTDTM), "%d%b%Y")), - CMSTRFL = ifelse(ASTDY < 0, "Yes", "No"), - CMENRFL = ifelse(CMENRTPT == "ONGOING", "Yes", "No") - ) %>% - select( - ID, AGSXRC, TRT01A, CMDECOD, TRTSD, CMASTD, ASTDY, ADURN, - CMSTRFL, CMENRFL, CMDOSE, CMDOSU, CMDOSFRQ, CMROUTE - ) - - var_labels(out) <- c( - ID = "Center/Patient ID", - AGSXRC = "Age/Sex/Race", - TRT01A = "Treatment", - CMDECOD = "Medication Name", - TRTSD = "Date of First\nStudy Drug\nAdministration", - CMASTD = "Medication\nStart Date", - ASTDY = "Study Day", - ADURN = "Duration\n(days)", - CMSTRFL = "Previous?", - CMENRFL = "Ongoing\nat Final\nContact?", - CMDOSE = "Dose", - CMDOSU = "Dose Unit", - CMDOSFRQ = "Frequency", - CMROUTE = "Route" - ) - - result <- as_listing( - out, - key_cols = c("TRT01A", "ID", "AGSXRC", "CMDECOD"), - disp_cols = names(out), - main_title = "Listing of Previous and Concomitant Medications" - ) %>% head(50) - - testthat::expect_snapshot(result) -}) diff --git a/tests/testthat/test-listing_cml02a_gl.R b/tests/testthat/test-listing_cml02a_gl.R deleted file mode 100644 index 0ef1bf90..00000000 --- a/tests/testthat/test-listing_cml02a_gl.R +++ /dev/null @@ -1,20 +0,0 @@ -testthat::test_that("CML02A_GL listing is produced correctly", { - out <- adcm_pharmaverse %>% - select(ATC2, CMDECOD, CMTRT) %>% - unique() - - var_labels(out) <- c( - ATC2 = "ATC Class Level 2", - CMDECOD = "WHODrug Preferred Name", - CMTRT = "Investigator-Specified\nTreatment Term" - ) - - result <- as_listing( - out, - key_cols = c("ATC2", "CMDECOD", "CMTRT"), - disp_cols = names(out), - main_title = "Listing of Concomitant Medication Class Level 2, Preferred Name, and Investigator-Specified Terms" - ) %>% head(50) - - testthat::expect_snapshot(result) -}) diff --git a/tests/testthat/test-listing_cml02b_gl.R b/tests/testthat/test-listing_cml02b_gl.R deleted file mode 100644 index 1eebdc62..00000000 --- a/tests/testthat/test-listing_cml02b_gl.R +++ /dev/null @@ -1,23 +0,0 @@ -testthat::test_that("CML02B_GL listing is produced correctly", { - out <- adcm_pharmaverse %>% - select(ATC1, ATC2, ATC3, ATC4, CMDECOD, CMTRT) %>% - unique() - - var_labels(out) <- c( - ATC1 = "ATC Class Level 1", - ATC2 = "ATC Class Level 2", - ATC3 = "ATC Class Level 3", - ATC4 = "ATC Class Level 4", - CMDECOD = "WHODrug Preferred Name", - CMTRT = "Investigator-Specified\nTreatment Term" - ) - - result <- as_listing( - out, - key_cols = c("ATC1", "ATC2", "ATC3", "ATC4", "CMDECOD", "CMTRT"), - disp_cols = names(out), - main_title = "Listing of Concomitant Medication Class, Preferred Name, and Investigator-Specified Terms" - ) %>% head(50) - - testthat::expect_snapshot(result) -}) diff --git a/tests/testthat/test-listing_dsl01.R b/tests/testthat/test-listing_dsl01.R deleted file mode 100644 index 750195a1..00000000 --- a/tests/testthat/test-listing_dsl01.R +++ /dev/null @@ -1,32 +0,0 @@ -testthat::test_that("DSL01 listing is produced correctly", { - out <- adsl_raw %>% - mutate( - ID = paste(SITEID, SUBJID, sep = "/"), - ASR = paste(AGE, SEX, RACE, sep = "/"), - SSADM = toupper(format(as.Date(TRTSDTM), format = "%d%b%Y")), - STDWD = as.numeric(ceiling(difftime(TRTEDTM, TRTSDTM, units = "days"))), - DISCONT = ifelse(!is.na(DCSREAS) & toupper(EOSSTT) == "DISCONTINUED", "Yes", "No") - ) %>% - select(ID, ASR, ARMCD, SSADM, STDWD, DISCONT) - - var_labels(out) <- c( - ID = "Center/Patient ID", - ASR = "Age/Sex/Race", - ARMCD = "Treatment", - SSADM = "Date of First\nStudy Drug\nAdministration", - STDWD = "Study Day\nof Withdrawal", - DISCONT = "Discontinued\nEarly from Study?" - ) - - result <- as_listing( - out, - key_cols = "ARMCD", - disp_cols = names(out), - main_title = "Listing of Patients with Study Drug Withdrawn Due to Adverse Events", - subtitles = "Population: All Patients", - main_footer = c("Program: xxxx", "Output: xxxx"), - prov_footer = "Page 1 of 1" - ) %>% head(50) - - testthat::expect_snapshot(result) -}) diff --git a/tests/testthat/test-listing_dsl02.R b/tests/testthat/test-listing_dsl02.R deleted file mode 100644 index 4b65df10..00000000 --- a/tests/testthat/test-listing_dsl02.R +++ /dev/null @@ -1,34 +0,0 @@ -testthat::test_that("DSL02 listing is produced correctly", { - out <- adsl_raw %>% - filter(AEWITHFL == "Y") %>% - mutate( - ID = paste(SITEID, SUBJID, sep = "/"), - ASR = paste(AGE, SEX, RACE, sep = "/"), - DISCONT = ifelse(!is.na(DCSREAS) & EOSSTT != "COMPLETED", "Yes", "No"), - SSADTM = as.Date(TRTSDTM, tz = "UTC"), - SSAEDY = as.numeric(ceiling(difftime(EOSDT, SSADTM, units = "days"))), - RANDEDY = as.numeric(ceiling(difftime(EOSDT, RANDDT, units = "days"))), - ) %>% - filter(DISCONT == "Yes") %>% - select(ID, ASR, TRT01A, SSADTM, EOSDY, SSAEDY, RANDEDY, DCSREAS) - - var_labels(out) <- c( - ID = "Center/Patient ID", - ASR = "Age/Sex/Race", - TRT01A = "Treatment", - SSADTM = "Date of First\nStudy Drug\nAdministration", - EOSDY = "Day of Last\nStudy Drug\nAdministration", - SSAEDY = "Day of Study\nDiscontinuation\nRelative to First\nStudy Drug\nAdministration", - RANDEDY = "Day of Study\nDiscontinuation\nRelative to\nRandomization", - DCSREAS = "Reason for\nDiscontinuation" - ) - - result <- as_listing( - out, - key_cols = "TRT01A", - disp_cols = names(out), - main_title = "Listing of Patients Who Discontinued Early from Study" - ) %>% head(50) - - testthat::expect_snapshot(result) -}) diff --git a/tests/testthat/test-listing_dsur4.R b/tests/testthat/test-listing_dsur4.R deleted file mode 100644 index eee0813d..00000000 --- a/tests/testthat/test-listing_dsur4.R +++ /dev/null @@ -1,23 +0,0 @@ -testthat::test_that("DSUR4 listing is produced correctly", { - out <- adsl_raw %>% - filter(DTHFL == "Y") %>% - mutate(ID = paste(SITEID, SUBJID, sep = "/")) %>% - select(ARM, ID, DTHCAUS) - death_num <- length(unique(out$ID)) - - var_labels(out) <- c( - ARM = "Treatment Group", - ID = "Center/Patient ID", - DTHCAUS = "Cause of Death" - ) - - result <- as_listing( - out, - key_cols = c("ARM"), - disp_cols = names(out), - main_title = "Listing of Patients Who Died During Reporting Period", - subtitles = paste("Number of patient deaths during reporting period =", death_num) - ) %>% head(50) - - testthat::expect_snapshot(result) -}) diff --git a/tests/testthat/test-listing_egl01.R b/tests/testthat/test-listing_egl01.R deleted file mode 100644 index 52084528..00000000 --- a/tests/testthat/test-listing_egl01.R +++ /dev/null @@ -1,62 +0,0 @@ -testthat::test_that("EGL01 listing is produced correctly", { - get_param_unit_range <- function(dataset) { - u_rng <- lapply(unique(dataset$PARAMCD), function(p) { - dat <- dataset %>% filter(PARAMCD == p) - list( - unit = unique(dat$EGSTRESU), - range = paste0(unique(dat$ANRLO), "-", unique(dat$ANRHI)) - ) - }) - names(u_rng) <- unique(dataset$PARAMCD) - u_rng - } - - eg_u_rng <- get_param_unit_range(adeg_pharmaverse) - - adeg_sub <- adeg_pharmaverse %>% - filter(!is.na(AVAL) & SAFFL == "Y" & ANL01FL == "Y" & !is.na(ASEQ) & PARAMCD != "EGINTP" & DTYPE == "AVERAGE") %>% - mutate( - CRTNPT = paste(SITEID, sub("^.*-([[:alnum:]]+)$", "\\1", SUBJID), sep = "/"), - AGSXRC = paste(AGE, SEX, RACE, sep = "/"), - AVAL = format(round(AVAL, 2), nsmall = 2), - AVAL_ANRIND = ifelse(ANRIND %in% c("NORMAL", ""), AVAL, paste(AVAL, substr(ANRIND, 1, 1), sep = "/")), - CHG = format(round(CHG, 2), nsmall = 2) - ) - - anl_eg <- adeg_sub %>% - select(SUBJID, CRTNPT, AGSXRC, TRT01A, PARAMCD, AVAL_ANRIND, CHG, ADY, AVISIT, ADTM) %>% - tidyr::pivot_wider( - id_cols = c(SUBJID, CRTNPT, AGSXRC, TRT01A, ADY, AVISIT, ADTM), - names_from = PARAMCD, - values_from = c(AVAL_ANRIND, CHG) - ) - - out <- anl_eg %>% - select( - CRTNPT, AGSXRC, TRT01A, AVISIT, ADY, AVAL_ANRIND_HR, CHG_HR, AVAL_ANRIND_QT, CHG_QT, AVAL_ANRIND_RR, CHG_RR - ) %>% - var_relabel( - CRTNPT = "Center/Subject ID", - AGSXRC = "Age/Sex/Race", - TRT01A = "Treatment", - AVISIT = "Visit", - ADY = "Study\nDay", - AVAL_ANRIND_HR = paste0("Heart Rate Result\n(", eg_u_rng$HR$unit[1], ");\nRange:(", eg_u_rng$HR$range[1], ")"), - CHG_HR = "Heart Rate\nChange from BL", - AVAL_ANRIND_QT = paste0("QT Duration Result\n(", eg_u_rng$QT$unit[1], ");\nRange:(", eg_u_rng$QT$range[1], ")"), - CHG_QT = "QT Duration\nChange from BL", - AVAL_ANRIND_RR = paste0("RR Duration Result\n(", eg_u_rng$RR$unit[1], ");\nRange:(", eg_u_rng$RR$range[1], ")"), - CHG_RR = "RR Duration\nChange from BL" - ) - - result <- as_listing( - out, - key_cols = c("TRT01A", "CRTNPT", "AGSXRC", "AVISIT", "ADY"), - disp_cols = names(out), - main_title = "Listing of ECG Data: Safety-Evaluable Patients", - main_footer = "Baseline is the patient's last observation prior to initiation of study drug. Abnormalities are - flagged as high (H) or low (L) if outside the Roche standard reference range." - ) %>% head(50) - - testthat::expect_snapshot(result) -}) diff --git a/tests/testthat/test-listing_exl01.R b/tests/testthat/test-listing_exl01.R deleted file mode 100644 index 34ab24ac..00000000 --- a/tests/testthat/test-listing_exl01.R +++ /dev/null @@ -1,30 +0,0 @@ -testthat::test_that("EXL01 listing is produced correctly", { - out <- adex_pharmaverse %>% - filter(PARAMCD == "DOSE" & !is.na(AVAL) & SAFFL == "Y") %>% - mutate( - CRTNPT = paste(SITEID, SUBJID, sep = "/") - ) %>% - arrange(CRTNPT, VISIT) %>% - select(CRTNPT, VISIT, EXSTDY, EXENDY, TRT01A, AVAL, AVALU, EXDOSFRQ, EXROUTE) - - var_labels(out) <- c( - CRTNPT = "Center/Subject ID", - VISIT = "Visit", - EXSTDY = "Study Day\nFrom", - EXENDY = "Study Day\nTo", - TRT01A = "Treatment", - AVAL = "Dose", - AVALU = "Unit", - EXDOSFRQ = "Frequency", - EXROUTE = "Route" - ) - - result <- as_listing( - out, - key_cols = c("TRT01A", "CRTNPT", "VISIT"), - disp_cols = names(out), - main_title = "Listing of Exposure to Study Drug" - ) %>% head(50) - - testthat::expect_snapshot(result) -}) diff --git a/tests/testthat/test-listing_lbl01.R b/tests/testthat/test-listing_lbl01.R deleted file mode 100644 index 61c4a96c..00000000 --- a/tests/testthat/test-listing_lbl01.R +++ /dev/null @@ -1,53 +0,0 @@ -testthat::test_that("LBL01 listing is produced correctly", { - adlb_x <- adlb_pharmaverse %>% - filter(!is.na(AVAL) & !is.na(LBSEQ) & !is.na(ADY) & ANRIND != "") %>% - mutate( - CPID = paste(SITEID, SUBJID, sep = "/"), - PARAM_U = paste0(PARAMCD, "\n(", AVALU, " / NCI CTCAE grade)"), - ANRIND = factor( - case_when( - ANRIND == "LOW" ~ "L", - ANRIND == "HIGH" ~ "H", - TRUE ~ as.character(ANRIND) - ), - levels = c("", "H", "L", "NORMAL") - ), - AVALC = as.character(format(round(AVAL, 2), nsmall = 2)) - ) %>% - mutate(AVAL_GR = ifelse( - !ANRIND %in% c("H", "L"), AVALC, - paste(AVALC, paste0(ANRIND, sub("-", "", ATOXGR)), sep = " / ") - )) %>% - select(CPID, TRT01A, ADY, LBSEQ, PARAM_U, AVAL_GR) %>% - unique() - - out <- adlb_x %>% - arrange(CPID, ADY, PARAM_U, LBSEQ) %>% - tidyr::pivot_wider( - id_cols = c(TRT01A, CPID, ADY), - names_from = PARAM_U, - values_from = AVAL_GR - ) %>% - group_by(CPID) %>% - mutate(DLD = ADY - lag(ADY)) %>% - ungroup() %>% - select(CPID, TRT01A, ADY, DLD, unique(adlb_x$PARAM_U)) - - var_labels(out) <- names(out) - out <- out %>% var_relabel( - TRT01A = "Treatment", - CPID = "Center/Patient ID", - ADY = "Study\nDay", - DLD = "Days Since\nLast Dose of\nStudy Drug" - ) - - result <- as_listing( - out, - key_cols = c("TRT01A", "CPID"), - disp_cols = names(out), - main_title = "Listing of Laboratory Test Results", - main_footer = "NCI CTCAE grade is displayed as abnormal high (H) or low (L) followed by the grade." - ) %>% head(50) - - testthat::expect_snapshot(result) -}) diff --git a/tests/testthat/test-listing_lbl01_rls.R b/tests/testthat/test-listing_lbl01_rls.R deleted file mode 100644 index 9e6d7533..00000000 --- a/tests/testthat/test-listing_lbl01_rls.R +++ /dev/null @@ -1,59 +0,0 @@ -testthat::test_that("LBL01_RLS listing is produced correctly", { - adlb_x <- adlb_pharmaverse %>% - mutate(ANRIND = factor( - case_when( - ANRIND == "LOW" & AVAL > stats::quantile(adlb_raw$AVAL, probs = c(0.1)) ~ "L", - ANRIND == "HIGH" & AVAL < stats::quantile(adlb_raw$AVAL, probs = c(0.9)) ~ "H", - ANRIND == "LOW" & AVAL <= stats::quantile(adlb_raw$AVAL, probs = c(0.1)) ~ "LL", - ANRIND == "HIGH" & AVAL >= stats::quantile(adlb_raw$AVAL, probs = c(0.9)) ~ "HH", - TRUE ~ as.character(ANRIND) - ), - levels = c("", "H", "HH", "L", "LL", "NORMAL") - )) - - adlb_x <- adlb_x %>% - filter(!is.na(LBSEQ) & !is.na(ADY) & ANRIND != "") %>% - mutate( - CPID = paste(SITEID, SUBJID, sep = "/"), - PARAM_U = paste0(PARAMCD, "\n(", AVALU, ")"), - AVALC = as.character(format(round(AVAL, 2), nsmall = 2)) - ) %>% - mutate(AVAL_GR = ifelse( - !ANRIND %in% c("H", "HH", "L", "LL"), AVALC, - paste(AVALC, ANRIND, sep = " / ") - )) %>% - select(CPID, TRT01A, ADY, LBSEQ, PARAM_U, AVAL_GR) %>% - unique() - - out <- adlb_x %>% - arrange(CPID, ADY, PARAM_U, LBSEQ) %>% - tidyr::pivot_wider( - id_cols = c(TRT01A, CPID, ADY), - names_from = PARAM_U, - values_from = AVAL_GR - ) %>% - group_by(CPID) %>% - mutate(DLD = ADY - lag(ADY)) %>% - ungroup() %>% - select(CPID, TRT01A, ADY, DLD, unique(adlb_x$PARAM_U)) - - var_labels(out) <- names(out) - out <- out %>% var_relabel( - TRT01A = "Treatment", - CPID = "Center/Patient ID", - ADY = "Study\nDay", - DLD = "Days Since\nLast Dose of\nStudy Drug" - ) - - result <- as_listing( - out, - key_cols = c("TRT01A", "CPID"), - disp_cols = names(out), - main_title = "Listing of Laboratory Test Results Using Roche Safety Lab Standardization", - main_footer = "Abnormalities are flagged as high (H) or low (L) if outside the Roche standard reference range; - high high (HH) or low low (LL) if outside the Roche marked reference range with a clinically relevant change - from baseline." - ) %>% head(50) - - testthat::expect_snapshot(result) -}) diff --git a/tests/testthat/test-listing_lbl02a.R b/tests/testthat/test-listing_lbl02a.R deleted file mode 100644 index c193589f..00000000 --- a/tests/testthat/test-listing_lbl02a.R +++ /dev/null @@ -1,51 +0,0 @@ -testthat::test_that("LBL02A listing is produced correctly", { - adlb_x <- adlb_pharmaverse %>% - filter(ANRIND %in% c("LOW", "HIGH"), !ATOXGR %in% c("0", ""), LBTEST != "") %>% - mutate( - LBTEST_U = paste0(LBTEST, " (", AVALU, ")"), - CPID = paste(SITEID, SUBJID, sep = "/"), - ADTM = ADT, # no ADTM in pharmaverse::adlb - ADTM = toupper(format(as.Date(ADTM), "%d%b%Y")), - AVAL = format(round(AVAL, 1), nsmall = 1), - LBNRNG = paste(format(round(ANRLO, 1), nsmall = 1), format(round(ANRHI, 1), nsmall = 1), sep = " - "), - ANRIND_GR = factor( - case_when( - ANRIND == "LOW" ~ paste0("L", sub("-", "", ATOXGR)), - ANRIND == "HIGH" ~ paste0("H", ATOXGR) - ) - ) - ) %>% - select(LBTEST_U, TRT01A, CPID, ADY, ADTM, AVAL, ADY, LBNRNG, ANRIND_GR) %>% - unique() %>% - arrange(CPID, ADY) %>% - group_by(LBTEST_U, CPID) %>% - mutate(DLD = ADY - lag(ADY)) %>% - ungroup() %>% - mutate(DLD = ifelse(is.na(DLD), 0, DLD)) - - out <- adlb_x %>% - select(LBTEST_U, TRT01A, CPID, ADY, ADTM, DLD, AVAL, LBNRNG, ANRIND_GR) - - var_labels(out) <- names(out) - out <- out %>% var_relabel( - LBTEST_U = "Lab Test (Unit)", - TRT01A = "Treatment", - CPID = "Center/Patient ID", - ADY = "Study\nDay", - ADTM = "Date", - DLD = "Days Since\nLast Dose of\nStudy Drug", - AVAL = "Result", - LBNRNG = "Lab Normal\nRange", - ANRIND_GR = "NCI\nCTCAE\nGrade" - ) - - result <- as_listing( - out, - key_cols = c("TRT01A", "LBTEST_U", "CPID"), - disp_cols = names(out), - main_title = "Listing of Laboratory Abnormalities Defined by NCI CTCAE Grade >= 1", - main_footer = "NCI CTCAE grade is displayed as abnormal high (H) or low (L) followed by the grade." - ) %>% head(50) - - testthat::expect_snapshot(result) -}) diff --git a/tests/testthat/test-listing_lbl02a_rls.R b/tests/testthat/test-listing_lbl02a_rls.R deleted file mode 100644 index d7df62ef..00000000 --- a/tests/testthat/test-listing_lbl02a_rls.R +++ /dev/null @@ -1,80 +0,0 @@ -testthat::test_that("LBL02A_RLS listing is produced correctly", { - adlb_x <- adlb_pharmaverse %>% - filter( - LBTEST != "" - ) %>% - mutate( - LBTEST_U = paste0(LBTEST, " (", AVALU, ")"), - CPID = paste(SITEID, SUBJID, sep = "/") - ) %>% - mutate(CRC = paste("40%", "40%", sep = " / ")) - - std_rng <- adlb_x %>% - group_by(LBTEST_U) %>% - summarise( - STD_RNG_LO = stats::quantile(AVAL, probs = c(0.1), na.rm = TRUE), - STD_RNG_HI = stats::quantile(AVAL, probs = c(0.9), na.rm = TRUE) - ) %>% - ungroup() - - adlb_x <- adlb_x %>% - left_join(std_rng, by = "LBTEST_U") %>% - mutate( - AVAL = format(round(AVAL, 1), nsmall = 1), - PCHG = format(round(PCHG, 1), nsmall = 1), - LBNRNG = paste(ANRLO, ANRHI, sep = " - "), - STD_RNG_LO = format(round(STD_RNG_LO, 1), nsmall = 1), - STD_RNG_HI = format(round(STD_RNG_HI, 1), nsmall = 1) - ) %>% - mutate( - STD_RNG = paste(STD_RNG_LO, STD_RNG_HI, sep = " - "), - ANRIND = factor(case_when( - ANRIND == "LOW" & AVAL > STD_RNG_LO ~ "L", - ANRIND == "HIGH" & AVAL < STD_RNG_HI ~ "H", - ANRIND == "LOW" & AVAL <= STD_RNG_LO ~ "LL", - ANRIND == "HIGH" & AVAL >= STD_RNG_HI ~ "HH", - TRUE ~ "" - )) - ) %>% - select(LBTEST_U, TRT01A, CPID, ADY, AVAL, PCHG, STD_RNG, LBNRNG, CRC, ANRIND) %>% - unique() %>% - arrange(CPID, ADY) %>% - group_by(LBTEST_U, CPID) %>% - mutate(DLD = ADY - lag(ADY)) %>% - ungroup() %>% - mutate(DLD = ifelse(is.na(DLD), 0, DLD)) - - out <- adlb_x %>% - select(LBTEST_U, TRT01A, CPID, ADY, DLD, AVAL, PCHG, STD_RNG, LBNRNG, CRC, ANRIND) - - var_labels(out) <- names(out) - out <- out %>% - var_relabel( - LBTEST_U = "Lab Test (Unit)", - TRT01A = "Treatment", - CPID = "Center/Patient ID", - ADY = "Study\nDay", - DLD = "Days Since\nLast Dose of\nStudy Drug", - AVAL = "Result", - PCHG = "% Change\nfrom\nBaseline", - STD_RNG = "Standard\nReference\nRange", - LBNRNG = "Marked\nReference\nRange", - CRC = "Clinically\nRelevant\nChange\nDec./Inc.", - ANRIND = "Abnormality\nFlag" - ) - - result <- as_listing( - out, - key_cols = c("TRT01A", "LBTEST_U", "CPID"), - disp_cols = names(out), - main_title = "Listing of Laboratory Abnormalities Defined by Roche Safety Lab Standardization", - main_footer = paste( - "Standard reference range, marked reference range and clinically relevant change from baseline are from the", - "Roche Safety Lab Standardization guideline. Abnormalities are flagged as high (H) or low (L) if outside", - "the standard reference range; high high (HH) or low low (LL) if outside the marked reference range with a", - "clinically relevant change from baseline." - ) - ) %>% head(50) - - testthat::expect_snapshot(result) -}) diff --git a/tests/testthat/test-listing_lbl02b.R b/tests/testthat/test-listing_lbl02b.R deleted file mode 100644 index 202efdd3..00000000 --- a/tests/testthat/test-listing_lbl02b.R +++ /dev/null @@ -1,57 +0,0 @@ -testthat::test_that("LBL02B listing is produced correctly", { - adlb_x <- adlb_pharmaverse %>% - filter( - !sub("-", "", ATOXGR) %in% c("", "0", "1"), - LBTEST != "", - !is.na(ADY), - !ANRIND %in% c("", "NORMAL") - ) %>% - mutate( - CPID = paste(SITEID, SUBJID, sep = "/"), - ADTM = ADT, - ADTM = toupper(format(as.Date(ADTM), "%d%b%Y")), - AVAL = format(round(AVAL, 1), nsmall = 1), - LBNRNG = paste(format(round(ANRLO, 1), nsmall = 1), format(round(ANRHI, 1), nsmall = 1), sep = " - "), - ANRIND_GR = factor( - case_when( - ANRIND == "LOW" ~ paste0("L", sub("-", "", ATOXGR)), - ANRIND == "HIGH" ~ paste0("H", ATOXGR) - ) - ) - ) %>% - select(LBTEST, TRT01A, CPID, ADY, ADTM, AVAL, AVALU, LBNRNG, ANRIND_GR) %>% - unique() %>% - arrange(CPID, ADY) %>% - group_by(LBTEST, CPID) %>% - mutate(DLD = ADY - lag(ADY)) %>% - ungroup() %>% - mutate(DLD = ifelse(is.na(DLD), 0, DLD)) - - out <- adlb_x %>% - select(LBTEST, TRT01A, CPID, ADY, ADTM, DLD, AVAL, AVALU, LBNRNG, ANRIND_GR) - - var_labels(out) <- names(out) - out <- out %>% - var_relabel( - LBTEST = "Lab Test", - TRT01A = "Treatment", - CPID = "Center/Patient ID", - ADY = "Study\nDay", - ADTM = "Date", - DLD = "Days Since\nLast Dose of\nStudy Drug", - AVAL = "Result", - AVALU = "Unit", - LBNRNG = "Lab Normal\nRange", - ANRIND_GR = "NCI\nCTCAE\nGrade" - ) - - result <- as_listing( - out, - key_cols = c("TRT01A", "LBTEST", "CPID"), - disp_cols = names(out), - main_title = "Listing of Laboratory Abnormalities Defined by NCI CTCAE Grade >= 2", - main_footer = "NCI CTCAE grade is displayed as abnormal high (H) or low (L) followed by the grade." - ) %>% head(50) - - testthat::expect_snapshot(result) -}) diff --git a/tests/testthat/test-listing_mhl01.R b/tests/testthat/test-listing_mhl01.R deleted file mode 100644 index b0c52bd2..00000000 --- a/tests/testthat/test-listing_mhl01.R +++ /dev/null @@ -1,34 +0,0 @@ -testthat::test_that("MHL01 listing is produced correctly", { - out <- admh_raw %>% - mutate( - ASR = paste(AGE, SEX, RACE, sep = "/"), - ID = paste(SITEID, SUBJID, sep = "/"), - TRTSDTM = toupper(format(as.Date(TRTSDTM), "%d%b%Y")), - ASTDTM = toupper(format(as.Date(ASTDTM), "%d%b%Y")), - AENDTM = toupper(format(as.Date(AENDTM), "%d%b%Y")) - ) %>% - select(ID, ASR, TRT01A, MHBODSYS, MHDECOD, TRTSDTM, ASTDTM, ASTDY, AENDTM, AENDY, ATIREL) - - var_labels(out) <- c( - ID = "Center/Patient ID", - ASR = "Age/Sex/Race", - TRT01A = "Treatment", - MHBODSYS = "SOC", - MHDECOD = "Disease Term", - TRTSDTM = "Date of First\nStudy Drug\nAdministration", - ASTDTM = "Start Date\nof Disease", - ASTDY = "Start Day\nof Disease", - AENDTM = "End Date\nof Disease", - AENDY = "End Day\nof Disease", - ATIREL = "Time Relation\nof Disease" - ) - - result <- as_listing( - out, - key_cols = c("TRT01A", "ID", "ASR", "MHBODSYS", "MHDECOD"), - disp_cols = names(out), - main_title = "Listing of Medical History and Concurrent Diseases" - ) %>% head(50) - - testthat::expect_snapshot(result) -}) diff --git a/tests/testthat/test-listing_oncl01.R b/tests/testthat/test-listing_oncl01.R deleted file mode 100644 index 46239dfe..00000000 --- a/tests/testthat/test-listing_oncl01.R +++ /dev/null @@ -1,62 +0,0 @@ -testthat::test_that("ONCL01 listing is produced correctly", { - out_ex <- adex_raw %>% - filter(PARAMCD == "TNDOSE") %>% - mutate(ID = paste(SITEID, SUBJID, sep = "/")) %>% - select(ID, AVAL) - - out_rs <- adrs_raw %>% - filter( - PARAM %in% c("Investigator End Of Induction Response", "Best Confirmed Overall Response by Investigator") - ) %>% - mutate(ID = paste(SITEID, SUBJID, sep = "/")) %>% - select(ID, AVALC, PARAM) %>% - tidyr::pivot_wider( - id_cols = ID, - names_from = PARAM, - values_from = AVALC - ) %>% - right_join(out_ex, ., by = "ID", multiple = "all") - - adtte_flt <- adtte_raw %>% - filter(PARAMCD %in% c("OS", "PFS", "CRSD")) %>% - mutate( - PARAM = paste(PARAM, paste0("(", AVALU, ")"), sep = " "), ID = paste(SITEID, SUBJID, sep = "/"), - trigeventpfs = ifelse(CNSR == 0, EVNTDESC, NA) - ) - - out_trg <- adtte_flt %>% select(ID, trigeventpfs) - - out_tte <- adtte_flt %>% - select(ID, TRT01A, PARAM, AVAL, trigeventpfs) %>% - tidyr::pivot_wider( - id_cols = c(ID, TRT01A), - names_from = PARAM, - values_from = AVAL - ) %>% - mutate_at( - c("Overall Survival (DAYS)", "Progression Free Survival (DAYS)", "Duration of Confirmed Response (DAYS)"), - function(x) format(round(x, 1), nsmall = 1) - ) %>% - select( - ID, TRT01A, `Overall Survival (DAYS)`, `Progression Free Survival (DAYS)`, `Duration of Confirmed Response (DAYS)` - ) %>% - right_join(out_trg, ., by = "ID", multiple = "all") - - out <- out_tte %>% - right_join(out_rs, ., by = "ID", multiple = "all") %>% - select( - "ID", "TRT01A", "AVAL", "Best Confirmed Overall Response by Investigator", - "Investigator End Of Induction Response", "Overall Survival (DAYS)", - "Progression Free Survival (DAYS)", "trigeventpfs", "Duration of Confirmed Response (DAYS)" - ) - - result <- as_listing( - out, - key_cols = c("TRT01A", "ID"), - disp_cols = names(out), - main_title = "Listing of Individual Efficacy Data", - main_footer = "PFS = Progression Free Survival" - ) %>% head(50) - - testthat::expect_snapshot(result) -}) diff --git a/tests/testthat/test-listing_pkcl01.R b/tests/testthat/test-listing_pkcl01.R deleted file mode 100644 index 91dbc33e..00000000 --- a/tests/testthat/test-listing_pkcl01.R +++ /dev/null @@ -1,57 +0,0 @@ -testthat::test_that("PKCL01 listing is produced correctly", { - adpc <- adpc_pharmaverse - analyte <- "Pharmacokinetic concentration of Xanomeline" - out <- adpc %>% - filter(PARAM == analyte) %>% - select(ARM, USUBJID, VISIT, NFRLT, AFRLT, AVAL) - - var_labels(out) <- c( - ARM = "Treatment Group", - USUBJID = "Subject ID", - VISIT = "Visit", - NFRLT = paste0("Nominal Sampling\nTime (hr)"), - AFRLT = paste0("Actual Time\nFrom First\nDose (hr)"), - AVAL = paste0("Concentration\n(", adpc$AVALU[1], ")") - ) - - result <- as_listing( - out, - key_cols = c("ARM", "USUBJID", "VISIT"), - disp_cols = names(out), - main_title = paste( - "Listing of", analyte, "Concentration by Treatment Group, Subject and Nominal Time,", - "PK Population\nProtocol: xxnnnnn" - ), - subtitles = paste("Analyte:", analyte) - ) %>% head(50) - - testthat::expect_snapshot(result) -}) - -testthat::test_that("PKCL01 listing key columns values are repeated when entries span multiple pages", { - adpc <- adpc_pharmaverse - out <- adpc %>% - select(TRT01A, USUBJID, VISIT, NFRLT, AFRLT, AVAL) - - var_labels(out) <- c( - TRT01A = "Treatment Group", - USUBJID = "Subject ID", - VISIT = "Visit", - NFRLT = paste0("Nominal Sampling\nTime (", adpc$FRLTU[1], ")"), - AFRLT = paste0("Actual Time\nFrom First\nDose (", adpc$FRLTU[1], ")"), - AVAL = paste0("Concentration\n(", adpc$AVALU[1], ")") - ) - - out <- out %>% - arrange(TRT01A, USUBJID, NFRLT) - - result <- as_listing( - out, - key_cols = c("TRT01A", "USUBJID", "VISIT"), - disp_cols = names(out) - ) %>% - head(50) %>% - export_as_txt(tf_wrap = TRUE, cpp = 120, lpp = 30) - - testthat::expect_snapshot(result %>% cat()) -}) diff --git a/tests/testthat/test-listing_pkcl02.R b/tests/testthat/test-listing_pkcl02.R deleted file mode 100644 index 91c00147..00000000 --- a/tests/testthat/test-listing_pkcl02.R +++ /dev/null @@ -1,63 +0,0 @@ -testthat::test_that("PKCL02 listing is produced correctly", { - drug_a <- "XANOMELINE" - spec <- "URINE" - adpc <- adpc_pharmaverse - adpc_x <- adpc %>% - mutate(REGIMEN = ifelse("REGIMEN" %in% names(adpc), REGIMEN, "BID")) %>% - filter( - TRT01A == "Xanomeline High Dose", - PCTEST == drug_a, - PARCAT1 == spec - ) - - out <- adpc_x %>% - tidyr::pivot_longer( - cols = c(AVAL), - names_to = "URCD", - values_to = "VALUE" - ) %>% - mutate( - URCD = case_when( - URCD == "AVAL" ~ "UR_Conc", - TRUE ~ URCD - ), - UNIT = case_when( - URCD == "UR_Conc" ~ as.character(AVALU), - TRUE ~ "NA" - ) - ) %>% - mutate( - PARAM_INT = paste0( - URCD, " (", UNIT, ") -\nUrine Collection\nInterval", - ifelse(PCTPT == "Predose", "", " (hours)"), ":\n", - gsub("[PTH]", "", PCTPT) - ) - ) %>% - select(TRT01A, USUBJID, VISIT, PARAM_INT, VALUE) %>% - unique() %>% - tidyr::pivot_wider( - id_cols = c(TRT01A, USUBJID, VISIT), - names_from = PARAM_INT, - values_from = VALUE - ) - - var_labels(out) <- names(out) - out <- out %>% var_relabel( - TRT01A = "Treatment Group", - USUBJID = "Subject ID", - VISIT = "Visit" - ) - - result <- as_listing( - out, - key_cols = c("TRT01A", "USUBJID", "VISIT"), - disp_cols = names(out), - main_title = paste0( - "Listing of ", drug_a, " Urine Concentration and Volumes following ", - unique(adpc_x$REGIMEN)[1], " of ", drug_a, ", PK Population\nProtocol: xxnnnnn" - ), - subtitles = paste("Analyte:", drug_a) - ) %>% head(50) - - testthat::expect_snapshot(result) -}) diff --git a/tests/testthat/test-listing_pkpl01.R b/tests/testthat/test-listing_pkpl01.R deleted file mode 100644 index 98920125..00000000 --- a/tests/testthat/test-listing_pkpl01.R +++ /dev/null @@ -1,39 +0,0 @@ -testthat::test_that("PKPL01 listing is produced correctly", { - drug_a <- "Xanomeline Low Dose" - spec <- "PLASMA" - adpp <- adpp_pharmaverse - adpp_x <- adpp %>% filter( - ARM == drug_a, - PPSPEC == spec - ) - - # tmp solution - adpp_x$AVISIT <- rep(c("visit 1", "visit 2", "visit 3")) - - out <- adpp_x %>% - mutate(PARAM = paste0(PARAMCD, " (", PPORRESU, ")")) %>% - select(TRT01A, USUBJID, AVISIT, PARAM, AVAL) %>% - unique() %>% # This is a temp fix, as avisit was added this way - tidyr::pivot_wider( - id_cols = c(TRT01A, USUBJID, AVISIT), - names_from = PARAM, - values_from = AVAL - ) - - var_labels(out) <- names(out) - out <- out %>% var_relabel( - TRT01A = "Treatment Group", - USUBJID = "Subject ID", - AVISIT = "Visit" - ) - - result <- as_listing( - out, - key_cols = c("TRT01A", "USUBJID", "AVISIT"), - disp_cols = names(out), - main_title = paste("Listing of", drug_a, spec, "PK Parameters, PK Population\nProtocol: xxnnnnn"), - subtitles = paste("Analyte:", drug_a) - ) %>% head(50) - - testthat::expect_snapshot(result) -}) diff --git a/tests/testthat/test-listing_pkpl02.R b/tests/testthat/test-listing_pkpl02.R deleted file mode 100644 index 7cf4fc06..00000000 --- a/tests/testthat/test-listing_pkpl02.R +++ /dev/null @@ -1,38 +0,0 @@ -testthat::test_that("PKPL02 listing is produced correctly", { - drug_a <- "XANOMELINE" - spec <- "URINE" - adpp <- adpp_pharmaverse - adpp_x <- adpp %>% - mutate(REGIMEN = ifelse("REGIMEN" %in% names(adpp), REGIMEN, "BID")) %>% - filter( - PPCAT == drug_a, - PPSPEC == spec - ) - - out <- adpp_x %>% - mutate(PARAM = paste0(PPTEST, " (", AVALU, ")")) %>% - select(TRT01A, USUBJID, AVISIT, PARAM, AVAL) %>% - unique() %>% - tidyr::pivot_wider( - id_cols = c(TRT01A, USUBJID, AVISIT), - names_from = PARAM, - values_from = AVAL - ) - - var_labels(out) <- names(out) - out <- out %>% var_relabel( - TRT01A = "Treatment Group", - USUBJID = "Subject ID", - AVISIT = "Visit" - ) - - result <- as_listing( - out, - key_cols = c("TRT01A", "USUBJID", "AVISIT"), - disp_cols = names(out), - main_title = paste("Listing of", drug_a, spec, "PK Parameters, PK Population\nProtocol: xxnnnnn"), - subtitles = paste("Analyte:", drug_a) - ) %>% head(50) - - testthat::expect_snapshot(result) -}) diff --git a/tests/testthat/test-listing_pkpl04.R b/tests/testthat/test-listing_pkpl04.R deleted file mode 100644 index 42f9b50d..00000000 --- a/tests/testthat/test-listing_pkpl04.R +++ /dev/null @@ -1,53 +0,0 @@ -testthat::test_that("PKPL04 listing is produced correctly", { - adpp <- adpp_pharmaverse - visit <- "Day 1" - drug_a <- "Xanomeline Low Dose" - drug_b <- "Xanomeline High Dose" - - adpp_x <- adpp %>% - filter( - AVISIT == visit, - TRT01A %in% c(drug_a, drug_b), - PARAMCD %in% c("CMAX", "AUCALL") - ) %>% - mutate( - PARAM_U = paste0(PPTEST, " (", AVALU, ")") - ) %>% - select(USUBJID, PARAM_U, TRT01A, AVAL) %>% - unique() - - adpp_ratio <- adpp_x %>% - tidyr::pivot_wider( - id_cols = c(USUBJID, PARAM_U), - names_from = TRT01A, - values_from = AVAL - ) - - adpp_ratio[, paste0(drug_a, "/", drug_b)] <- as.numeric(unlist(adpp_ratio[, drug_a] / adpp_ratio[, drug_b])) - - out <- adpp_ratio %>% - tidyr::pivot_wider( - id_cols = USUBJID, - names_from = PARAM_U, - names_glue = "{PARAM_U}\n{.value}", - values_from = c(all_of(drug_a), all_of(drug_b), paste0(drug_a, "/", drug_b)) - ) %>% - select(names(.)[c(1:2, 4, 6, 3, 5, 7)]) - - var_labels(out) <- names(out) - out <- out %>% var_relabel(USUBJID = "Subject ID") - - result <- as_listing( - out, - key_cols = "USUBJID", - disp_cols = names(out), - main_title = paste0( - "Listing of Individual ", drug_a, " ", paste(unique(adpp_x$PARAM_U), collapse = " and "), " Ratios following ", - unique(adpp_x$REGIMEN), " ", paste(drug_a, drug_b, sep = " or "), ", PK Population\nProtocol: xxnnnnn", - "\nVisit: ", unique(adpp_x$AVISIT) - ), - subtitles = paste0("\nAnalytes: ", paste(drug_a, drug_b, sep = " and ")) - ) %>% head(50) - - testthat::expect_snapshot(result) -}) diff --git a/tests/testthat/test-listing_vsl01.R b/tests/testthat/test-listing_vsl01.R deleted file mode 100644 index a54259dc..00000000 --- a/tests/testthat/test-listing_vsl01.R +++ /dev/null @@ -1,84 +0,0 @@ -testthat::test_that("VSL01 listing is produced correctly", { - get_param_unit_range <- function(dataset) { - u_rng <- lapply(unique(dataset$PARAMCD), function(p) { - dat <- dataset %>% filter(PARAMCD == p) - list( - unit = unique(dat$AVALU), - range = paste0(unique(dat$ANRLO), "-", unique(dat$ANRHI)) - ) - }) - names(u_rng) <- unique(dataset$PARAMCD) - u_rng - } - vs_u_rng <- get_param_unit_range(advs_raw) - - advs_sub <- advs_raw %>% - filter(!is.na(AVAL) & SAFFL == "Y" & !is.na(VSSEQ)) %>% - mutate( - CRTNPT = paste(SITEID, sub("^.*-([[:alnum:]]+)$", "\\1", SUBJID), sep = "/"), - AGSXRC = paste(AGE, SEX, RACE, sep = "/"), - AVAL = format(round(AVAL, 2), nsmall = 2), - AVAL_ANRIND = ifelse(ANRIND %in% c("NORMAL", ""), AVAL, paste(AVAL, substr(ANRIND, 1, 1), sep = "/")), - CHG = format(round(CHG, 2), nsmall = 2) - ) - - anl_vs <- advs_sub %>% - select(SUBJID, CRTNPT, AGSXRC, TRT01A, PARAMCD, AVAL_ANRIND, CHG, ADY, AVISIT, ADTM) %>% - tidyr::pivot_wider( - id_cols = c(SUBJID, CRTNPT, AGSXRC, TRT01A, ADY, AVISIT, ADTM), - names_from = PARAMCD, - values_from = c(AVAL_ANRIND, CHG) - ) - - out <- anl_vs %>% - select( - CRTNPT, AGSXRC, TRT01A, AVISIT, ADY, AVAL_ANRIND_WEIGHT, CHG_WEIGHT, AVAL_ANRIND_TEMP, CHG_TEMP, - AVAL_ANRIND_DIABP, CHG_DIABP, AVAL_ANRIND_SYSBP, CHG_SYSBP, AVAL_ANRIND_PULSE, CHG_PULSE, - AVAL_ANRIND_RESP, CHG_RESP - ) %>% - var_relabel( - CRTNPT = "Center/Subject ID", - AGSXRC = "Age/Sex/Race", - TRT01A = "Treatment", - AVISIT = "Visit", - ADY = "Study\nDay", - AVAL_ANRIND_WEIGHT = paste0( - "Weight\nResult\n(", vs_u_rng$WEIGHT$unit, ");\nRange:(", - vs_u_rng$WEIGHT$range, ")" - ), - CHG_WEIGHT = "Weight\nChange from BL", - AVAL_ANRIND_TEMP = paste0("Temperature Result\n(", vs_u_rng$TEMP$unit, ");\nRange:(", vs_u_rng$TEMP$range, ")"), - CHG_TEMP = "Temperature Rate\nChange from BL", - AVAL_ANRIND_DIABP = paste0( - "Diastolic Blood\nPressure,\nSitting\nResult\n(", vs_u_rng$DIABP$unit, - ");\nRange:(", vs_u_rng$DIABP$range, ")" - ), - CHG_DIABP = "Diastolic Blood\nPressure,\nSitting\nChange from BL", - AVAL_ANRIND_SYSBP = paste0( - "Systolic Blood\nPressure,\nSitting\n(", vs_u_rng$SYSBP$unit, ");\nRange:(", - vs_u_rng$SYSBP$range, ")" - ), - CHG_SYSBP = "Systolic Blood\nPressure,\nSitting\nChange from BL", - AVAL_ANRIND_PULSE = paste0( - "Pulse Rate Result\n(", vs_u_rng$PULSE$unit, ");\nRange:(", - vs_u_rng$PULSE$range, ")" - ), - CHG_PULSE = "Pulse Rate\nChange from BL", - AVAL_ANRIND_RESP = paste0( - "Respiratory Rate\nResult\n(", vs_u_rng$RESP$unit, ");\nRange:(", - vs_u_rng$RESP$range, ")" - ), - CHG_RESP = "Respiratory Rate\nChange from BL" - ) - - result <- as_listing( - out, - key_cols = c("TRT01A", "CRTNPT", "AGSXRC", "AVISIT"), - disp_cols = names(out), - main_title = "Listing of Vital Signs: Safety-Evaluable Patients", - main_footer = "Baseline is the patient's last observation prior to initiation of study drug. Abnormalities are -flagged as high (H) or low (L) if outside the Roche standard reference range." - ) %>% head(50) - - testthat::expect_snapshot(result) -}) diff --git a/tests/testthat/test-pagination_listing.R b/tests/testthat/test-pagination_listing.R deleted file mode 100644 index 027431ef..00000000 --- a/tests/testthat/test-pagination_listing.R +++ /dev/null @@ -1,157 +0,0 @@ -# Using ael03 with minor modifications to test pagination for listings - -# Data pre-processing -result <- adae_raw %>% - filter(AESER == "Y") %>% - mutate( - CPID = paste(SITEID, SUBJID, sep = "/"), - ASR = paste(AGE, SEX, RACE, sep = "/"), - Date_First = toupper(format(as.Date(TRTSDTM), "%d%b%Y")), - Duration = AENDY - ASTDY + 1, - Related = ifelse(AEREL == "Y", "Yes", ifelse(AEREL == "N", "No", "")), - Outcome = case_when( - AEOUT == "FATAL" ~ 1, - AEOUT == "NOT RECOVERED/NOT RESOLVED" ~ 2, - AEOUT == "RECOVERED/RESOLVED" ~ 3, - AEOUT == "RECOVERED/RESOLVED WITH SEQUELAE" ~ 4, - AEOUT == "RECOVERING/RESOLVING" ~ 5, - AEOUT == "UNKNOWN" ~ 6 - ), - Treated = ifelse(AECONTRT == "Y", "Yes", ifelse(AECONTRT == "N", "No", "")), - Action = case_when( - AEACN == "DOSE INCREASED" ~ 1, - AEACN == "DOSE NOT CHANGED" ~ 2, - AEACN == "DOSE REDUCED" | AEACN == "DOSE RATE REDUCED" ~ 3, - AEACN == "DRUG INTERRUPTED" ~ 4, - AEACN == "DRUG WITHDRAWN" ~ 5, - AEACN == "NOT APPLICABLE" | AEACN == "NOT EVALUABLE" ~ 6, - AEACN == "UNKNOWN" ~ 7 - ), - SERREAS = case_when( - AESDTH == "Y" ~ "1", - AESLIFE == "Y" ~ "2", - AESHOSP == "Y" ~ "3", - AESDISAB == "Y" ~ "4", - AESCONG == "Y" ~ "5", - AESMIE == "Y" ~ "6", - TRUE ~ " " - ) - ) %>% - select(CPID, ASR, TRT01A, AEDECOD, Date_First, ASTDY, Duration, AESEV, Related, Outcome, Treated, Action, SERREAS) - -# Adding labels -var_labels(result) <- c( - CPID = "Center/Patient ID", - ASR = "Age/Sex/Race", - TRT01A = "Treatment", - AEDECOD = "Adverse\nEvent MedDRA\nPreferred Term", - Date_First = "Date of\nFirst Study\nDrug\nAdministration", - ASTDY = "Study\nDay of\nOnset", - Duration = "AE\nDuration\nin Days", - AESEV = "Most\nExtreme\nIntensity", - Related = "Caused by\nStudy\nDrug", - Outcome = "Outcome\n(1)", - Treated = "Treatment\nfor AE", - Action = "Action\nTaken\n(2)", - SERREAS = "Reason\nClassified\nas Serious\n(3)" -) - -# Creating the list -lst_res <- as_listing( - result, - key_cols = c("CPID", "ASR", "TRT01A"), - disp_cols = names(result), - main_title = "Listing of Serious Adverse Events", - subtitles = c("Some long subtitles that should eventually be split if wrapping is there", "maybe"), - main_footer = "(1) Outcome: 1 = fatal; 2 = not recovered/not resolved; 3 = recovered/resolved; - 4 = recovered/resolved with sequelae; 5 = recovering/resolving; 6 = unknown. -(2) Action taken with study drug: 1 = dose increased; 2 = dose not changed; 3 = dose reduced; 4 = drug interrupted; - 5 = drug withdrawn; 6 = not applicable; 7 = unknown. -(3) Reason classified as serious: 1 = resulted in death; 2 = life threatening; 3 = required prolonged in patient - hospitalization; 4 = disabling; 5 = a congenital anomaly/birth defect in offspring of study subject; - 6 = does not meet any of the above serious criteria, but may jeopardize the subject, and may require medical or - surgical intervention to prevent one of the outcomes listed above. -* Study day derived from imputed onset date. -** Duration derived from imputed onset date and/or end date.", - prov_footer = "Do we need referential footnotes? Still not as the main ref notes are in the labels, conveniently." -) %>% head(50) - -testthat::test_that("Direct pagination works fine", { - testthat::expect_equal(nrow(lst_res), 50) # head() worked - - clw <- propose_column_widths(lst_res) / 2 + 1 - - pg_lst <- testthat::expect_silent( - paginate_listing(lst_res, lpp = 50, colwidths = floor(clw), print_pages = FALSE) - ) - testthat::expect_equal(length(pg_lst), 10L) - - pg_lst <- paginate_listing(lst_res, page_type = "a4", font_size = 9, print_pages = FALSE) - testthat::expect_equal(length(pg_lst), 7L) - - testthat::expect_silent( # for footers \n - export_as_txt(lst_res, page_type = "a4", font_size = 9) - ) -}) - - -testthat::test_that("pagination counts the right number of lines when wrapping on keycols is present", { - adae <- pharmaverseadam::adae %>% - select(AESOC, AEDECOD, AETERM) %>% - unique() - - var_labels(adae) <- c( - AESOC = "MedDRA System Organ Class", - AEDECOD = "MedDRA Preferred Term", - AETERM = "Investigator-Specified Adverse Event Term" - ) - - lsting <- as_listing( - adae, - key_cols = c("AESOC", "AEDECOD"), - disp_cols = names(adae), - main_title = "Glossary of Adverse Event Preferred Terms and Investigator-Specified Adverse Event Terms", - subtitles = "Protocal xxx", - main_footer = "Investigator text for AEs is coded using MedDRA version 26.1.", - prov_footer = "blah blah blah" - ) - - pagination_test1 <- testthat::expect_silent( - export_as_txt(lsting, - colwidths = c(150, 38, 70), - cpp = 400, lpp = 35, tf_wrap = FALSE, page_break = "\f" - ) - ) - spl_pag_test1 <- strsplit(pagination_test1, "\\f")[[1]] - testthat::expect_equal(length(spl_pag_test1), 11) - testthat::expect_true( - all( - sapply(spl_pag_test1[-length(spl_pag_test1)], function(x) { - length(strsplit(x, "\\n")[[1]]) == 35 - }) - ) - ) - testthat::expect_equal( - length(strsplit(spl_pag_test1[length(spl_pag_test1)], "\\n")[[1]]), - 16 - ) - - pagination_test2 <- testthat::expect_silent( - export_as_txt(lsting, - colwidths = c(48, 38, 70), cpp = 180, lpp = 35, tf_wrap = TRUE, page_break = "\f" - ) - ) - spl_pag_test2 <- strsplit(pagination_test2, "\\f")[[1]] - testthat::expect_equal(length(spl_pag_test2), 11) - testthat::expect_true( - all( - sapply(spl_pag_test2[-length(spl_pag_test2)], function(x) { - length(strsplit(x, "\\n")[[1]]) == 35 - }) - ) - ) - testthat::expect_equal( - length(strsplit(spl_pag_test2[length(spl_pag_test2)], "\\n")[[1]]), - 19 - ) -}) diff --git a/tests/testthat/test-pagination_table.R b/tests/testthat/test-pagination_table.R deleted file mode 100644 index 14ff69bb..00000000 --- a/tests/testthat/test-pagination_table.R +++ /dev/null @@ -1,218 +0,0 @@ -# All of these tests are based on AET04 variant 1 and mainly concern pagination, -# i.e. paginate_table and its parameters. - -# Data pre-processing -adsl <- adsl_raw -adae <- adae_raw %>% - dplyr::mutate( - AEDECOD = as.character(AEDECOD), - AEBODSYS = as.character(AEBODSYS), - ) -gr_grp <- list( - "- Any Grade -" = c("1", "2", "3", "4", "5"), - "Grade 1-2" = c("1", "2"), - "Grade 3-4" = c("3", "4"), - "Grade 5" = "5" -) - -# Raw result for future pruning -raw_result <- basic_table() %>% - split_cols_by("ACTARM") %>% - add_colcounts() %>% - count_occurrences_by_grade( - var = "AETOXGR", - grade_groups = gr_grp - ) %>% - split_rows_by("AEBODSYS", - split_fun = trim_levels_in_group("AETOXGR"), - child_labels = "visible", nested = TRUE - ) %>% - summarize_occurrences_by_grade( - var = "AETOXGR", - grade_groups = gr_grp - ) %>% - split_rows_by("AEDECOD", - split_fun = trim_levels_in_group("AETOXGR"), - child_labels = "visible", nested = TRUE - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = "unique", - .labels = "- Any Grade -" - ) %>% - count_occurrences_by_grade( - var = "AETOXGR", - grade_groups = gr_grp[-1], - .indent_mods = -1L - ) %>% - build_table(adae, alt_counts_df = adsl) %>% - sort_at_path( - path = "AEBODSYS", - scorefun = cont_n_allcols, - decreasing = TRUE - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEDECOD"), - scorefun = cont_n_allcols, - decreasing = TRUE - ) - -testthat::test_that("Direct pagination with standard values", { - # Standard, direct call - pag_res <- testthat::expect_silent(paginate_table(raw_result, font_size = 12)) - testthat::expect_equal(sapply(pag_res, nrow), c(55, 22)) - testthat::expect_equal(sapply(pag_res, ncol), c(3, 3)) -}) - -testthat::test_that("Pagination with specific column widths and minimum lines per page", { - # With combo of rows and cols per page - std_col_widths <- propose_column_widths(raw_result) - # Min h-width: first value is the row label, second is the largest content, 3 is the inter-space - cpp_width <- std_col_widths[1] + max(std_col_widths[-1]) + 3 - pag_res <- testthat::expect_silent( - paginate_table(raw_result, cpp = cpp_width, lpp = 13) # 13 is the minimum -> automatic way? - ) - testthat::expect_equal(length(pag_res), 11 * 3) # 11 because 3 branches (out of 8) have 2 leaves - testthat::expect_snapshot(pag_res[9:10]) # randomly picked to have a comparison -}) - -# More decoration -res <- raw_result -main_title(res) <- "main title with some new \nline" -subtitles(res) <- c("sub", "-------", "titles") -main_footer(res) <- "main footer" -prov_footer(res) <- "prov \nfooter that has a lot of \nnew \nlines" -top_left(res) <- "SOME TOPLEFT" -table_inset(res) <- 5 -fnotes_at_path( - res, - c(make_row_df(res)$path[[7]]), - c("B: Placebo") # nolint -) <- "Some notes" - -testthat::test_that("Pagination works also if table is decorated", { - clw <- c(10, 8, 8, 10) # random values to have "some" wrapping - - # Std calculations for minimum lpp - # title (2) + subtitle (3) + empty line (1) + div (1) + header (3) + - # + nrows (x) + ref footnote (3) + footer (1+2 empty lines) + prov footer (4) - testthat::expect_silent(paginate_table(raw_result, lpp = 13)) - testthat::expect_error(suppressMessages(paginate_table(raw_result, lpp = 12))) - # base is: 20 + x [x from paginate_table(raw_result) is min 13 - 3 (header)] - # -> 30 - # for pagination with decoration and no wrapping we expect 27 - lpp_min <- 28 # -2 less because of ref fnotes - cpp_min <- 72 # 70 is the std now, this table is 72 - testthat::expect_silent(paginate_table(res, lpp = lpp_min, cpp = cpp_min)) - testthat::expect_error(suppressMessages(paginate_table(res, lpp = lpp_min - 1, cpp = cpp_min))) - - # for clw above this is 42 (15 more lines due to wrapping) - lpp_min <- 42 - pg_tbl_no_clw <- paginate_table(res, lpp = lpp_min, cpp = cpp_min) - pg_tbl_w_clw <- paginate_table(res, lpp = lpp_min, colwidths = clw, cpp = cpp_min) - testthat::expect_error(paginate_table(res, lpp = lpp_tmp - 1, colwidths = clw, cpp = cpp_min)) - - res1 <- toString(pg_tbl_no_clw[[1]], widths = clw) - res2 <- toString(res[ - 1:21, , # found manually - keep_titles = TRUE, - keep_footers = TRUE, - keep_topleft = TRUE - ], widths = clw) - - testthat::expect_identical(res1, res2) - testthat::expect_equal(length(pg_tbl_no_clw), length(pg_tbl_w_clw) - 7) - - testthat::expect_snapshot(cat(res1)) - - testthat::expect_snapshot(cat(toString(pg_tbl_no_clw[[3]], widths = clw))) - testthat::expect_snapshot(cat(toString(pg_tbl_w_clw[[3]], widths = clw))) -}) - -testthat::test_that("Pagination works for page types", { - # Other parameters: page type - pag_res <- paginate_table(res, page_type = "letter") - testthat::expect_snapshot(sapply(pag_res, nrow)) - testthat::expect_snapshot(pag_res[[2]]) - pag_res <- paginate_table(res, page_type = "a4") - testthat::expect_snapshot(sapply(pag_res, nrow)) - testthat::expect_snapshot(pag_res[[2]]) - pag_res <- paginate_table(res, page_type = "legal") - testthat::expect_snapshot(sapply(pag_res, nrow)) - testthat::expect_snapshot(pag_res[[1]]) -}) - -testthat::test_that("Pagination works for page width and height", { - # Other parameters: page height and width - pag_res <- paginate_table(res, pg_width = 7, pg_height = 10) - testthat::expect_snapshot(sapply(pag_res, nrow)) - testthat::expect_snapshot(pag_res[2]) -}) - -testthat::test_that("Pagination works for page types", { - # Other parameters: all together - pag_res <- paginate_table( - res, - landscape = TRUE, - lineheight = 2, - font_size = 7, - font_family = "Courier", - margins = c(top = 1, bottom = 1, left = 3, right = 3) - ) - testthat::expect_snapshot(sapply(pag_res, nrow)) - testthat::expect_snapshot(pag_res[5:6]) # randomly picked to have a comparison -}) - -testthat::test_that("AET04 variant 2 page_by pagination tests", { - adae <- adae %>% - dplyr::filter(ACTARM == "A: Drug X") %>% - dplyr::mutate(AEBODSYS = factor(AEBODSYS)) - - lyt <- basic_table() %>% - split_cols_by("ACTARM") %>% - add_colcounts() %>% - split_rows_by("AEBODSYS", - split_fun = trim_levels_in_group("AETOXGR"), - child_labels = "visible", nested = TRUE, - page_by = TRUE - ) %>% - summarize_occurrences_by_grade( - var = "AETOXGR", - grade_groups = gr_grp - ) %>% - split_rows_by("AEDECOD", - split_fun = trim_levels_in_group("AETOXGR"), - child_labels = "visible", nested = TRUE - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = "unique", - .labels = "- Any Grade -" - ) %>% - count_occurrences_by_grade( - var = "AETOXGR", - grade_groups = gr_grp[-1], - .indent_mods = -1L - ) - - result <- lyt %>% - build_table(adae, alt_counts_df = adsl) %>% - sort_at_path( - path = "AEBODSYS", - scorefun = cont_n_allcols, - decreasing = TRUE - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEDECOD"), - scorefun = cont_n_allcols, - decreasing = TRUE - ) - - res <- testthat::expect_silent(result) - pag_res <- testthat::expect_silent(paginate_table(res)) - testthat::expect_setequal( - sapply(pag_res, page_titles), - paste0("AEBODSYS: ", levels(adae$AEBODSYS)) - ) - testthat::expect_snapshot(pag_res[c(2, 5)]) # randomly picked to have a comparison -}) diff --git a/tests/testthat/test-table_adat03.R b/tests/testthat/test-table_adat03.R deleted file mode 100644 index e6e00cdf..00000000 --- a/tests/testthat/test-table_adat03.R +++ /dev/null @@ -1,73 +0,0 @@ -adpc <- adpc_raw %>% select(USUBJID, NFRLT, AVAL, AVALU) -anl <- adab_raw %>% - filter(., PARAM == "ADA interpreted per sample result") %>% - select(-AVAL, AVALU) - -anl <- merge(anl, adpc, by = c("USUBJID", "NFRLT")) %>% - mutate(AVAL_LT = ifelse(AVAL <= 15, TRUE, FALSE)) - -# parameters in columns -adat03_stats <- c("n", "mean", "sd", "median", "min", "max", "cv", "geom_mean", "count_fraction") -adat03_lbls <- c( - n = "Total Number\nof Measurable\n Samples", - mean = "Mean", - sd = "SD", - median = "Median", - min = "Minimum", - max = "Maximum", - cv = "CV (%)", - geom_mean = "Geometric Mean", - count_fraction = paste0("Samples with\nConcentration\n≤ 15μg/mL") -) -adat03_fmts <- c( - n = "xx.", - mean = sprintf_format("%.3e"), - sd = sprintf_format("%.3e"), - median = sprintf_format("%.3e"), - min = sprintf_format("%.3e"), - max = sprintf_format("%.3e"), - cv = "xx.x", - geom_mean = sprintf_format("%.3e"), - count_fraction = format_count_fraction -) - -afun_list <- lapply( - 1:9, - function(i) make_afun(s_summary, .stats = adat03_stats[i], .formats = adat03_fmts[i], .labels = "Overall") -) - -testthat::test_that("ADAT03 is produced correctly", { - result <- basic_table() %>% - split_rows_by( - var = "ARM", - label_pos = "topleft", - split_label = "Treatment Group", - split_fun = drop_split_levels, - section_div = "" - ) %>% - add_rowcounts() %>% - split_rows_by( - var = "VISIT", - label_pos = "topleft", - split_label = "Visit", - child_labels = "hidden" - ) %>% - analyze_vars_in_cols( - vars = c(rep("AVAL", 8), "AVAL_LT"), - .stats = adat03_stats, - .labels = adat03_lbls, - .formats = adat03_fmts - ) %>% - analyze_colvars( - afun_list, - nested = FALSE, - extra_args = list(".labels" = "Overall") - ) %>% - build_table(anl, alt_counts_df = adsl_raw) - - fnotes_at_path(result, rowpath = NULL, colpath = c("multivars", "AVAL")) <- "footnote1" # nolint - fnotes_at_path(result, rowpath = NULL, colpath = c("multivars", "AVAL_LT")) <- "footnote2" # nolint - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_aet01.R b/tests/testthat/test-table_aet01.R deleted file mode 100644 index 35fbb3c1..00000000 --- a/tests/testthat/test-table_aet01.R +++ /dev/null @@ -1,311 +0,0 @@ -set.seed(1) -adsl <- adsl_pharmaverse -adae <- adae_pharmaverse - -adsl <- df_explicit_na(adsl) -adae <- df_explicit_na( - adae, - omit_columns = c("SMQ01NAM", "SMQ01SC", "SMQ02NAM", "SMQ02SC", "CQ01NAM", "STUDYID", "USUBJID") -) - -aesdth_tmp <- sample(c("N", "Y"), size = nrow(adae), replace = TRUE, prob = c(0.99, 0.01)) -aeacn_tmp <- sample( - c("DOSE NOT CHANGED", "DOSE INCREASED", "DRUG INTERRUPTED", "DRUG WITHDRAWN"), - size = nrow(adae), - replace = TRUE, prob = c(0.68, 0.02, 0.25, 0.05) -) - -adae <- adae %>% - mutate( - AEDECOD = with_label(as.character(AEDECOD), "Dictionary-Derived Term"), - AESDTH = with_label(aesdth_tmp, "Results in Death"), - AEACN = with_label(aeacn_tmp, "Action Taken with Study Treatment"), - FATAL = with_label(AESDTH == "Y", "AE with fatal outcome"), - SEV = with_label(AESEV == "SEVERE", "Severe AE (at greatest intensity)"), - SER = with_label(AESER == "Y", "Serious AE"), - SERWD = with_label(AESER == "Y" & AEACN == "DRUG WITHDRAWN", "Serious AE leading to withdrawal from treatment"), - SERDSM = with_label( - AESER == "Y" & AEACN %in% c("DRUG INTERRUPTED", "DOSE INCREASED", "DOSE REDUCED"), - "Serious AE leading to dose modification/interruption" - ), - RELSER = with_label(AESER == "Y" & AEREL == "Y", "Related Serious AE"), - WD = with_label(AEACN == "DRUG WITHDRAWN", "AE leading to withdrawal from treatment"), - DSM = with_label( - AEACN %in% c("DRUG INTERRUPTED", "DOSE INCREASED", "DOSE REDUCED"), "AE leading to dose modification/interruption" - ), - REL = with_label(AEREL == "Y", "Related AE"), - RELWD = with_label(AEREL == "Y" & AEACN == "DRUG WITHDRAWN", "Related AE leading to withdrawal from treatment"), - RELDSM = with_label( - AEREL == "Y" & AEACN %in% c("DRUG INTERRUPTED", "DOSE INCREASED", "DOSE REDUCED"), - "Related AE leading to dose modification/interruption" - ), - CTC35 = with_label(AETOXGR %in% c("3", "4", "5"), "Grade 3-5 AE"), - CTC45 = with_label(AETOXGR %in% c("4", "5"), "Grade 4/5 AE"), - SMQ01 = with_label(SMQ01NAM != "", aesi_label(adae$SMQ01NAM, adae$SMQ01SC)), - SMQ02 = with_label(SMQ02NAM != "", aesi_label(adae$SMQ02NAM, adae$SMQ02SC)), - CQ01 = with_label(CQ01NAM != "", aesi_label(adae$CQ01NAM)), - USUBJID_AESEQ = paste(USUBJID, AESEQ, sep = "@@") # Create unique ID per AE in dataset. - ) %>% - filter(ANL01FL == "Y") - -testthat::test_that("Safety Summary Variant 1 works as expected", { - aesi_vars <- c("FATAL", "SER", "SERWD", "SERDSM", "RELSER", "WD", "DSM", "REL", "RELWD", "RELDSM", "SEV") - - # Layout for variables from adsl dataset. - lyt_adsl <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - count_patients_with_event( - "USUBJID", - filters = c("DTHFL" = "Y"), - denom = "N_col", - .labels = c(count_fraction = "Total number of deaths") - ) %>% - count_patients_with_event( - "USUBJID", - filters = c("DCSREAS" = "ADVERSE EVENT"), - denom = "N_col", - .labels = c(count_fraction = "Total number of patients withdrawn from study due to an AE"), - table_names = "tot_wd" - ) - - result_adsl <- build_table(lyt_adsl, df = adsl, alt_counts_df = adsl) - - # Layout for variables from adae dataset. - lyt_adae <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one AE", - nonunique = "Total number of AEs" - ), - .formats = list(unique = format_count_fraction_fixed_dp, nonunique = "xx"), - show_labels = "hidden" - ) %>% - count_patients_with_flags( - "USUBJID", - flag_variables = aesi_vars, - denom = "N_col", - var_labels = "Total number of patients with at least one", - show_labels = "visible" - ) - - result_adae <- build_table(lyt_adae, df = adae, alt_counts_df = adsl) - - # Combine tables. - col_info(result_adsl) <- col_info(result_adae) - result <- rbind( - result_adae[1:2, ], - result_adsl, - result_adae[3:nrow(result_adae), ] - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - - -testthat::test_that("Safety Summary Variant 2 (with Medical Concepts Section) works as expected", { - aesi_vars <- c("FATAL", "SER", "SERWD", "SERDSM", "RELSER", "WD", "DSM", "REL", "RELWD", "RELDSM", "CTC35") - basket_vars <- c("SMQ01", "SMQ02", "CQ01") - - # Layout for variables from adsl dataset. - lyt_adsl <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - count_patients_with_event( - "USUBJID", - filters = c("DTHFL" = "Y"), - denom = "N_col", - .labels = c(count_fraction = "Total number of deaths") - ) %>% - count_patients_with_event( - "USUBJID", - filters = c("DCSREAS" = "ADVERSE EVENT"), - denom = "N_col", - .labels = c(count_fraction = "Total number of patients withdrawn from study due to an AE"), - table_names = "tot_wd" - ) - - result_adsl <- build_table(lyt_adsl, df = adsl, alt_counts_df = adsl) - - # Layout for variables from adae dataset. - lyt_adae <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one AE", - nonunique = "Total number of AEs" - ), - .formats = list(unique = format_count_fraction_fixed_dp, nonunique = "xx"), - show_labels = "hidden" - ) %>% - count_patients_with_flags( - "USUBJID", - flag_variables = aesi_vars, - denom = "N_col", - var_labels = "Total number of patients with at least one", - show_labels = "visible" - ) %>% - count_patients_with_flags( - "USUBJID", - flag_variables = basket_vars, - table_names = "table_aesi", - denom = "N_col", - var_labels = "Total number of patients with at least one", - show_labels = "visible" - ) - - result_adae <- build_table(lyt_adae, df = adae, alt_counts_df = adsl) - - # Combine tables. - col_info(result_adsl) <- col_info(result_adae) - result <- rbind( - result_adae[1:2, ], - result_adsl, - result_adae[3:nrow(result_adae), ] - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("Safety Summary Variant 3 (with Modified Rows) works as expected", { - aesi_vars <- c("FATAL", "SER", "WD", "REL", "CTC35", "CTC45") - # Layout for variables from adsl dataset. - lyt_adsl <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - count_patients_with_event( - "USUBJID", - filters = c("DTHFL" = "Y"), - denom = "N_col", - .labels = c(count_fraction = "Total number of deaths") - ) %>% - count_patients_with_event( - "USUBJID", - filters = c("DCSREAS" = "ADVERSE EVENT"), - denom = "N_col", - .labels = c(count_fraction = "Total number of patients withdrawn from study due to an AE"), - table_names = "tot_wd" - ) %>% - count_patients_with_event( - "USUBJID", - filters = c("DCSREAS" = "WITHDRAWAL BY SUBJECT"), - denom = "N_col", - .labels = c(count_fraction = "Total number of patients withdrawn informed consent"), - table_names = "tot_dscsreas_wd" - ) - result_adsl <- build_table(lyt_adsl, df = adsl, alt_counts_df = adsl) - - # Layout for variables from adae dataset. - lyt_adae <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one AE", - nonunique = "Total number of AEs" - ), - .formats = list(unique = format_count_fraction_fixed_dp, nonunique = "xx"), - show_labels = "hidden" - ) %>% - count_patients_with_flags( - "USUBJID", - flag_variables = aesi_vars, - denom = "N_col", - var_labels = "Total number of patients with at least one", - show_labels = "visible" - ) - result_adae <- build_table(lyt_adae, df = adae, alt_counts_df = adsl) - - # Combine tables. - col_info(result_adsl) <- col_info(result_adae) - result <- rbind( - result_adae[1:2, ], - result_adsl, - result_adae[3:nrow(result_adae), ] - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("Safety Summary Variant 4 (with Rows Counting Events and Additional Sections) works as expected", { - count_subj_vars <- c("FATAL", "SER", "WD", "DSM", "REL", "CTC35") - count_term_vars <- c("SER", "DSM", "REL", "CTC35", "CTC45") - count_ae_vars <- c("SER", "DSM", "REL", "CTC35", "CTC45") - - # Layout for variables from adsl dataset. - lyt_adsl <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - count_patients_with_event( - "USUBJID", - filters = c("DTHFL" = "Y"), - denom = "N_col", - .labels = c(count_fraction = "Total number of deaths") - ) %>% - count_patients_with_event( - "USUBJID", - filters = c("DCSREAS" = "ADVERSE EVENT"), - denom = "N_col", - .labels = c(count_fraction = "Total number of patients withdrawn from study due to an AE"), - table_names = "tot_wd" - ) - - result_adsl <- build_table(lyt_adsl, df = adsl, alt_counts_df = adsl) - - # Layout for variables from adae dataset. - lyt_adae <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one AE", - nonunique = "Total number of AEs" - ), - .formats = list(unique = format_count_fraction_fixed_dp, nonunique = "xx"), - show_labels = "hidden" - ) %>% - count_patients_with_flags( - "USUBJID", - flag_variables = count_subj_vars, - denom = "N_col", - var_labels = "Total number of patients with at least one", - show_labels = "visible" - ) %>% - count_patients_with_flags( - "AEDECOD", - flag_variables = count_term_vars, - .stats = "count", - .formats = c(count = "xx"), - table_names = "table_term", - var_labels = "Total number of unique preferred terms which are", - show_labels = "visible" - ) %>% - count_patients_with_flags( - "USUBJID_AESEQ", - flag_variables = count_ae_vars, - .stats = "count", - .formats = c(count = "xx"), - table_names = "table_ae", - var_labels = "Total number of adverse events which are", - show_labels = "visible" - ) - - result_adae <- build_table(lyt_adae, df = adae, alt_counts_df = adsl) - - # Combine tables. - col_info(result_adsl) <- col_info(result_adae) - result <- rbind( - result_adae[1:2, ], - result_adsl, - result_adae[3:nrow(result_adae), ] - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_aet01_aesi.R b/tests/testthat/test-table_aet01_aesi.R deleted file mode 100644 index 15650f1e..00000000 --- a/tests/testthat/test-table_aet01_aesi.R +++ /dev/null @@ -1,551 +0,0 @@ -adsl <- adsl_pharmaverse -adae <- adae_pharmaverse - -adsl <- filter(adsl, SAFFL == "Y") -adae <- filter(adae, ANL01FL == "Y" & SAFFL == "Y") - -adsl <- df_explicit_na(adsl) -adae <- df_explicit_na(adae) - -not_resolved <- adae %>% - filter(!(AEOUT %in% c("RECOVERED/RESOLVED", "FATAL", "RECOVERED/RESOLVED WITH SEQUELAE"))) %>% - distinct(USUBJID) %>% - mutate(NOT_RESOLVED = "Y") - -adae <- adae %>% - left_join(not_resolved, by = c("USUBJID")) %>% - mutate( - ALL_RESOLVED = with_label(is.na(NOT_RESOLVED), "Total number of patients with all non-fatal AEs resolved"), - NOT_RESOLVED = with_label( - !is.na(NOT_RESOLVED), "Total number of patients with at least one unresolved or ongoing non-fatal AE" - ) - ) - -adae <- adae %>% - mutate( - AEDECOD = as.character(AEDECOD), - WD = with_label(AEACN == "DRUG WITHDRAWN", "Total number of patients with study drug withdrawn due to AE"), - DSM = with_label( - AEACN %in% c("DRUG INTERRUPTED", "DOSE INCREASED", "DOSE REDUCED"), - "Total number of patients with dose modified/interrupted due to AE" - ), - CONTRT = with_label(AECONTRT == "Y", "Total number of patients with treatment received for AE"), - SER = with_label(AESER == "Y", "Total number of patients with at least one serious AE"), - REL = with_label(AEREL == "Y", "Total number of patients with at least one related AE"), - ALL_RESOLVED_WD = with_label( - WD == TRUE & ALL_RESOLVED == TRUE, "No. of patients with study drug withdrawn due to resolved AE" - ), - ALL_RESOLVED_DSM = with_label( - DSM == TRUE & ALL_RESOLVED == TRUE, "No. of patients with dose modified/interrupted due to resolved AE" - ), - ALL_RESOLVED_CONTRT = with_label( - CONTRT == TRUE & ALL_RESOLVED == TRUE, "No. of patients with treatment received for resolved AE" - ), - NOT_RESOLVED_WD = with_label( - WD == TRUE & NOT_RESOLVED == TRUE, "No. of patients with study drug withdrawn due to unresolved or ongoing AE" - ), - NOT_RESOLVED_DSM = with_label( - DSM == TRUE & NOT_RESOLVED == TRUE, - "No. of patients with dose modified/interrupted due to unresolved or ongoing AE" - ), - NOT_RESOLVED_CONTRT = with_label( - CONTRT == TRUE & NOT_RESOLVED == TRUE, "No. of patients with treatment received for unresolved or ongoing AE" - ), - SERWD = with_label( - AESER == "Y" & AEACN == "DRUG WITHDRAWN", "No. of patients with study drug withdrawn due to serious AE" - ), - SERCONTRT = with_label( - AECONTRT == "Y" & AESER == "Y", "No. of patients with dose modified/interrupted due to serious AE" - ), - SERDSM = with_label( - AESER == "Y" & AEACN %in% c("DRUG INTERRUPTED", "DOSE INCREASED", "DOSE REDUCED"), - "No. of patients with treatment received for serious AE" - ), - RELWD = with_label( - AEREL == "Y" & AEACN == "DRUG WITHDRAWN", "No. of patients with study drug withdrawn due to related AE" - ), - RELDSM = with_label( - AEREL == "Y" & AEACN %in% c("DRUG INTERRUPTED", "DOSE INCREASED", "DOSE REDUCED"), - "No. of patients with dose modified/interrupted due to related AE" - ), - RELCONTRT = with_label(AECONTRT == "Y" & AEREL == "Y", "No. of patients with treatment received for related AE"), - RELSER = with_label(AESER == "Y" & AEREL == "Y", "No. of patients with serious, related AE") - ) - -adae <- adae %>% - mutate( - AETOXGR = forcats::fct_recode( - AETOXGR, - "Grade 1" = "1", - "Grade 2" = "2", - "Grade 3" = "3", - "Grade 4" = "4", - "Grade 5 (fatal outcome)" = "5" - ) - ) - -testthat::test_that("AET01_AESI Variant 1 works as expected", { - aesi_vars <- c("WD", "DSM", "CONTRT", "ALL_RESOLVED", "NOT_RESOLVED", "SER", "REL") - - lyt_adae <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - count_patients_with_event( - vars = "USUBJID", - filters = c("ANL01FL" = "Y"), - denom = "N_col", - .labels = c(count_fraction = "Total number of patients with at least one AE") - ) %>% - count_values( - "ANL01FL", - values = "Y", - .stats = "count", - .labels = c(count = "Total number of AEs"), - table_names = "total_aes" - ) %>% - count_occurrences_by_grade( - var = "AETOXGR", - var_labels = "Total number of patients with at least one AE by worst grade", - show_labels = "visible" - ) %>% - count_patients_with_flags("USUBJID", flag_variables = aesi_vars, denom = "N_col") - - result <- build_table(lyt_adae, df = adae, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET01_AESI Variant 2 works as expected", { - aesi_vars <- c("WD", "DSM", "CONTRT") - aesi_resolved <- c("ALL_RESOLVED", "ALL_RESOLVED_WD", "ALL_RESOLVED_DSM", "ALL_RESOLVED_CONTRT") - aesi_not_resolved <- c("NOT_RESOLVED", "NOT_RESOLVED_WD", "NOT_RESOLVED_DSM", "NOT_RESOLVED_CONTRT") - aesi_ser <- c("SER", "SERWD", "SERDSM", "SERCONTRT") - aesi_rel <- c("REL", "RELWD", "RELDSM", "RELCONTRT", "RELSER") - - lyt_adae <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - count_patients_with_event( - vars = "USUBJID", - filters = c("ANL01FL" = "Y"), - denom = "N_col", - .labels = c(count_fraction = "Total number of patients with at least one AE") - ) %>% - count_values( - "ANL01FL", - values = "Y", - .stats = "count", - .labels = c(count = "Total number of AEs"), - table_names = "total_aes" - ) %>% - count_occurrences_by_grade( - var = "AETOXGR", - var_labels = "Total number of patients with at least one AE by worst grade", - show_labels = "visible" - ) %>% - count_patients_with_flags( - "USUBJID", - flag_variables = c(aesi_vars, aesi_resolved[1]), denom = "N_col" - ) %>% - count_patients_with_flags( - "USUBJID", - flag_variables = aesi_resolved[-1], denom = "N_col", .indent_mods = 1L, table_names = "fl_res" - ) %>% - count_patients_with_flags( - "USUBJID", - flag_variables = aesi_not_resolved[1], denom = "N_col", table_names = "fl_notres_main" - ) %>% - count_patients_with_flags( - "USUBJID", - flag_variables = aesi_not_resolved[-1], denom = "N_col", .indent_mods = 1L, table_names = "fl_notres" - ) %>% - count_patients_with_flags( - "USUBJID", - flag_variables = aesi_ser[1], denom = "N_col", table_names = "fl_ser_main" - ) %>% - count_patients_with_flags( - "USUBJID", - flag_variables = aesi_ser[-1], denom = "N_col", .indent_mods = 1L, table_names = "fl_ser" - ) %>% - count_patients_with_flags( - "USUBJID", - flag_variables = aesi_rel[1], denom = "N_col", table_names = "fl_rel_main" - ) %>% - count_patients_with_flags( - "USUBJID", - flag_variables = aesi_rel[-1], denom = "N_col", .indent_mods = 1L, table_names = "fl_rel" - ) - - result <- build_table(lyt_adae, df = adae, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET01_AESI Variant 3 works as expected", { - adsl <- adsl_pharmaverse - - adae_mult <- adae_pharmaverse %>% - df_explicit_na() - - # for illustration purposes only, create AEREL1, AEREL2, AEACN1, AEACN2 from respective variables - adae_mult <- adae_mult %>% - mutate( - AEREL1 = AEREL, - AEREL2 = AEREL, - AEACN1 = AEACN, - AEACN2 = AEACN - ) - - not_resolved <- adae_mult %>% - filter(!(AEOUT %in% c("RECOVERED/RESOLVED", "FATAL", "RECOVERED/RESOLVED WITH SEQUELAE"))) %>% - distinct(USUBJID) %>% - mutate(NOT_RESOLVED = "Y") - - adae_mult <- adae_mult %>% - left_join(not_resolved, by = c("USUBJID")) %>% - mutate( - ALL_RESOLVED = with_label(is.na(NOT_RESOLVED), "Total number of patients with all non-fatal AEs resolved"), - NOT_RESOLVED = with_label( - !is.na(NOT_RESOLVED), "Total number of patients with at least one non-fatal unresolved or ongoing AE" - ) - ) - - adae_mult <- adae_mult %>% - mutate( - AEDECOD = as.character(AEDECOD), - WD1 = with_label(AEACN1 == "DRUG WITHDRAWN", "Total number of patients with study drug 1 withdrawn due to AE"), - WD2 = with_label(AEACN2 == "DRUG WITHDRAWN", "Total number of patients with study drug 2 withdrawn due to AE"), - DSM1 = with_label( - AEACN1 %in% c("DRUG INTERRUPTED", "DOSE INCREASED", "DOSE REDUCED"), - "Total number of patients with dose of study drug 1 modified/interrupted due to AE" - ), - DSM2 = with_label( - AEACN2 %in% c("DRUG INTERRUPTED", "DOSE INCREASED", "DOSE REDUCED"), - "Total number of patients with dose of study drug 2 modified/interrupted due to AE" - ), - CONTRT = with_label(AECONTRT == "Y", "Total number of patients with treatment received for AE"), - SER = with_label(AESER == "Y", "Total number of patients with at least one serious AE"), - REL1 = with_label(AEREL1 == "Y", "Total number of patients with at least one AE related to study drug 1"), - REL2 = with_label(AEREL2 == "Y", "Total number of patients with at least one AE related to study drug 2"), - ALL_RESOLVED_WD1 = with_label( - WD1 == TRUE & ALL_RESOLVED == TRUE, "No. of patients with study drug 1 withdrawn due to resolved AE" - ), - ALL_RESOLVED_DSM1 = with_label( - DSM1 == TRUE & ALL_RESOLVED == TRUE, - "No. of patients with dose of study drug 1 modified/interrupted due to resolved AE" - ), - ALL_RESOLVED_CONTRT = with_label( - CONTRT == TRUE & ALL_RESOLVED == TRUE, "No. of patients with treatment received for resolved AE" - ), - ALL_RESOLVED_WD2 = with_label( - WD2 == TRUE & ALL_RESOLVED == TRUE, "No. of patients with study drug 2 withdrawn due to resolved AE" - ), - ALL_RESOLVED_DSM2 = with_label( - DSM2 == TRUE & ALL_RESOLVED == TRUE, - "No. of patients with dose of study drug 2 modified/interrupted due to resolved AE" - ), - NOT_RESOLVED_WD1 = with_label( - WD1 == TRUE & NOT_RESOLVED == TRUE, - "No. of patients with study drug 1 withdrawn due to unresolved or ongoing AE" - ), - NOT_RESOLVED_DSM1 = with_label( - DSM1 == TRUE & NOT_RESOLVED == TRUE, - "No. of patients with dose of study drug 1 modified/interrupted due to unresolved or ongoing AE" - ), - NOT_RESOLVED_CONTRT = with_label( - CONTRT == TRUE & NOT_RESOLVED == TRUE, "No. of patients with treatment received for unresolved or ongoing AE" - ), - NOT_RESOLVED_WD2 = with_label( - WD2 == TRUE & NOT_RESOLVED == TRUE, - "No. of patients with study drug 2 withdrawn due to unresolved or ongoing AE" - ), - NOT_RESOLVED_DSM2 = with_label( - DSM2 == TRUE & NOT_RESOLVED == TRUE, - "No. of patients with dose of study drug 2 modified/interrupted due to unresolved or ongoing AE" - ), - SERWD1 = with_label( - AESER == "Y" & AEACN1 == "DRUG WITHDRAWN", "No. of patients with study drug 1 withdrawn due to serious AE" - ), - SERWD2 = with_label( - AESER == "Y" & AEACN2 == "DRUG WITHDRAWN", "No. of patients with study drug 2 withdrawn due to serious AE" - ), - SERCONTRT = with_label(AECONTRT == "Y" & AESER == "Y", "No. of patients with treatment received for serious AE"), - SERDSM1 = with_label( - AESER == "Y" & AEACN1 %in% c("DRUG INTERRUPTED", "DOSE INCREASED", "DOSE REDUCED"), - "No. of patients with dose of study drug 1 modified/interrupted due to serious AE" - ), - SERDSM2 = with_label( - AESER == "Y" & AEACN2 %in% c("DRUG INTERRUPTED", "DOSE INCREASED", "DOSE REDUCED"), - "No. of patients with dose of study drug 2 modified/interrupted due to serious AE" - ), - REL1WD1 = with_label( - AEREL1 == "Y" & AEACN1 == "DRUG WITHDRAWN", - "No. of patients with study drug 1 withdrawn due to AE related to study drug 1" - ), - REL1WD2 = with_label( - AEREL1 == "Y" & AEACN2 == "DRUG WITHDRAWN", - "No. of patients with study drug 1 withdrawn due to AE related to study drug 2" - ), - REL2WD1 = with_label( - AEREL1 == "Y" & AEACN1 == "DRUG WITHDRAWN", - "No. of patients with study drug 2 withdrawn due to AE related to study drug 1" - ), - REL2WD2 = with_label( - AEREL1 == "Y" & AEACN2 == "DRUG WITHDRAWN", - "No. of patients with study drug 2 withdrawn due to AE related to study drug 2" - ), - REL1DSM1 = with_label( - AEREL1 == "Y" & AEACN1 %in% c("DRUG INTERRUPTED", "DOSE INCREASED", "DOSE REDUCED"), - "No. of patients with dose of study drug 1 modified/interrupted due to AE related to study drug 1" - ), - REL2DSM1 = with_label( - AEREL2 == "Y" & AEACN1 %in% c("DRUG INTERRUPTED", "DOSE INCREASED", "DOSE REDUCED"), - "No. of patients with dose of study drug 2 modified/interrupted due to AE related to study drug 1" - ), - REL1DSM2 = with_label( - AEREL1 == "Y" & AEACN2 %in% c("DRUG INTERRUPTED", "DOSE INCREASED", "DOSE REDUCED"), - "No. of patients with dose of study drug 1 modified/interrupted due to AE related to study drug 2" - ), - REL2DSM2 = with_label( - AEREL2 == "Y" & AEACN2 %in% c("DRUG INTERRUPTED", "DOSE INCREASED", "DOSE REDUCED"), - "No. of patients with dose of study drug 2 modified/interrupted due to AE related to study drug 2" - ), - REL1CONTRT = with_label( - AECONTRT == "Y" & AEREL1 == "Y", "No. of patients with treatment received for AE related to study drug 1" - ), - REL2CONTRT = with_label( - AECONTRT == "Y" & AEREL2 == "Y", "No. of patients with treatment received for AE related to study drug 2" - ), - REL1SER = with_label(AESER == "Y" & AEREL1 == "Y", "No. of patients with serious AE related to study drug 1"), - REL2SER = with_label(AESER == "Y" & AEREL2 == "Y", "No. of patients with serious AE related to study drug 2") - ) - - adae_mult <- adae_mult %>% - mutate(AETOXGR = forcats::fct_recode( - AETOXGR, - "Grade 1" = "1", - "Grade 2" = "2", - "Grade 3" = "3", - "Grade 4" = "4", - "Grade 5 (fatal outcome)" = "5" - )) - - aesi_vars <- c("WD1", "WD2", "DSM1", "DSM2", "CONTRT") - aesi_res <- c( - "ALL_RESOLVED", "ALL_RESOLVED_WD1", "ALL_RESOLVED_WD2", - "ALL_RESOLVED_DSM1", "ALL_RESOLVED_DSM2", "ALL_RESOLVED_CONTRT" - ) - aesi_not_res <- c( - "NOT_RESOLVED", "NOT_RESOLVED_WD1", "NOT_RESOLVED_WD2", - "NOT_RESOLVED_DSM1", "NOT_RESOLVED_DSM2", "NOT_RESOLVED_CONTRT" - ) - aesi_ser <- c("SER", "SERWD1", "SERWD2", "SERDSM1", "SERDSM2", "SERCONTRT") - aesi_rel1 <- c("REL1", "REL1WD1", "REL1WD2", "REL1DSM1", "REL1DSM2", "REL1CONTRT", "REL1SER") - aesi_rel2 <- c("REL2", "REL2WD1", "REL2WD2", "REL2DSM1", "REL2DSM2", "REL2CONTRT", "REL2SER") - - lyt_adae_mult <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - count_patients_with_event( - vars = "USUBJID", - filters = c("ANL01FL" = "Y"), - denom = "N_col", - .labels = c(count_fraction = "Total number of patients with at least one AE") - ) %>% - count_values( - "ANL01FL", - values = "Y", - .stats = "count", - .labels = c(count = "Total number of AEs"), - table_names = "total_aes" - ) %>% - count_occurrences_by_grade( - var = "AETOXGR", - var_labels = "Total number of patients with at least one AE by worst grade", - show_labels = "visible" - ) %>% - count_patients_with_flags( - "USUBJID", - flag_variables = c(aesi_vars, aesi_res[1]), denom = "N_col" - ) %>% - count_patients_with_flags( - "USUBJID", - flag_variables = aesi_res[-1], denom = "N_col", .indent_mods = 1L, table_names = "fl_res" - ) %>% - count_patients_with_flags( - "USUBJID", - flag_variables = aesi_not_res[1], denom = "N_col", table_names = "fl_notres_main" - ) %>% - count_patients_with_flags( - "USUBJID", - flag_variables = aesi_not_res[-1], denom = "N_col", .indent_mods = 1L, table_names = "fl_notres" - ) %>% - count_patients_with_flags( - "USUBJID", - flag_variables = aesi_ser[1], denom = "N_col", table_names = "fl_ser_main" - ) %>% - count_patients_with_flags( - "USUBJID", - flag_variables = aesi_ser[-1], denom = "N_col", .indent_mods = 1L, table_names = "fl_ser" - ) %>% - count_patients_with_flags( - "USUBJID", - flag_variables = aesi_rel1[1], denom = "N_col", table_names = "fl_rel1_main" - ) %>% - count_patients_with_flags( - "USUBJID", - flag_variables = aesi_rel1[-1], denom = "N_col", .indent_mods = 1L, table_names = "fl_rel1" - ) %>% - count_patients_with_flags( - "USUBJID", - flag_variables = aesi_rel2[1], denom = "N_col", table_names = "fl_rel2_main" - ) %>% - count_patients_with_flags( - "USUBJID", - flag_variables = aesi_rel2[-1], denom = "N_col", .indent_mods = 1L, table_names = "fl_rel2" - ) - - result <- build_table(lyt_adae_mult, df = adae_mult, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -# SMQ stuff will not work quite yet -testthat::test_that("AET01_AESI Variant 4 works as expected", { - adsl <- filter(adsl_pharmaverse, SAFFL == "Y") - adae <- filter(adae_pharmaverse, ANL01FL == "Y" & SAFFL == "Y") - - adsl <- df_explicit_na(adsl) - adae <- df_explicit_na(adae) - - stack_adae_by_smq <- function(adae, smq) { - adae_labels <- c(var_labels(adae), "Standardized MedDRA Query") - l_df <- lapply(smq, function(ae_grp) { - ae_scope <- gsub("NAM", "SC", ae_grp) - keep <- adae[[ae_grp]] != "" - df <- adae[keep, ] - if (substr(ae_grp, 1, 3) == "SMQ") { - df[["SMQ"]] <- aesi_label(as.character(df[[ae_grp]]), scope = as.character(df[[ae_scope]])) - } else { - df[["SMQ"]] <- df[[ae_grp]] - } - df - }) - result <- do.call(rbind, l_df) - var_labels(result) <- adae_labels - result - } - - adae_smq <- stack_adae_by_smq(adae, c("SMQ01NAM", "SMQ02NAM", "CQ01NAM")) - - not_resolved <- adae_smq %>% - filter(!(AEOUT %in% c("RECOVERED/RESOLVED", "FATAL", "RECOVERED/RESOLVED WITH SEQUELAE"))) %>% - distinct(USUBJID) %>% - mutate(NOT_RESOLVED = "Y") - - adae_smq <- adae_smq %>% - left_join(not_resolved, by = c("USUBJID")) %>% - mutate( - ALL_RESOLVED = with_label(is.na(NOT_RESOLVED), "Total number of patients with all non-fatal AEs resolved"), - NOT_RESOLVED = with_label( - !is.na(NOT_RESOLVED), "Total number of patients with at least one non-fatal unresolved or ongoing AE" - ) - ) - - adae_smq <- adae_smq %>% - mutate( - AEDECOD = as.character(AEDECOD), - WD = with_label(AEACN == "DRUG WITHDRAWN", "Total number of patients with study drug withdrawn due to AE"), - DSM = with_label( - AEACN %in% c("DRUG INTERRUPTED", "DOSE INCREASED", "DOSE REDUCED"), - "Total number of patients with dose modified/interrupted due to AE" - ), - CONTRT = with_label(AECONTRT == "Y", "Total number of patients with treatment received for AE"), - SER = with_label(AESER == "Y", "Total number of patients with at least one serious AE"), - REL = with_label(AEREL == "Y", "Total number of patients with at least one related AE"), - ALL_RESOLVED_WD = with_label( - WD == TRUE & ALL_RESOLVED == TRUE, "No. of patients with study drug withdrawn due to resolved AE" - ), - ALL_RESOLVED_DSM = with_label( - DSM == TRUE & ALL_RESOLVED == TRUE, "No. of patients with dose modified/interrupted due to resolved AE" - ), - ALL_RESOLVED_CONTRT = with_label( - CONTRT == TRUE & ALL_RESOLVED == TRUE, "No. of patients with treatment received for resolved AE" - ), - NOT_RESOLVED_WD = with_label( - WD == TRUE & NOT_RESOLVED == TRUE, "No. of patients with study drug withdrawn due to unresolved or ongoing AE" - ), - NOT_RESOLVED_DSM = with_label( - DSM == TRUE & NOT_RESOLVED == TRUE, - "No. of patients with dose modified/interrupted due to unresolved or ongoing AE" - ), - NOT_RESOLVED_CONTRT = with_label( - CONTRT == TRUE & NOT_RESOLVED == TRUE, "No. of patients with treatment received for unresolved or ongoing AE" - ), - SERWD = with_label( - AESER == "Y" & AEACN == "DRUG WITHDRAWN", "No. of patients with study drug withdrawn due to serious AE" - ), - SERCONTRT = with_label(AECONTRT == "Y" & AESER == "Y", "No. of patients with treatment received for serious AE"), - SERDSM = with_label( - AESER == "Y" & AEACN %in% c("DRUG INTERRUPTED", "DOSE INCREASED", "DOSE REDUCED"), - "No. of patients with dose modified/interrupted due to serious AE" - ), - RELWD = with_label( - AEREL == "Y" & AEACN == "DRUG WITHDRAWN", "No. of patients with study drug withdrawn due to related AE" - ), - RELDSM = with_label( - AEREL == "Y" & AEACN %in% c("DRUG INTERRUPTED", "DOSE INCREASED", "DOSE REDUCED"), - "No. of patients with dose modified/interrupted due to related AE" - ), - RELCONTRT = with_label(AECONTRT == "Y" & AEREL == "Y", "No. of patients with treatment received for related AE"), - RELSER = with_label(AESER == "Y" & AEREL == "Y", "No. of patients with serious, related AE") - ) - - adae_smq <- adae_smq %>% - mutate( - AETOXGR = forcats::fct_recode(AETOXGR, - "Grade 1" = "1", - "Grade 2" = "2", - "Grade 3" = "3", - "Grade 4" = "4", - "Grade 5 (fatal outcome)" = "5" - ) - ) - - split_fun <- remove_split_levels("") - aesi_vars <- c("WD", "DSM", "CONTRT", "ALL_RESOLVED", "NOT_RESOLVED", "SER", "REL") - - lyt_adae <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - split_rows_by( - "SMQ", - child_labels = "visible", - split_fun = split_fun, - split_label = "Standardized MedDRA Query", - label_pos = "topleft" - ) %>% - count_patients_with_event( - vars = "USUBJID", - filters = c("ANL01FL" = "Y"), - denom = "N_col", - .labels = c(count_fraction = "Total number of patients with at least one AE") - ) %>% - count_values( - "ANL01FL", - values = "Y", - .stats = "count", - .labels = c(count = "Total number of AEs"), - table_names = "total_aes" - ) %>% - count_occurrences_by_grade( - var = "AETOXGR", - var_labels = "Total number of patients with at least one AE by worst grade", - .show_labels = "visible" - ) %>% - count_patients_with_flags("USUBJID", flag_variables = aesi_vars, denom = "N_col") - - result <- build_table(lyt_adae, df = adae_smq, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_aet02.R b/tests/testthat/test-table_aet02.R deleted file mode 100644 index 568b8840..00000000 --- a/tests/testthat/test-table_aet02.R +++ /dev/null @@ -1,612 +0,0 @@ -# Test all variants of AET02 - -adsl <- adsl_pharmaverse -adae <- adae_pharmaverse - -# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels. -adsl <- df_explicit_na(adsl) -adae <- df_explicit_na(adae) %>% - var_relabel( - AEBODSYS = "MedDRA System Organ Class", - AEDECOD = "MedDRA Preferred Term" - ) %>% - filter(ANL01FL == "Y") - -# Define the split function -split_fun <- drop_split_levels - -testthat::test_that("AET02 variant 1 is produced correctly", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ACTARM") %>% - add_overall_col(label = "All Patients") %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one adverse event", - nonunique = "Overall total number of events" - ) - ) %>% - split_rows_by( - "AEBODSYS", - child_labels = "visible", - nested = FALSE, - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adae$AEBODSYS) - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one adverse event", - nonunique = "Total number of events" - ) - ) %>% - count_occurrences( - vars = "AEDECOD", - .indent_mods = -1L - ) %>% - append_varlabels(adae, "AEDECOD", indent = 1L) - - result <- build_table(lyt, df = adae, alt_counts_df = adsl) - - result <- result %>% - prune_table() %>% - sort_at_path( - path = c("AEBODSYS"), - scorefun = cont_n_allcols - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEDECOD"), - scorefun = score_occurrences - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) - - # Testing pagination with not repeated Total number of patients - pag_result <- paginate_table(result) - testthat::expect_identical( - to_string_matrix(pag_result[[1]], with_spaces = FALSE)[3, 1], - "Total number of patients with at least one adverse event" - ) - testthat::expect_identical( - to_string_matrix(pag_result[[2]], with_spaces = FALSE)[5, 1], - "SKIN AND SUBCUTANEOUS TISSUE DISORDERS" - ) -}) - -testthat::test_that("AET02 variant 2 is produced correctly", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ACTARM") %>% - add_overall_col(label = "All Patients") %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one adverse event", - nonunique = "Overall total number of events" - ) - ) %>% - split_rows_by( - "AEBODSYS", - child_labels = "visible", - nested = FALSE, - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adae$AEBODSYS) - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = c("unique"), - .labels = c( - unique = "Total number of patients with at least one adverse event" - ) - ) %>% - count_occurrences(vars = "AEDECOD", .indent_mods = -1L) %>% - append_varlabels(adae, "AEDECOD", indent = 1L) %>% - count_values( - "STUDYID", - values = as.character(unique(adae$STUDYID)), - .stats = "count", - .labels = c(count = "Total number of events"), - .indent_mods = c(count = -1L) - ) - - result <- build_table(lyt, df = adae, alt_counts_df = adsl) %>% - prune_table() %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEDECOD"), - scorefun = score_occurrences - ) %>% - sort_at_path( - path = c("AEBODSYS"), - scorefun = cont_n_allcols - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET02 variant 3 is produced correctly", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ACTARM") %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one adverse event", - nonunique = "Overall total number of events" - ) - ) %>% - split_rows_by( - "AEBODSYS", - child_labels = "visible", - nested = FALSE, - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adae$AEBODSYS) - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one adverse event", - nonunique = "Total number of events" - ) - ) %>% - split_rows_by( - "AEHLT", - child_labels = "visible", - nested = TRUE, - split_fun = split_fun, - indent_mod = -1L, - label_pos = "topleft", - split_label = obj_label(adae$AEHLT) - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one adverse event", - nonunique = "Total number of events" - ) - ) %>% - count_occurrences(vars = "AEDECOD", .indent_mods = -1L) %>% - append_varlabels(adae, c("AEDECOD"), indent = 2L) - - result <- build_table(lyt, df = adae, alt_counts_df = adsl) %>% - prune_table() %>% - sort_at_path( - path = c("AEBODSYS"), - scorefun = cont_n_allcols - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEHLT"), - scorefun = cont_n_allcols - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEHLT", "*", "AEDECOD"), - scorefun = score_occurrences - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET02 variant 4 is produced correctly", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ACTARM") %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one adverse event", - nonunique = "Total number of events" - ), - show_labels = "hidden" - ) %>% - count_occurrences(vars = "AEDECOD") %>% - append_varlabels(adae, "AEDECOD") - - result <- build_table(lyt, df = adae, alt_counts_df = adsl) %>% - sort_at_path( - path = c("AEDECOD"), - scorefun = score_occurrences - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET02 variant 5 is produced correctly", { - adae_5 <- adae %>% dplyr::filter(ACTARM != "Xanomeline Low Dose") - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ACTARM") %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one adverse event", - nonunique = "Overall total number of events" - ) - ) %>% - split_rows_by( - "AEBODSYS", - child_labels = "visible", - nested = FALSE, - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adae$AEBODSYS) - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one adverse event", - nonunique = "Total number of events" - ) - ) %>% - count_occurrences(vars = "AEDECOD", .indent_mods = -1L) %>% - append_varlabels(adae, "AEDECOD", indent = 1L) - - result <- build_table(lyt, df = adae_5, alt_counts_df = adsl) %>% - prune_table() %>% - sort_at_path( - path = c("AEBODSYS"), - scorefun = cont_n_allcols - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEDECOD"), - scorefun = score_occurrences - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET02 variant 6 is produced correctly", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ACTARM") %>% - split_rows_by( - "AEBODSYS", - child_labels = "visible", - nested = FALSE, - indent_mod = -1L, - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adae$AEBODSYS) - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = "unique", - .labels = "Total number of patients with at least one adverse event" - ) %>% - count_occurrences( - vars = "AEDECOD", - .indent_mods = 1L - ) %>% - append_varlabels(adae, "AEDECOD", indent = 1L) - - result <- build_table(lyt, df = adae, alt_counts_df = adsl) %>% - prune_table() %>% - sort_at_path( - path = c("AEBODSYS"), - scorefun = cont_n_allcols - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEDECOD"), - scorefun = score_occurrences - ) - - criteria_fun <- function(tr) is(tr, "ContentRow") - result <- trim_rows(result, criteria = criteria_fun) - - row_condition <- has_fraction_in_any_col( - atleast = 0.05, - col_names = names(table(adsl$ACTARM)) - ) - result <- prune_table(result, keep_rows(row_condition)) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET02 variant 7 is produced correctly", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ACTARM") %>% - split_rows_by( - "AEBODSYS", - child_labels = "visible", - nested = TRUE, - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adae$AEBODSYS) - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = "unique", - .labels = "Total number of patients with at least one adverse event" - ) %>% - split_rows_by( - "AEHLT", - child_labels = "visible", - nested = TRUE, - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adae$AEHLT) - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = "unique", - .labels = "Total number of patients with at least one adverse event" - ) %>% - count_occurrences(vars = "AEDECOD") %>% - append_varlabels(adae, c("AEDECOD"), indent = 2L) - - result <- build_table(lyt, adae, alt_counts_df = adsl) %>% - prune_table() %>% - sort_at_path( - path = c("AEBODSYS"), - scorefun = cont_n_allcols, - decreasing = TRUE - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEHLT"), - scorefun = cont_n_allcols, - decreasing = TRUE - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEHLT", "*", "AEDECOD"), - scorefun = score_occurrences, - decreasing = TRUE - ) - - criteria_fun <- function(tr) is(tr, "ContentRow") - result <- trim_rows(result, criteria = criteria_fun) - - row_condition <- has_fraction_in_any_col( - atleast = 0.05, - col_names = names(table(adsl$ACTARM)) - ) - result <- prune_table(result, keep_rows(row_condition)) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET02 variant 8 is produced correctly", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ACTARM") %>% - split_rows_by( - "AEBODSYS", - child_labels = "visible", - nested = FALSE, - indent_mod = -1L, - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adae$AEBODSYS) - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = "unique", - .labels = "Total number of patients with at least one adverse event" - ) %>% - count_occurrences( - vars = "AEDECOD", - .indent_mods = 1L - ) %>% - append_varlabels(adae, "AEDECOD", indent = 1L) - - result <- build_table(lyt, df = adae, alt_counts_df = adsl) %>% - prune_table() %>% - sort_at_path( - path = c("AEBODSYS"), - scorefun = cont_n_allcols - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEDECOD"), - scorefun = score_occurrences - ) - - criteria_fun <- function(tr) is(tr, "ContentRow") - result <- trim_rows(result, criteria = criteria_fun) - - row_condition <- has_fraction_in_any_col( - atleast = 0.10, - col_names = names(table(adsl$ACTARM)) - ) - result <- prune_table(result, keep_rows(row_condition)) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET02 variant 9 is produced correctly", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ACTARM") %>% - split_rows_by( - "AEBODSYS", - child_labels = "visible", - nested = FALSE, - indent_mod = -1L, - split_fun = split_fun, - split_label = obj_label(adae$AEBODSYS), - label_pos = "topleft" - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = "unique", - .labels = "Total number of patients with at least one adverse event" - ) %>% - count_occurrences( - vars = "AEDECOD", - .indent_mods = 1L - ) %>% - append_varlabels(adae, "AEDECOD", indent = 1L) - - result <- build_table(lyt, df = adae, alt_counts_df = adsl) %>% - prune_table() %>% - sort_at_path( - path = c("AEBODSYS"), - scorefun = cont_n_allcols - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEDECOD"), - scorefun = score_occurrences - ) - - criteria_fun <- function(tr) is(tr, "ContentRow") - result <- trim_rows(result, criteria = criteria_fun) - - row_condition <- has_count_in_any_col( - atleast = 3, - col_names = names(table(adsl$ACTARM)) - ) - result <- prune_table(result, keep_rows(row_condition)) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET02 variant 10 is produced correctly", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ACTARM") %>% - split_rows_by( - "AEBODSYS", - child_labels = "visible", - nested = FALSE, - indent_mod = -1L, - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adae$AEBODSYS) - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = "unique", - .labels = "Total number of patients with at least one adverse event" - ) %>% - count_occurrences( - vars = "AEDECOD", - .indent_mods = 1L - ) %>% - append_varlabels(adae, "AEDECOD", indent = 1L) - - result <- build_table(lyt, df = adae, alt_counts_df = adsl) %>% - prune_table() %>% - sort_at_path( - path = c("AEBODSYS"), - scorefun = cont_n_allcols - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEDECOD"), - scorefun = score_occurrences - ) - - criteria_fun <- function(tr) is(tr, "ContentRow") - result <- trim_rows(result, criteria = criteria_fun) - - row_condition <- has_fractions_difference( - atleast = 0.05, - col_names = levels(adsl$ACTARM) - ) - result <- prune_table(result, keep_rows(row_condition)) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET02 variant 11 is produced correctly", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ACTARM") %>% - split_rows_by( - "AEBODSYS", - child_labels = "visible", - nested = FALSE, - indent_mod = -1L, - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adae$AEBODSYS) - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = "unique", - .labels = "Total number of patients with at least one adverse event" - ) %>% - count_occurrences( - vars = "AEDECOD", - .indent_mods = 1L - ) %>% - append_varlabels(adae, "AEDECOD", indent = 1L) - - result <- build_table(lyt, df = adae, alt_counts_df = adsl) %>% - prune_table() %>% - sort_at_path( - path = c("AEBODSYS"), - scorefun = cont_n_allcols - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEDECOD"), - scorefun = score_occurrences - ) - - criteria_fun <- function(tr) is(tr, "ContentRow") - result <- trim_rows(result, criteria = criteria_fun) - - row_condition <- has_fraction_in_cols( - atleast = 0.05, - col_names = c("Placebo") - ) - result <- prune_table(result, keep_rows(row_condition)) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET02 variant 12 is produced correctly", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ACTARM") %>% - split_rows_by( - "AEBODSYS", - child_labels = "visible", - nested = FALSE, - indent_mod = -1L, - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adae$AEBODSYS) - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = "unique", - .labels = "Total number of patients with at least one adverse event" - ) %>% - count_occurrences( - vars = "AEDECOD", - .indent_mods = 1L - ) %>% - append_varlabels(adae, "AEDECOD", indent = 1L) - - result <- build_table(lyt, df = adae, alt_counts_df = adsl) %>% - prune_table() %>% - sort_at_path( - path = c("AEBODSYS"), - scorefun = cont_n_allcols - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEDECOD"), - scorefun = score_occurrences - ) - - criteria_fun <- function(tr) is(tr, "ContentRow") - result <- trim_rows(result, criteria = criteria_fun) - - row_condition1 <- has_fractions_difference(atleast = 0.05, col_names = c("Placebo", "Xanomeline High Dose")) - row_condition2 <- has_fractions_difference(atleast = 0.05, col_names = c("Placebo", "Xanomeline Low Dose")) - row_condition <- row_condition1 | row_condition2 - result <- prune_table(result, keep_rows(row_condition)) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_aet02_smq.R b/tests/testthat/test-table_aet02_smq.R deleted file mode 100644 index ce3b6c71..00000000 --- a/tests/testthat/test-table_aet02_smq.R +++ /dev/null @@ -1,92 +0,0 @@ -# Test all variants of AET02 SMQ -stack_adae_by_smq <- function(adae, smq) { - l_df <- lapply(smq, function(ae_grp) { - keep <- !(is.na(adae[[ae_grp]])) - df <- adae[keep, ] - df[["AE_GRP"]] <- ae_grp - df - }) - - do.call(rbind, l_df) -} - -adsl <- adsl_pharmaverse -adae <- adae_pharmaverse - -testthat::test_that("AET02SMQ variant 1 is produced correctly", { - adae <- stack_adae_by_smq(adae, c("SMQ01NAM")) - - lyt <- basic_table() %>% - split_cols_by("ARM") %>% - add_colcounts() %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique"), - .labels = c( - unique = "Total number of patients with at least one adverse event" - ) - ) %>% - split_rows_by( - "AE_GRP", - child_labels = "visible", - nested = FALSE, - split_fun = drop_split_levels - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one adverse event", - nonunique = "Overall total number of events" - ) - ) %>% - count_occurrences(vars = "AEDECOD", .indent_mods = -1L) - - result <- build_table(lyt, adae, alt_counts_df = adsl) - - result <- result %>% - sort_at_path(path = c("AE_GRP"), scorefun = cont_n_allcols) %>% - sort_at_path(path = c("AE_GRP", "*", "AEDECOD"), scorefun = score_occurrences) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET02SMQ variant 2 is produced correctly", { - adae <- stack_adae_by_smq(adae, c("SMQ01NAM", "CQ01NAM")) - - lyt <- basic_table() %>% - split_cols_by("ARM") %>% - add_colcounts() %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique"), - .labels = c( - unique = "Total number of patients with at least one adverse event" - ) - ) %>% - split_rows_by( - "AE_GRP", - child_labels = "visible", - nested = FALSE, - split_fun = drop_split_levels - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one adverse event", - nonunique = "Overall total number of events" - ) - ) %>% - count_occurrences(vars = "AEDECOD", .indent_mods = -1L) - - result <- build_table(lyt, adae, alt_counts_df = adsl) - - result <- result %>% - sort_at_path(path = c("AE_GRP"), scorefun = cont_n_allcols) %>% - sort_at_path(path = c("AE_GRP", "*", "AEDECOD"), scorefun = score_occurrences) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_aet03.R b/tests/testthat/test-table_aet03.R deleted file mode 100644 index 03f48bf7..00000000 --- a/tests/testthat/test-table_aet03.R +++ /dev/null @@ -1,104 +0,0 @@ -adsl <- adsl_pharmaverse -adae <- adae_pharmaverse - -# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels. -adsl <- df_explicit_na(adsl) -adae <- df_explicit_na(adae) %>% - var_relabel( - AEBODSYS = "MedDRA System Organ Class", - AEDECOD = "MedDRA Preferred Term" - ) %>% - filter(ANL01FL == "Y") - -adae <- adae %>% mutate(ASEV = as.character(AESEV)) -adae$ASEV[1:15] <- "LIFE THREATENING" -adae <- adae %>% mutate(ASEV = factor(ASEV, levels = c("MILD", "MODERATE", "SEVERE", "LIFE THREATENING"))) - -testthat::test_that("AET03 variant 1 is produced correctly", { - grade_groups <- list("- Any Intensity -" = c("MILD", "MODERATE", "SEVERE", "LIFE THREATENING")) - - split_fun <- trim_levels_in_group - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - count_occurrences_by_grade( - var = "ASEV", - grade_groups = grade_groups - ) %>% - split_rows_by( - "AEBODSYS", - child_labels = "visible", - nested = TRUE, - split_fun = split_fun("ASEV"), - label_pos = "topleft", - split_label = obj_label(adae$AEBODSYS) - ) %>% - summarize_occurrences_by_grade( - var = "ASEV", - grade_groups = grade_groups - ) %>% - split_rows_by( - "AEDECOD", - child_labels = "visible", - nested = TRUE, - indent_mod = -1L, - split_fun = split_fun("ASEV"), - label_pos = "topleft", - split_label = obj_label(adae$AEDECOD) - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = "unique", - .labels = c("- Any Intensity -") - ) %>% - count_occurrences_by_grade( - var = "ASEV", - .indent_mods = -1L - ) %>% - append_varlabels(adae, "AESEV", indent = 2L) - - result <- lyt %>% - build_table( - adae, - alt_counts_df = adsl - ) %>% - sort_at_path( - path = "AEBODSYS", - scorefun = cont_n_allcols, - decreasing = TRUE - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEDECOD"), - scorefun = cont_n_allcols, - decreasing = TRUE - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) - - result_matrix <- to_string_matrix(result, with_spaces = FALSE) - - # Pagination also works (and sorting) - lpp_test <- 20 - testthat::expect_equal( - nrow(paginate_table(result, lpp = lpp_test)[[3]]) + 4, # 4 is the header - lpp_test - ) - - # With 8, it works perfectly for the first block but others have much more nesting - lpp_test <- 8 - testthat::expect_error( - suppressMessages(paginate_table(result, lpp = lpp_test)[[1]]) - ) - - pag_result <- paginate_table(result) - - testthat::expect_identical( - to_string_matrix(pag_result[[2]], with_spaces = FALSE)[3, 1], - " Severity/Intensity" - ) - testthat::expect_identical( - to_string_matrix(pag_result[[1]], with_spaces = FALSE)[3:4, 1], - c(" Severity/Intensity", "- Any Intensity -") - ) -}) diff --git a/tests/testthat/test-table_aet04.R b/tests/testthat/test-table_aet04.R deleted file mode 100644 index 1fa7d0f6..00000000 --- a/tests/testthat/test-table_aet04.R +++ /dev/null @@ -1,533 +0,0 @@ -adsl <- adsl_pharmaverse -adae <- adae_pharmaverse -adsl <- df_explicit_na(adsl) %>% filter(TRT01A != "") -adae <- df_explicit_na(adae) %>% - var_relabel( - AEBODSYS = "MedDRA System Organ Class", - AEDECOD = "MedDRA Preferred Term" - ) %>% - filter( - ANL01FL == "Y", - AETOXGR != "" - ) - -# Pre-Processing -grade_groups <- list( - "Grade 1-2" = c("1", "2"), - "Grade 3-4" = c("3", "4"), - "Grade 5" = "5" -) -adae$TOTAL_VAR <- "- Any adverse events - " - -# Further reducing burden of the table size -adae <- level_reducer(adae, "AEDECOD", p_to_keep = 0.7) - -# Helper function to avoid filtering also the first part of the table, where general information is given. -my_row_condition <- function(row_fnc_condition) { - function(table_row) { - ret <- NULL - if (indent_mod(table_row) == 0) { - ret <- TRUE - } else { - ret <- row_fnc_condition(table_row) - } - ret - } -} - -# Helper function to calculate sum from first nested row -score_all_sum <- function(tt) { - cleaf <- collect_leaves(tt)[[1]] - if (NROW(cleaf) == 0) { - stop("score_all_sum score function used at subtable [", obj_name(tt), "] that has no content.") - } - sum(sapply(row_values(cleaf), function(cv) cv[1])) -} - -# Raw table used by variant 8/10 -raw_table <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - split_rows_by( - var = "TOTAL_VAR", - label_pos = "hidden", - child_labels = "visible", - indent_mod = -1L - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = "unique", - .labels = "- Any Grade -", - .indent_mods = 7L - ) %>% - count_occurrences_by_grade( - var = "AETOXGR", - grade_groups = grade_groups, - .indent_mods = 6L - ) %>% - split_rows_by( - "AEBODSYS", - child_labels = "visible", - nested = FALSE, - split_fun = drop_split_levels, - split_label = var_labels(adae)[["AEBODSYS"]], - label_pos = "topleft" - ) %>% - split_rows_by( - "AEDECOD", - child_labels = "visible", - split_fun = add_overall_level("- Overall -", trim = TRUE), - split_label = var_labels(adae)[["AEDECOD"]], - label_pos = "topleft" - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = "unique", - .labels = "- Any Grade -", - .indent_mods = 6L - ) %>% - count_occurrences_by_grade( - var = "AETOXGR", - grade_groups = grade_groups, - .indent_mods = 5L - ) %>% - append_topleft(" Grade") %>% - build_table(adae, alt_counts_df = adsl) %>% - prune_table() %>% - sort_at_path( - path = "AEBODSYS", - scorefun = score_all_sum, - decreasing = TRUE - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEDECOD"), - scorefun = score_all_sum, - decreasing = TRUE - ) - -testthat::test_that("AET04 variant 1 is produced correctly", { - res <- testthat::expect_silent(raw_table) - - testthat::expect_snapshot(res) - - # Pagination also works (and sorting) - testthat::expect_silent( - pag_result <- paginate_table(res, lpp = 15) - ) - - testthat::expect_identical( - "SKIN AND SUBCUTANEOUS TISSUE DISORDERS", - to_string_matrix(pag_result[[3]], with_spaces = FALSE)[4, 1] - ) - testthat::expect_identical( - trimws(to_string_matrix(pag_result[[1]], with_spaces = FALSE)[5:6, 1]), - c("- Any Grade -", "Grade 1-2") - ) -}) - -testthat::test_that("AET04 variant 2 is produced correctly (Fill in of Treatment Groups)", { - adae2 <- adae %>% filter(ACTARM == "Xanomeline High Dose") - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - split_rows_by( - var = "TOTAL_VAR", - label_pos = "hidden", - child_labels = "visible", - indent_mod = -1L - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = "unique", - .labels = "- Any Grade -", - .indent_mods = 7L - ) %>% - count_occurrences_by_grade( - var = "AETOXGR", - grade_groups = grade_groups, - .indent_mods = 6L - ) %>% - split_rows_by( - "AEBODSYS", - child_labels = "visible", - nested = FALSE, - split_fun = drop_split_levels, - split_label = var_labels(adae)[["AEBODSYS"]], - label_pos = "topleft" - ) %>% - split_rows_by( - "AEDECOD", - child_labels = "visible", - split_fun = add_overall_level("- Overall -", trim = TRUE), - split_label = var_labels(adae)[["AEDECOD"]], - label_pos = "topleft" - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = "unique", - .labels = "- Any Grade -", - .indent_mods = 6L - ) %>% - count_occurrences_by_grade( - var = "AETOXGR", - grade_groups = grade_groups, - .indent_mods = 5L - ) %>% - append_topleft(" Grade") - - result <- lyt %>% - build_table(adae2, alt_counts_df = adsl) %>% - prune_table() %>% - sort_at_path( - path = "AEBODSYS", - scorefun = score_all_sum, - decreasing = TRUE - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEDECOD"), - scorefun = score_all_sum, - decreasing = TRUE - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) - - # Pagination also works (and sorting) - testthat::expect_silent( - pag_result <- paginate_table(result, lpp = 15) - ) - - testthat::expect_identical( - to_string_matrix(pag_result[[3]], with_spaces = FALSE)[4, 1], - "SKIN AND SUBCUTANEOUS TISSUE DISORDERS" - ) - testthat::expect_identical( - to_string_matrix(pag_result[[1]], with_spaces = FALSE)[5:6, 2], - c("0", "0") - ) -}) - -testthat::test_that("AET04 variant 3 is produced correctly (Fill in of Grades)", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - split_rows_by( - var = "TOTAL_VAR", - label_pos = "hidden", - child_labels = "visible", - indent_mod = -1L - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = "unique", - .labels = "- Any Grade -", - .indent_mods = 7L - ) %>% - count_occurrences_by_grade( - var = "AETOXGR", - grade_groups = grade_groups, - .indent_mods = 6L - ) %>% - split_rows_by( - "AEBODSYS", - child_labels = "visible", - nested = FALSE, - split_fun = drop_split_levels, - split_label = var_labels(adae)[["AEBODSYS"]], - label_pos = "topleft" - ) %>% - split_rows_by( - "AEDECOD", - child_labels = "visible", - split_fun = add_overall_level("- Overall -", trim = TRUE), - split_label = var_labels(adae)[["AEDECOD"]], - label_pos = "topleft" - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = "unique", - .labels = "- Any Grade -", - .indent_mods = 6L - ) %>% - count_occurrences_by_grade( - var = "AETOXGR", - grade_groups = grade_groups, - .indent_mods = 5L - ) %>% - append_topleft(" Grade") - - result <- lyt %>% - build_table(adae, alt_counts_df = adsl) %>% - sort_at_path( - path = "AEBODSYS", - scorefun = score_all_sum, - decreasing = TRUE - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEDECOD"), - scorefun = score_all_sum, - decreasing = TRUE - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) - - # Pagination also works (and sorting) - testthat::expect_silent( - pag_result <- paginate_table(result, lpp = 15) - ) - - testthat::expect_identical( - to_string_matrix(pag_result[[3]], with_spaces = FALSE)[4, 1], - "SKIN AND SUBCUTANEOUS TISSUE DISORDERS" - ) - testthat::expect_identical( - to_string_matrix(pag_result[[1]], with_spaces = FALSE)[5:6, 2], - c("23 (26.7%)", "17 (19.8%)") - ) -}) - -testthat::test_that("AET04 variant 4 is produced correctly (Collapsing of Grades: grades 1&2, grades 3&4&5)", { - grade_groups_1 <- list( - "Grade 1-2" = c("1", "2"), - "Grade 3-5" = c("3", "4", "5") - ) - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - split_rows_by( - var = "TOTAL_VAR", - label_pos = "hidden", - child_labels = "visible", - indent_mod = -1L - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = "unique", - .labels = "- Any Grade -", - .indent_mods = 7L - ) %>% - count_occurrences_by_grade( - var = "AETOXGR", - grade_groups = grade_groups_1, - .indent_mods = 6L - ) %>% - split_rows_by( - "AEBODSYS", - child_labels = "visible", - nested = FALSE, - split_fun = drop_split_levels, - split_label = var_labels(adae)[["AEBODSYS"]], - label_pos = "topleft" - ) %>% - split_rows_by( - "AEDECOD", - child_labels = "visible", - split_fun = add_overall_level("- Overall -", trim = TRUE), - split_label = var_labels(adae)[["AEDECOD"]], - label_pos = "topleft" - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = "unique", - .labels = "- Any Grade -", - .indent_mods = 6L - ) %>% - count_occurrences_by_grade( - var = "AETOXGR", - grade_groups = grade_groups_1, - .indent_mods = 5L - ) %>% - append_topleft(" Grade") - - result <- lyt %>% - build_table(adae, alt_counts_df = adsl) %>% - prune_table() %>% - sort_at_path( - path = "AEBODSYS", - scorefun = score_all_sum, - decreasing = TRUE - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEDECOD"), - scorefun = score_all_sum, - decreasing = TRUE - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) - - # Pagination works - testthat::expect_silent( - pag_result <- paginate_table(result, lpp = 15) - ) -}) - -# No test done for variant 5 (Using Worst Grade Flags from ADAE) since it's similar to -# variant 1 (just pre-processing the data). - -testthat::test_that( - "AET04 variant 6 is produced correctly (with an Incidence Rate of at Least 5%, totals restricted)", - { - # Simple wrapper to return subset ADAE to a threshold of xx%. - get_adae_trimmed <- function(adsl, adae, cutoff_rate) { - n_per_arm <- adsl %>% - dplyr::count(ACTARM) - - anl_terms <- adae %>% - dplyr::group_by(ACTARM, AEBODSYS, AEDECOD) %>% - dplyr::count( - unique_terms = n_distinct(USUBJID) - ) %>% - dplyr::select(-n) %>% - dplyr::ungroup() - - anl_terms <- dplyr::left_join( - anl_terms, - n_per_arm, - by = "ACTARM" - ) %>% - dplyr::mutate( - ae_rate = unique_terms / n - ) %>% - dplyr::filter(ae_rate >= cutoff_rate) %>% - dplyr::select(AEDECOD) %>% - unique() - - anl <- dplyr::left_join( - anl_terms, - adae, - by = "AEDECOD" - ) - anl - } - - adae6 <- get_adae_trimmed(adsl, adae, cutoff_rate = 0.4) - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - split_rows_by( - var = "TOTAL_VAR", - label_pos = "hidden", - child_labels = "visible", - indent_mod = -1L - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = "unique", - .labels = "- Any Grade -", - .indent_mods = 7L - ) %>% - count_occurrences_by_grade( - var = "AETOXGR", - grade_groups = grade_groups, - .indent_mods = 6L - ) %>% - split_rows_by( - "AEBODSYS", - child_labels = "visible", - nested = FALSE, - split_fun = drop_split_levels, - split_label = var_labels(adae)[["AEBODSYS"]], - label_pos = "topleft" - ) %>% - split_rows_by( - "AEDECOD", - child_labels = "visible", - split_fun = add_overall_level("- Overall -", trim = TRUE), - split_label = var_labels(adae)[["AEDECOD"]], - label_pos = "topleft" - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = "unique", - .labels = "- Any Grade -", - .indent_mods = 6L - ) %>% - count_occurrences_by_grade( - var = "AETOXGR", - grade_groups = grade_groups, - .indent_mods = 5L - ) %>% - append_topleft(" Grade") - - result <- lyt %>% - build_table(adae6, alt_counts_df = adsl) %>% - prune_table() %>% - sort_at_path( - path = "AEBODSYS", - scorefun = score_all_sum, - decreasing = TRUE - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEDECOD"), - scorefun = score_all_sum, - decreasing = TRUE - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) - - # Pagination works - testthat::expect_silent( - pag_result <- paginate_table(result, lpp = 15) - ) - } -) - -# No test done for variant 7, Adverse Events by Highest NCI CTCAE Grade -# (with an Incidence Rate of at Least X Patients, totals unrestriced). -# With this variant, the SOC level is not trimmed (even if there are no terms left). - -# NOTE: STREAM logic will only trim at term level -testthat::test_that("AET04 variant 8 is produced correctly (with an Incidence Rate of at Least X Patients)", { - cutoff <- 58L - row_condition <- has_count_in_any_col(atleast = cutoff, col_names = levels(adsl$ACTARM)) - - result <- prune_table(raw_table, keep_content_rows(my_row_condition(row_condition))) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) - - # Pagination works - testthat::expect_silent( - pag_result <- paginate_table(result, lpp = 15) - ) -}) - -# NOTE: STREAM logic will only stream at term level -testthat::test_that("AET04 variant 9 is produced correctly (with a Difference in Incidence Rate of at Least X%)", { - cutoff <- 0.1 - row_condition <- has_fractions_difference(atleast = cutoff, col_names = levels(adsl$ACTARM)) - - result <- prune_table(raw_table, keep_content_rows(my_row_condition(row_condition))) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) - - # Pagination works - testthat::expect_silent( - pag_result <- paginate_table(result, lpp = 15) - ) -}) - -# No test done for variant 10, Adverse Events by Highest NCI CTCAE Grade -# (with an Incidence Rate of at Least X%, SOCs below X% removed). -# With this variant, SOC levels above the threshold are still in the table even if -# there are no terms left. - -testthat::test_that( - "AET04 variant 11 is produced correctly (with Incidence Rate of at Least X%, all SOCs w/o preferred terms removed)", - { - cutoff <- 0.4 - row_condition <- has_fraction_in_any_col(atleast = cutoff, col_names = levels(adsl$ACTARM)) - - result <- prune_table(raw_table, keep_content_rows(my_row_condition(row_condition))) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) - - # Pagination works - testthat::expect_silent( - pag_result <- paginate_table(result, lpp = 15) - ) - } -) diff --git a/tests/testthat/test-table_aet04_pi.R b/tests/testthat/test-table_aet04_pi.R deleted file mode 100644 index d2c2fd1b..00000000 --- a/tests/testthat/test-table_aet04_pi.R +++ /dev/null @@ -1,319 +0,0 @@ -full_table_aet04_pi <- function(adsl, adae_max) { - grade_groups <- list( - "Any Grade (%)" = c("1", "2", "3", "4", "5"), - "Grade 3-4 (%)" = c("3", "4"), - "Grade 5 (%)" = "5" - ) - - col_counts <- rep(table(adsl$ACTARM), each = length(grade_groups)) - basic_table() %>% - split_cols_by("ACTARM") %>% - split_cols_by_groups("MAXAETOXGR", groups_list = grade_groups) %>% - split_rows_by( - "AEBODSYS", - child_labels = "visible", nested = FALSE, - indent_mod = -1L, split_fun = trim_levels_in_group("AEDECOD") - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = "unique", - .labels = "Total number of patients with at least one adverse event" - ) %>% - analyze_vars( - "AEDECOD", - na.rm = TRUE, - denom = "N_col", - .stats = "count_fraction", - .formats = c(count_fraction = format_fraction_threshold(0.01)) - ) %>% - build_table(adae_max, col_counts = col_counts) -} - -criteria_fun <- function(tr) { - inherits(tr, "ContentRow") -} - -adsl <- adsl_pharmaverse %>% - df_explicit_na() -adae_max <- adae_pharmaverse %>% - dplyr::group_by(ACTARM, USUBJID, AEBODSYS, AEDECOD) %>% - dplyr::summarize( - MAXAETOXGR = max(as.numeric(AETOXGR)) - ) %>% - dplyr::ungroup() %>% - dplyr::mutate( - ACTARM = factor(ACTARM), - MAXAETOXGR = factor(MAXAETOXGR), - AEBODSYS = factor(AEBODSYS), - AEDECOD = factor(AEDECOD) - ) %>% - df_explicit_na() - -testthat::test_that("AET04_PI full table is produced correctly", { - result <- full_table_aet04_pi(adsl, adae_max) %>% - sort_at_path( - path = c("AEBODSYS"), - scorefun = score_occurrences_cont_cols(col_indices = c(1, 4, 7)), - decreasing = TRUE - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEDECOD"), - scorefun = score_occurrences_cols(col_indices = c(1, 4, 7)), - decreasing = TRUE - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET04_PI variant 1 is produced correctly", { - full_table <- full_table_aet04_pi(adsl, adae_max) %>% - sort_at_path( - path = c("AEBODSYS"), - scorefun = score_occurrences_cont_cols(col_indices = c(1, 4, 7)), - decreasing = TRUE - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEDECOD"), - scorefun = score_occurrences_cols(col_indices = c(1, 4, 7)), - decreasing = TRUE - ) - at_least_5percent_any <- has_fraction_in_any_col(atleast = 0.05, col_indices = c(1, 4, 7)) - - result <- full_table %>% - trim_rows(criteria = criteria_fun) %>% - prune_table(keep_rows(at_least_5percent_any)) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET04_PI variant 2 is produced correctly", { - full_table <- full_table_aet04_pi(adsl, adae_max) %>% - sort_at_path( - path = c("AEBODSYS"), - scorefun = score_occurrences_cont_cols(col_indices = c(1, 4, 7)), - decreasing = TRUE - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEDECOD"), - scorefun = score_occurrences_cols(col_indices = c(1, 4, 7)), - decreasing = TRUE - ) - - at_least_7percent_any_drugx <- has_fraction_in_cols(atleast = 0.07, col_indices = 1) - - result <- full_table %>% - trim_rows(criteria = criteria_fun) %>% - prune_table(keep_rows(at_least_7percent_any_drugx)) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET04_PI variant 3 is produced correctly", { - full_table <- full_table_aet04_pi(adsl, adae_max) %>% - sort_at_path( - path = c("AEBODSYS"), - scorefun = score_occurrences_cont_cols(col_indices = c(1, 4, 7)), - decreasing = TRUE - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEDECOD"), - scorefun = score_occurrences_cols(col_indices = c(1, 4, 7)), - decreasing = TRUE - ) - - at_least_10percent_any <- has_fraction_in_any_col(atleast = 0.10, col_indices = c(1, 4, 7)) - - result <- full_table %>% - trim_rows(criteria = criteria_fun) %>% - prune_table(keep_rows(at_least_10percent_any)) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET04_PI variant 4 is produced correctly", { - full_table <- full_table_aet04_pi(adsl, adae_max) %>% - sort_at_path( - path = c("AEBODSYS"), - scorefun = score_occurrences_cont_cols(col_indices = c(1, 4, 7)), - decreasing = TRUE - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEDECOD"), - scorefun = score_occurrences_cols(col_indices = c(1, 4, 7)), - decreasing = TRUE - ) - - at_least_30percent_any <- has_fraction_in_any_col(atleast = 0.3, col_indices = c(1, 4, 7)) - at_least_15percent_diff <- has_fractions_difference(atleast = 0.15, col_indices = c(1, 4, 7)) - - result <- full_table %>% - trim_rows(criteria = criteria_fun) %>% - prune_table(keep_rows(at_least_30percent_any & at_least_15percent_diff)) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET04_PI variant 5 is produced correctly", { - full_table <- full_table_aet04_pi(adsl, adae_max) %>% - sort_at_path( - path = c("AEBODSYS"), - scorefun = score_occurrences_cont_cols(col_indices = c(1, 4, 7)), - decreasing = TRUE - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEDECOD"), - scorefun = score_occurrences_cols(col_indices = c(1, 4, 7)), - decreasing = TRUE - ) - - at_least_10percent_any <- has_fraction_in_any_col(atleast = 0.1, col_indices = c(1, 4, 7)) - at_least_1percent_g5 <- has_fraction_in_any_col(atleast = 0.01, col_indices = c(3, 6, 9)) - - result <- full_table %>% - trim_rows(criteria = criteria_fun) %>% - prune_table(keep_rows(at_least_10percent_any | at_least_1percent_g5)) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET04_PI variant 6 is produced correctly", { - grade_groups <- list( - "Any Grade (%)" = c("1", "2", "3", "4", "5"), - "Grade 1-2 (%)" = c("1", "2"), - "Grade 3-4 (%)" = c("3", "4"), - "Grade 5 (%)" = "5" - ) - - col_counts <- rep(table(adsl$ACTARM), each = length(grade_groups)) - full_table <- basic_table() %>% - split_cols_by("ACTARM") %>% - split_cols_by_groups("MAXAETOXGR", groups_list = grade_groups) %>% - split_rows_by( - "AEBODSYS", - child_labels = "visible", nested = FALSE, - indent_mod = -1L, split_fun = trim_levels_in_group("AEDECOD") - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = "unique", - .labels = "Total number of patients with at least one adverse event" - ) %>% - analyze_vars( - "AEDECOD", - na.rm = TRUE, - denom = "N_col", - .stats = "count_fraction", - .formats = c(count_fraction = format_fraction_threshold(0.01)) - ) %>% - build_table(adae_max, col_counts = col_counts) %>% - sort_at_path( - path = c("AEBODSYS"), - scorefun = score_occurrences_cont_cols(col_indices = c(1, 5, 9)), - decreasing = TRUE - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEDECOD"), - scorefun = score_occurrences_cols(col_indices = c(1, 5, 9)), - decreasing = TRUE - ) - - at_least_10percent_any <- has_fraction_in_any_col(atleast = 0.10, col_indices = c(1, 5, 9)) - - result <- full_table %>% - trim_rows(criteria = criteria_fun) %>% - prune_table(keep_rows(at_least_10percent_any)) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET04_PI variant 7 is produced correctly", { - grade_groups <- list( - "Any Grade (%)" = c("1", "2", "3", "4", "5"), - "Grade 3-4 (%)" = c("3", "4"), - "Grade 3-5 (%)" = c("3", "4", "5"), - "Grade 5 (%)" = "5" - ) - - col_counts <- rep(table(adsl$ACTARM), each = length(grade_groups)) - full_table <- basic_table() %>% - split_cols_by("ACTARM") %>% - split_cols_by_groups("MAXAETOXGR", groups_list = grade_groups) %>% - split_rows_by( - "AEBODSYS", - child_labels = "visible", nested = FALSE, - indent_mod = -1L, split_fun = trim_levels_in_group("AEDECOD") - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = "unique", - .labels = "Total number of patients with at least one adverse event" - ) %>% - analyze_vars( - "AEDECOD", - na.rm = TRUE, - denom = "N_col", - .stats = "count_fraction", - .formats = c(count_fraction = format_fraction_threshold(0.01)) - ) %>% - build_table(adae_max, col_counts = col_counts) %>% - sort_at_path( - path = c("AEBODSYS"), - scorefun = score_occurrences_cont_cols(col_indices = c(1, 5, 9)), - decreasing = TRUE - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEDECOD"), - scorefun = score_occurrences_cols(col_indices = c(1, 5, 9)), - decreasing = TRUE - ) - - at_least_10percent_any <- has_fraction_in_any_col(atleast = 0.10, col_indices = c(1, 5, 9)) - - result <- full_table %>% - trim_rows(criteria = criteria_fun) %>% - prune_table(keep_rows(at_least_10percent_any)) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET04_PI variant 8 is produced correctly", { - grade_groups <- list( - "Any Grade (%)" = c("1", "2", "3", "4", "5"), - "Grade 3-4 (%)" = c("3", "4"), - "Grade 5 (%)" = "5" - ) - - col_counts <- rep(table(adsl$ACTARM), each = length(grade_groups)) - full_table <- basic_table() %>% - split_cols_by("ACTARM") %>% - split_cols_by_groups("MAXAETOXGR", groups_list = grade_groups) %>% - analyze_vars( - "AEDECOD", - na.rm = TRUE, - denom = "N_col", - .stats = "count_fraction", - .formats = c(count_fraction = format_fraction_threshold(0.01)) - ) %>% - build_table(adae_max, col_counts = col_counts) - - at_least_10percent_any <- has_fraction_in_any_col(atleast = 0.1, col_indices = c(1, 4, 7)) - - result <- full_table %>% - prune_table(keep_rows(at_least_10percent_any)) %>% - sort_at_path( - path = c("AEDECOD"), - scorefun = score_occurrences_cols(col_indices = c(1, 4, 7)), - decreasing = TRUE - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_aet05.R b/tests/testthat/test-table_aet05.R deleted file mode 100644 index 919d323d..00000000 --- a/tests/testthat/test-table_aet05.R +++ /dev/null @@ -1,54 +0,0 @@ -adsl <- adsl_pharmaverse -adae <- adae_pharmaverse - -# Create portion fo adaette that is needed for tables, as pharmaverseadam doesn't have adaeatte -# Create First occurence of any AE from adae -adaette <- left_join( - select(adsl, USUBJID, ARM, TRTSDT), - select(filter(adae, AESEQ == 1), USUBJID, ASTDTM), - by = "USUBJID" -) %>% - mutate( - PARAM = "Time to first occurrence of any adverse event", - AVAL = as.numeric(difftime(TRTSDT, ASTDTM, units = "days")) / 365.25, - AVALU = "YEARS", - CNSR = ifelse(is.na(AVAL), 1, 0) - ) - -adsl <- df_explicit_na(adsl) -adaette <- df_explicit_na(adaette) - -anl <- adaette %>% - dplyr::filter(PARAM == "Time to first occurrence of any adverse event") %>% - dplyr::mutate(is_event = CNSR == 0) %>% - dplyr::mutate(n_events = as.integer(is_event)) - -testthat::test_that("AET05 variant 1 is produced correctly", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARM") %>% - estimate_incidence_rate( - vars = "AVAL", - n_events = "n_events", - control = control_incidence_rate(num_pt_year = 100) - ) - - result <- build_table(lyt, anl, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET05 variant 2 is produced correctly", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARM") %>% - estimate_incidence_rate( - vars = "AVAL", - n_events = "n_events", - control = control_incidence_rate(conf_type = "exact", num_pt_year = 100) - ) - - result <- build_table(lyt, anl, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_aet05_all.R b/tests/testthat/test-table_aet05_all.R deleted file mode 100644 index 95356732..00000000 --- a/tests/testthat/test-table_aet05_all.R +++ /dev/null @@ -1,48 +0,0 @@ -adsl <- adsl_raw -adaette <- adaette_raw - -# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels. -adsl <- df_explicit_na(adsl) -adaette <- df_explicit_na(adaette) - -# Create analysis dataset anl from the 2 parameters AEREPTTE & AETOT1 -anl_events <- adaette %>% - filter(PARAMCD == "AETOT1") %>% - select(USUBJID, ARM, ARMCD, n_events = AVAL) %>% - mutate(n_events = as.integer(n_events)) - -anl_tte <- adaette %>% - filter(PARAMCD == "AEREPTTE") %>% - select(USUBJID, ARM, ARMCD, AVAL) - -anl <- full_join(anl_tte, anl_events, by = c("USUBJID", "ARM", "ARMCD")) - -testthat::test_that("AET05_ALL variant 1 is produced correctly", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARM") %>% - estimate_incidence_rate( - vars = "AVAL", - n_events = "n_events", - control = control_incidence_rate(num_pt_year = 100) - ) - - result <- build_table(lyt, anl, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET05_ALL variant 2 is produced correctly", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARM") %>% - estimate_incidence_rate( - vars = "AVAL", - n_events = "n_events", - control = control_incidence_rate(conf_type = "exact", num_pt_year = 100) - ) - - result <- build_table(lyt, anl, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_aet06.R b/tests/testthat/test-table_aet06.R deleted file mode 100644 index d3f06467..00000000 --- a/tests/testthat/test-table_aet06.R +++ /dev/null @@ -1,194 +0,0 @@ -# Test variants 1 and 5 for AET06. Variants 2-4 are essentially identical -# to variant 1, needing only the data frame to be pre-processed -# and the baseline variable to be changed from SEX. - -adsl <- adsl_pharmaverse -adae <- adae_pharmaverse - -# Create portion fo adsub that is needed for tables, as pharmaverseadam doesn't have adsub -# This can be achieved by using certain rows of advs -adsub <- advs_pharmaverse %>% - filter(PARAMCD == "BMI" & VISIT == "BASELINE") %>% - select(STUDYID, USUBJID, PARAMCD, AVAL) %>% - unique() %>% - mutate( - AVALCAT1 = case_when( - AVAL < 18.5 ~ "<18.5", - 18.5 <= AVAL & AVAL < 25 ~ "18.5 - 24.9", - 25 <= AVAL & AVAL < 30 ~ "25 - 29.9", - AVAL >= 30 ~ ">30" - ), - AVALCAT1 = factor(AVALCAT1, levels = c("<18.5", "18.5 - 24.9", "25 - 29.9", ">30")) - ) - -adsub_bmi <- adsub %>% - dplyr::filter(PARAMCD == "BMI") %>% - dplyr::select(STUDYID, USUBJID, AVALCAT1) %>% - dplyr::mutate( - AVALCAT1 = factor(AVALCAT1, levels = c("<18.5", "18.5 - 24.9", "25 - 29.9", ">30")) - ) -adsl <- adsl %>% - dplyr::mutate( - RACE1 = dplyr::case_when( - RACE == "WHITE" ~ "WHITE", - TRUE ~ "NON-WHITE" - ), - RACE1 = factor( - RACE1, - levels = c("WHITE", "NON-WHITE") - ) - ) %>% - dplyr::left_join( - y = adsub_bmi, - by = c("STUDYID", "USUBJID") - ) - -adae_labels <- var_labels(adae) - -adae <- adae %>% - dplyr::mutate( - RACE1 = dplyr::case_when( - RACE == "WHITE" ~ "WHITE", - TRUE ~ "NON-WHITE" - ), - RACE1 = factor( - RACE1, - levels = c("WHITE", "NON-WHITE") - ) - ) %>% - dplyr::left_join( - y = adsub_bmi, - by = c("STUDYID", "USUBJID") - ) - -testthat::test_that("AET06 variant 1 is produced correctly", { - lyt <- basic_table() %>% - split_cols_by("ARM") %>% - split_cols_by("SEX") %>% - add_colcounts() %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one adverse event", - nonunique = "Overall total number of events" - ) - ) %>% - split_rows_by( - "AEBODSYS", - child_labels = "visible", - nested = FALSE, - split_fun = drop_split_levels, - indent_mod = 1L - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one adverse event", - nonunique = "Total number of events" - ) - ) %>% - count_occurrences(vars = "AEDECOD") - - result <- build_table(lyt, adae, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET06 variant 3 is produced correctly", { - lyt <- basic_table() %>% - split_cols_by("ARM") %>% - split_cols_by("AVALCAT1") %>% - add_colcounts() %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one adverse event", - nonunique = "Overall total number of events" - ) - ) %>% - split_rows_by( - "AEBODSYS", - child_labels = "visible", - nested = FALSE, - split_fun = drop_split_levels, - label_pos = "topleft", - split_label = obj_label(adae$AEBODSYS) - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one adverse event", - nonunique = "Total number of events" - ) - ) %>% - count_occurrences(vars = "AEDECOD", .indent_mods = -1L) %>% - append_varlabels(adae, "AEDECOD", indent = 1L) - - result <- build_table( - lyt = lyt, - df = adae, - alt_counts_df = adsl - ) %>% - prune_table() %>% - # Sorted by decreasing frequency across all groups by System Organ Class and Preferred Term. - sort_at_path( - path = c("AEBODSYS"), - scorefun = cont_n_allcols - ) %>% - sort_at_path( - path = c("AEBODSYS", "*", "AEDECOD"), - scorefun = score_occurrences - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET06 variant 5 is produced correctly", { - lyt <- basic_table() %>% - split_cols_by("ARM") %>% - split_cols_by("SEX") %>% - add_colcounts() %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one adverse event", - nonunique = "Overall total number of events" - ) - ) %>% - split_rows_by("AEBODSYS", child_labels = "visible", nested = FALSE) %>% - summarize_num_patients( - var = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one adverse event", - nonunique = "Total number of events" - ) - ) %>% - split_rows_by( - "AEHLT", - child_labels = "visible", - indent_mod = -1L, - split_fun = drop_split_levels - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one adverse event", - nonunique = "Total number of events" - ) - ) %>% - count_occurrences("AEDECOD") - - result <- build_table(lyt, adae, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_aet06_smq.R b/tests/testthat/test-table_aet06_smq.R deleted file mode 100644 index 95452681..00000000 --- a/tests/testthat/test-table_aet06_smq.R +++ /dev/null @@ -1,161 +0,0 @@ -# Test variants for AET06_SMQ. -adsl <- adsl_pharmaverse -adae <- adae_pharmaverse - -testthat::test_that("AET06_SMQ variant 1 is produced correctly", { - adsl_labels <- var_labels(adsl) - adae_labels <- var_labels(adae) - - adae <- adae %>% - dplyr::mutate( - SMQ1 = dplyr::case_when( - AEDECOD %in% c("NAUSEA", "VOMITING") ~ "SMQ 1 (broad)", - TRUE ~ NA_character_ - ), - SMQ2 = dplyr::case_when( - AEDECOD %in% c("VOMITING") ~ "SMQ 1 (narrow)", - TRUE ~ NA_character_ - ), - SMQ3 = dplyr::case_when( - AEDECOD %in% c("HEADACHE") ~ "AESI", - TRUE ~ NA_character_ - ) - ) - - adae_smq1 <- adae %>% - dplyr::filter(!is.na(SMQ1)) %>% - dplyr::rename(SMQ = SMQ1) %>% - dplyr::select(-SMQ2, -SMQ3) - - adae_smq2 <- adae %>% - dplyr::filter(!is.na(SMQ2)) %>% - dplyr::rename(SMQ = SMQ2) %>% - dplyr::select(-SMQ1, -SMQ3) - - adae_smq3 <- adae %>% - dplyr::filter(!is.na(SMQ3)) %>% - dplyr::rename(SMQ = SMQ3) %>% - dplyr::select(-SMQ1, -SMQ2) - - adae_f <- rbind(adae_smq1, adae_smq2, adae_smq3) - - var_labels(adae_f) <- c(adae_labels, "SMQ" = "Standardised MedDRA Queries") - - lyt <- basic_table() %>% - split_cols_by("ARM") %>% - split_cols_by("SEX") %>% - add_colcounts() %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique"), - .labels = c(unique = "Total number of patients with at least one adverse event") - ) %>% - split_rows_by( - "SMQ", - child_labels = "visible", - nested = FALSE, - split_fun = drop_split_levels - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one adverse event", - nonunique = "Total number of events" - ) - ) %>% - count_occurrences(vars = "AEDECOD") - - result <- build_table(lyt, adae_f, alt_counts_df = adsl) %>% - sort_at_path(path = c("SMQ", "*", "AEDECOD"), scorefun = score_occurrences) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET06_SMQ variant 2 is produced correctly", { - adsl_labels <- var_labels(adsl) - adae_labels <- var_labels(adae) - - adsl <- adsl %>% - dplyr::mutate( - AGE65 = dplyr::case_when( - AGE >= 65 ~ ">= 65", - TRUE ~ "< 65" - ), - AGE65 = factor(AGE65, levels = c(">= 65", "< 65")) - ) - - var_labels(adsl) <- c(adsl_labels, "AGE65" = "AGE65 GROUP") - - adae <- adae %>% - dplyr::mutate( - SMQ1 = dplyr::case_when( - AEDECOD %in% c("NAUSEA", "VOMITING") ~ "SMQ 1 (broad)", - TRUE ~ NA_character_ - ), - SMQ2 = dplyr::case_when( - AEDECOD %in% c("VOMITING") ~ "SMQ 1 (narrow)", - TRUE ~ NA_character_ - ), - SMQ3 = dplyr::case_when( - AEDECOD %in% c("HEADACHE") ~ "AESI", - TRUE ~ NA_character_ - ), - AGE65 = dplyr::case_when( - AGE >= 65 ~ ">= 65", - TRUE ~ "< 65" - ), - AGE65 = factor(AGE65, levels = c(">= 65", "< 65")) - ) - - adae_smq1 <- adae %>% - dplyr::filter(!is.na(SMQ1)) %>% - dplyr::rename(SMQ = SMQ1) %>% - dplyr::select(-SMQ2, -SMQ3) - - adae_smq2 <- adae %>% - dplyr::filter(!is.na(SMQ2)) %>% - dplyr::rename(SMQ = SMQ2) %>% - dplyr::select(-SMQ1, -SMQ3) - - adae_smq3 <- adae %>% - dplyr::filter(!is.na(SMQ3)) %>% - dplyr::rename(SMQ = SMQ3) %>% - dplyr::select(-SMQ1, -SMQ2) - - adae_f <- rbind(adae_smq1, adae_smq2, adae_smq3) - - var_labels(adae_f) <- c(adae_labels, "SMQ" = "Standardised MedDRA Queries", "AGE65" = "AGE65 GROUP") - - lyt <- basic_table() %>% - split_cols_by("ARM") %>% - split_cols_by("AGE65") %>% - add_colcounts() %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique"), - .labels = c(unique = "Total number of patients with at least one adverse event") - ) %>% - split_rows_by( - "SMQ", - child_labels = "visible", - nested = FALSE, - split_fun = drop_split_levels - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one adverse event", - nonunique = "Total number of events" - ) - ) %>% - count_occurrences(vars = "AEDECOD") - - result <- build_table(lyt, adae_f, alt_counts_df = adsl) %>% - sort_at_path(path = c("SMQ", "*", "AEDECOD"), scorefun = score_occurrences) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_aet07.R b/tests/testthat/test-table_aet07.R deleted file mode 100644 index 230ca2ec..00000000 --- a/tests/testthat/test-table_aet07.R +++ /dev/null @@ -1,79 +0,0 @@ -# 1. Preprocess ADAE so that deaths do not occur in arm "Xanomeline High Dose". -# 2. Concatenate AEBODSYS and AEDECOD per GDSR output standard AET07. -preprocess_adae <- function(adae) { - set.seed(1, kind = "Mersenne-Twister") - adae %>% - dplyr::mutate( - # Convert AESDTH to character for next step. - AESDTH = as.character(AESDTH), - # For demonstration purpose only, - # make "Xanomeline High Dose" as the arm without AE leading to death. - AESDTH = dplyr::case_when( - ARM == "Xanomeline Low Dose" ~ NA_character_, - TRUE ~ AESDTH - ), - AESDTH = as.factor(AESDTH), - SOC_PT = factor(paste(AEBODSYS, "/", AEDECOD)) - ) %>% - dplyr::filter(AESDTH == "Y") -} - -adsl <- adsl_pharmaverse -adae <- adae_pharmaverse - -testthat::test_that("AET07 variant 1 is produced correctly", { - adae <- adae %>% - preprocess_adae() - - lyt <- basic_table() %>% - split_cols_by("ACTARM", split_fun = drop_split_levels) %>% - add_colcounts() %>% - analyze_num_patients( - vars = "USUBJID", - .stats = "unique", - .labels = c(unique = "Total number of deaths"), - show_labels = "hidden" - ) %>% - count_occurrences( - vars = "SOC_PT" - ) - - result <- build_table(lyt, adae, alt_counts_df = adsl) %>% - sort_at_path( - path = "SOC_PT", - scorefun = score_occurrences, - decreasing = TRUE - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET07 variant 2 is produced correctly", { - adae <- adae %>% - preprocess_adae() - - lyt <- basic_table() %>% - split_cols_by("ACTARM") %>% - add_colcounts() %>% - analyze_num_patients( - vars = "USUBJID", - .stats = "unique", - .labels = c(unique = "Total number of deaths"), - show_labels = "hidden" - ) %>% - count_occurrences( - vars = "SOC_PT" - ) - - result <- build_table(lyt, adae, alt_counts_df = adsl) %>% - prune_table() %>% - sort_at_path( - path = "SOC_PT", - scorefun = score_occurrences, - decreasing = TRUE - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_aet09.R b/tests/testthat/test-table_aet09.R deleted file mode 100644 index 719629e1..00000000 --- a/tests/testthat/test-table_aet09.R +++ /dev/null @@ -1,104 +0,0 @@ -adsl <- adsl_pharmaverse %>% - df_explicit_na() - -adae <- adae_pharmaverse %>% - df_explicit_na() - -testthat::test_that("AET09 variant 1 is produced correctly, AE related to study drug", { - adae_r <- adae[adae$AEREL %in% c("PROBABLE", "POSSIBLE", "REMOTE"), ] - - lyt <- basic_table() %>% - split_cols_by(var = "ARM") %>% - add_colcounts() %>% - add_overall_col(label = "All Patients") %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one adverse event related to study drug", - nonunique = "Overall total number of events related to study drug" - ) - ) %>% - split_rows_by( - "AEBODSYS", - child_labels = "visible", - nested = FALSE, - split_fun = drop_split_levels - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one adverse event related to study drug", - nonunique = "Total number of events related to study drug" - ) - ) %>% - count_occurrences(vars = "AEDECOD", .indent_mods = -1L) - - result <- build_table(lyt, adae_r, alt_counts_df = adsl) - - result <- result %>% - prune_table() %>% - sort_at_path(path = c("AEBODSYS"), scorefun = cont_n_onecol(4)) %>% - sort_at_path(path = c("AEBODSYS", "*", "AEDECOD"), scorefun = score_occurrences) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AET09 variant 2 is produced correctly, AE related to study drug (including high-level terms)", { - adae_r <- adae[adae$AEREL %in% c("PROBABLE", "POSSIBLE", "REMOTE"), ] - - lyt <- basic_table() %>% - split_cols_by(var = "ARM") %>% - add_colcounts() %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one adverse event related to study drug", - nonunique = "Overall total number of events related to study drug" - ) - ) %>% - split_rows_by( - "AEBODSYS", - child_labels = "visible", - nested = FALSE, - split_fun = drop_split_levels - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one adverse event related to study drug", - nonunique = "Total number of events related to study drug" - ) - ) %>% - split_rows_by( - "AEHLT", - child_labels = "visible", - nested = TRUE, - indent_mod = -1L, - split_fun = drop_split_levels - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one adverse event related to study drug", - nonunique = "Total number of events related to study drug" - ) - ) %>% - count_occurrences(vars = "AEDECOD", .indent_mods = -1L) - - result <- build_table(lyt, adae_r, alt_counts_df = adsl) %>% - prune_table() - - result <- result %>% - sort_at_path(path = c("AEBODSYS"), scorefun = cont_n_allcols) %>% - sort_at_path(path = c("AEBODSYS", "*", "AEHLT"), scorefun = cont_n_allcols) %>% - sort_at_path(path = c("AEBODSYS", "*", "AEHLT", "*", "AEDECOD"), scorefun = score_occurrences) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_aet09_smq.R b/tests/testthat/test-table_aet09_smq.R deleted file mode 100644 index e3c5babb..00000000 --- a/tests/testthat/test-table_aet09_smq.R +++ /dev/null @@ -1,130 +0,0 @@ -# Test all variants of AET09 SMQ, adverse events related to stuy drug by standardized MEDDRA query -stack_adae_by_smq <- function(adae, smq) { - l_df <- lapply(smq, function(ae_grp) { - keep <- !(is.na(adae[[ae_grp]])) - df <- adae[keep, ] - df[["SMQ"]] <- ae_grp - df - }) - do.call(rbind, l_df) -} - -adsl <- adsl_pharmaverse -adae <- adae_pharmaverse - -testthat::test_that("AET09 variant 1 (AEs related to study drug by SMQ) is produced correctly", { - adsl_labels <- var_labels(adsl) - adae_labels <- var_labels(adae) - - adae <- adae %>% - dplyr::mutate( - SMQ1 = dplyr::case_when( - AEDECOD %in% c("NAUSEA", "VOMITING") ~ "SMQ 1 (broad)", - TRUE ~ NA_character_ - ), - SMQ2 = dplyr::case_when( - AEDECOD %in% c("VOMITING") ~ "SMQ 1 (narrow)", - TRUE ~ NA_character_ - ), - SMQ3 = dplyr::case_when( - AEDECOD %in% c("HEADACHE") ~ "AESI", - TRUE ~ NA_character_ - ) - ) - - adae <- stack_adae_by_smq(adae, c("SMQ1")) - adae_r <- adae[adae$AREL %in% c("PROBABLE", "REMOTE", "POSSIBLE"), ] - - lyt <- basic_table() %>% - split_cols_by("ARM") %>% - add_colcounts() %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique"), - .labels = c( - unique = "Total number of patients with at least one adverse event related to study drug" - ) - ) %>% - split_rows_by( - "SMQ", - child_labels = "visible", - nested = FALSE, - split_fun = drop_split_levels - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one adverse event related to study drug", - nonunique = "Total number of events related to study drug" - ) - ) %>% - count_occurrences(vars = "AEDECOD", .indent_mods = -1L) - - result <- build_table(lyt, adae_r, alt_counts_df = adsl) %>% - sort_at_path(path = c("SMQ"), scorefun = cont_n_allcols) %>% - sort_at_path(path = c("SMQ", "*", "AEDECOD"), scorefun = score_occurrences) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that( - "AET09 variant 2 (AEs related to study drug by SMQ with customized queries) is produced correctly", - { - adsl_labels <- var_labels(adsl) - adae_labels <- var_labels(adae) - - adae <- adae %>% - dplyr::mutate( - SMQ1 = dplyr::case_when( - AEDECOD %in% c("NAUSEA", "VOMITING") ~ "SMQ 1 (broad)", - TRUE ~ NA_character_ - ), - SMQ2 = dplyr::case_when( - AEDECOD %in% c("VOMITING") ~ "SMQ 1 (narrow)", - TRUE ~ NA_character_ - ), - SMQ3 = dplyr::case_when( - AEDECOD %in% c("HEADACHE") ~ "AESI", - TRUE ~ NA_character_ - ) - ) - - adae <- stack_adae_by_smq(adae, c("SMQ1", "SMQ2", "SMQ3")) - adae_r <- adae[adae$AREL %in% c("PROBABLE", "REMOTE", "POSSIBLE"), ] - - lyt <- basic_table() %>% - split_cols_by("ARM") %>% - add_colcounts() %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique"), - .labels = c( - unique = "Total number of patients with at least one adverse event related to study drug" - ) - ) %>% - split_rows_by( - "SMQ", - child_labels = "visible", - nested = FALSE, - split_fun = drop_split_levels - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one adverse event related to study drug", - nonunique = "Total number of events related to study drug" - ) - ) %>% - count_occurrences(vars = "AEDECOD", .indent_mods = -1L) - - result <- build_table(lyt, adae_r, alt_counts_df = adsl) %>% - sort_at_path(path = c("SMQ"), scorefun = cont_n_allcols) %>% - sort_at_path(path = c("SMQ", "*", "AEDECOD"), scorefun = score_occurrences) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) - } -) diff --git a/tests/testthat/test-table_aet10.R b/tests/testthat/test-table_aet10.R deleted file mode 100644 index 2ba1cd9d..00000000 --- a/tests/testthat/test-table_aet10.R +++ /dev/null @@ -1,24 +0,0 @@ -# Tests the single variant of AET10 - -adsl <- adsl_pharmaverse -adae <- adae_pharmaverse - -testthat::test_that("AET10 default variant is produced correctly", { - result1 <- basic_table() %>% - split_cols_by(var = "ARM", split_fun = add_overall_level("All Patients", first = FALSE)) %>% - add_colcounts() %>% - count_occurrences(vars = "AEDECOD") %>% - build_table(adae, alt_counts_df = adsl) - - result2 <- prune_table( - result1, - keep_rows( - has_fraction_in_any_col(atleast = 0.30, col_names = levels(adsl$ARM)) - ) - ) - - result <- sort_at_path(result2, path = c("AEDECOD"), scorefun = score_occurrences) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_aovt01.R b/tests/testthat/test-table_aovt01.R deleted file mode 100644 index de877d28..00000000 --- a/tests/testthat/test-table_aovt01.R +++ /dev/null @@ -1,73 +0,0 @@ -# Tests all variants of AOVT01 - -adsl <- adsl_raw -adqs <- adqs_raw - -testthat::test_that("AOVT01 variant with single endpoint is produced correctly", { - adqs_single <- adqs %>% - dplyr::filter( - AVISIT == "WEEK 1 DAY 8", # single time point - PARAMCD == "FKSI-FWB" # single end point - ) %>% - dplyr::mutate(CHG = ifelse(BMEASIFL == "Y", CHG, NA)) # only analyze evaluable population - - result <- basic_table() %>% - split_cols_by("ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% - add_colcounts() %>% - summarize_ancova( - vars = "CHG", - variables = list(arm = "ARMCD", covariates = NULL), - conf_level = 0.95, var_labels = "Unadjusted comparison", - .labels = c(lsmean = "Mean", lsmean_diff = "Difference in Means"), - table_names = "unadjusted" - ) %>% - summarize_ancova( - vars = "CHG", - variables = list(arm = "ARMCD", covariates = c("BASE", "STRATA1")), - conf_level = 0.95, var_labels = "Adjusted comparison (covariates BASE and STRATA1)", - table_names = "adjusted" - ) %>% - build_table(adqs_single, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AOVT01 variant with multiple endpoints is produced correctly", { - adqs_multi <- dplyr::filter(adqs, AVISIT == "WEEK 1 DAY 8") - n_per_arm <- table(adsl$ARM) - - result <- basic_table() %>% - split_cols_by("ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% - add_colcounts() %>% - split_rows_by("PARAMCD") %>% - summarize_ancova( - vars = "CHG", - variables = list(arm = "ARMCD", covariates = c("BASE", "STRATA1")), - conf_level = 0.95, var_labels = "Adjusted mean" - ) %>% - build_table(adqs_multi, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("AOVT01 variant with proportional weights is produced correctly", { - adqs_multi <- dplyr::filter(adqs, AVISIT == "WEEK 1 DAY 8") - n_per_arm <- table(adsl$ARM) - - result <- basic_table() %>% - split_cols_by("ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% - add_colcounts() %>% - split_rows_by("PARAMCD") %>% - summarize_ancova( - vars = "CHG", - variables = list(arm = "ARMCD", covariates = c("BASE", "STRATA1")), - conf_level = 0.95, var_labels = "Adjusted mean", - weights_emmeans = "proportional" - ) %>% - build_table(adqs_multi, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_aovt02.R b/tests/testthat/test-table_aovt02.R deleted file mode 100644 index e88be29d..00000000 --- a/tests/testthat/test-table_aovt02.R +++ /dev/null @@ -1,43 +0,0 @@ -adsl <- adsl_raw -adqs <- adqs_raw - -# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels. -adsl <- df_explicit_na(adsl) -adqs <- df_explicit_na(adqs) - -adqs_single <- adqs %>% - filter( - AVISIT == "WEEK 1 DAY 8", - PARAMCD == "FKSI-FWB" - ) %>% - mutate(CHG = ifelse(BMEASIFL == "Y", CHG, NA)) - -testthat::test_that("AOVT02 is produced correctly", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% - append_varlabels(adqs_single, "PARAM") %>% - summarize_ancova( - vars = "CHG", - variables = list(arm = "ARMCD", covariates = NULL), - conf_level = 0.95, - var_labels = "Unadjusted comparison", - .labels = c(lsmean = "Mean", lsmean_diff = "Difference in Means"), - table_names = "unadjusted" - ) %>% - summarize_ancova( - vars = "CHG", - variables = list(arm = "ARMCD", covariates = c("BASE", "STRATA1")), - conf_level = 0.95, - var_labels = "Adjusted comparison (covariates BASE and STRATA1)", - table_names = "adjusted" - ) - - result <- build_table( - lyt = lyt, - df = adqs_single, - alt_counts_df = adsl - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_aovt03.R b/tests/testthat/test-table_aovt03.R deleted file mode 100644 index ce76d7c9..00000000 --- a/tests/testthat/test-table_aovt03.R +++ /dev/null @@ -1,45 +0,0 @@ -adsl <- adsl_raw -adqs <- adqs_raw - -adqs_in <- adqs %>% - filter(AVISIT %in% c("WEEK 1 DAY 8", "WEEK 2 DAY 15", "WEEK 5 DAY 36")) %>% - droplevels() %>% - filter(PARAM %in% c("BFI All Questions", "Fatigue Interference")) %>% - mutate(CHG = ifelse(BMEASIFL == "Y", CHG, NA)) # only analyze evaluable population - -testthat::test_that("AOVT03 is produced correctly", { - result <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% - split_rows_by("PARAM", split_fun = drop_split_levels) %>% - summarize_ancova( - vars = "CHG", - variables = list(arm = "ARMCD", covariates = c("BASE", "AVISIT", "AVISIT*ARMCD")), - conf_level = 0.95, - var_labels = "WEEK 1 DAY 8", - table_names = "WEEK 1 DAY 8", - interaction_y = "WEEK 1 DAY 8", - interaction_item = "AVISIT" - ) %>% - summarize_ancova( - vars = "CHG", - variables = list(arm = "ARMCD", covariates = c("BASE", "AVISIT", "AVISIT*ARMCD")), - conf_level = 0.95, - var_labels = "WEEK 2 DAY 15", - table_names = "WEEK 2 DAY 15", - interaction_y = "WEEK 2 DAY 15", - interaction_item = "AVISIT" - ) %>% - summarize_ancova( - vars = "CHG", - variables = list(arm = "ARMCD", covariates = c("BASE", "AVISIT", "AVISIT*ARMCD")), - conf_level = 0.95, - var_labels = "WEEK 5 DAY 36", - table_names = "WEEK 5 DAY 36", - interaction_y = "WEEK 5 DAY 36", - interaction_item = "AVISIT" - ) %>% - build_table(adqs_in, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_cfbt01.R b/tests/testthat/test-table_cfbt01.R deleted file mode 100644 index 4ce238b7..00000000 --- a/tests/testthat/test-table_cfbt01.R +++ /dev/null @@ -1,65 +0,0 @@ -adsl <- adsl_raw -adqs <- adqs_raw - -adsl <- df_explicit_na(adsl) -adqs <- df_explicit_na(adqs) - -adqs <- adqs %>% - dplyr::filter( - PARAM == "BFI All Questions", - AVISIT != "SCREENING" - ) - -split_fun <- drop_split_levels - -testthat::test_that("CFBT01 default variant is produced correctly", { - afun <- function(x, .var, .spl_context, ...) { - n_fun <- sum(!is.na(x), na.rm = TRUE) - if (n_fun == 0) { - mean_sd_fun <- c(NA, NA) - median_fun <- NA - min_max_fun <- c(NA, NA) - } else { - mean_sd_fun <- c(mean(x, na.rm = TRUE), sd(x, na.rm = TRUE)) - median_fun <- median(x, na.rm = TRUE) - min_max_fun <- c(min(x), max(x)) - } - is_chg <- .var == "CHG" - is_baseline <- .spl_context$value[which(.spl_context$split == "AVISIT")] == "BASELINE" - if (is_baseline && is_chg) n_fun <- mean_sd_fun <- median_fun <- min_max_fun <- NULL - - in_rows( - "n" = n_fun, - "Mean (SD)" = mean_sd_fun, - "Median" = median_fun, - "Min - Max" = min_max_fun, - .formats = list("n" = "xx", "Mean (SD)" = "xx.xx (xx.xx)", "Median" = "xx.xx", "Min - Max" = "xx.xx - xx.xx"), - .format_na_strs = list("n" = "NE", "Mean (SD)" = "NE (NE)", "Median" = "NE", "Min - Max" = "NE - NE") - ) - } - - lyt <- basic_table() %>% - split_cols_by("ARM") %>% - split_rows_by( - "PARAM", - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adqs$PARAM) - ) %>% - split_rows_by( - "AVISIT", - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adqs$AVISIT) - ) %>% - split_cols_by_multivar( - vars = c("AVAL", "CHG"), - varlabels = c("Value at Visit", "Change from\nBaseline") - ) %>% - analyze_colvars(afun = afun) - - result <- build_table(lyt, adqs) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_cmht01.R b/tests/testthat/test-table_cmht01.R deleted file mode 100644 index 666aae16..00000000 --- a/tests/testthat/test-table_cmht01.R +++ /dev/null @@ -1,123 +0,0 @@ -adsl <- adsl_raw -adqs <- adqs_raw - -# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels. -adsl <- df_explicit_na(adsl) -adqs <- df_explicit_na(adqs) - -testthat::test_that("CMHT01 variant 1 is produced correctly", { - anl_01 <- adqs %>% - filter(PARAMCD == "FKSI-FWB" & AVISIT == "WEEK 1 DAY 8") %>% - mutate(is_rsp = PCHG > 15) %>% - mutate(ARM = relevel(ARM, ref = "A: Drug X")) %>% - var_relabel(ARM = "Description of Planned Arm") %>% - mutate(strata = interaction(STRATA1, STRATA2, drop = TRUE)) - - lyt_01 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% - estimate_proportion(vars = "is_rsp", table_names = "est_prop") %>% - estimate_proportion_diff( - var_labels = "Unstratified Analysis", - vars = "is_rsp", - show_labels = "visible", - table_names = "est_prop_diff" - ) %>% - test_proportion_diff(vars = "is_rsp", table_names = "test_prop") %>% - estimate_odds_ratio(vars = "is_rsp", table_names = "est_or") %>% - estimate_proportion_diff( - var_labels = "Stratified Analysis", - vars = "is_rsp", - show_labels = "visible", - method = "cmh", - variables = list(strata = "strata"), - table_names = "est_prop_diff_strat" - ) %>% - test_proportion_diff( - vars = "is_rsp", - method = "cmh", - variables = list(strata = "strata"), - table_names = "test_prop_strat" - ) %>% - estimate_odds_ratio( - vars = "is_rsp", - variables = list(strata = "strata", arm = "ARM"), - table_names = "est_or_strat" - ) - - # https://github.com/therneau/survival/issues/240 - withr::with_options( - opts_partial_match_old, - result <- build_table( - lyt = lyt_01, - df = anl_01, - alt_counts_df = adsl - ) - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("CMHT01 variant 2 is produced correctly", { - anl_02 <- adqs %>% - filter(AVISIT == "WEEK 1 DAY 8") %>% - mutate(is_rsp = PCHG > 15) %>% - mutate(PARAM = droplevels(PARAM)) %>% - mutate(ARM = relevel(ARM, ref = "A: Drug X")) %>% - var_relabel(ARM = "Description of Planned Arm") %>% - mutate(strata = interaction(STRATA1, STRATA2, drop = TRUE)) - - var_labels(anl_02)["PARAM"] <- "Parameter" - - split_fun <- drop_split_levels - - lyt_02 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% - split_rows_by( - var = "PARAM", - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(anl_02$PARAM) - ) %>% - estimate_proportion(vars = "is_rsp", table_names = "est_prop") %>% - estimate_proportion_diff( - var_labels = "Unstratified Analysis", - vars = "is_rsp", - show_labels = "visible", - table_names = "est_prop_diff" - ) %>% - test_proportion_diff(vars = "is_rsp", table_names = "test_prop") %>% - estimate_odds_ratio(vars = "is_rsp", table_names = "est_or") %>% - estimate_proportion_diff( - var_labels = "Stratified Analysis", - vars = "is_rsp", - show_labels = "visible", - method = "cmh", - variables = list(strata = "strata"), - table_names = "est_prop_diff_strat" - ) %>% - test_proportion_diff( - vars = "is_rsp", - method = "cmh", - variables = list(strata = "strata"), - table_names = "test_prop_strat" - ) %>% - estimate_odds_ratio( - vars = "is_rsp", - variables = list(strata = "strata", arm = "ARM"), - table_names = "est_or_strat" - ) - - # https://github.com/therneau/survival/issues/240 - withr::with_options( - opts_partial_match_old, - result <- build_table( - lyt = lyt_02, - df = anl_02, - alt_counts_df = adsl - ) - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_cmt01.R b/tests/testthat/test-table_cmt01.R deleted file mode 100644 index 47438288..00000000 --- a/tests/testthat/test-table_cmt01.R +++ /dev/null @@ -1,136 +0,0 @@ -adsl <- adsl_pharmaverse -adcm <- adcm_pharmaverse - -testthat::test_that("CMT01 default variant (Concomitant medications) is produced correctly", { - adcm_c <- adcm %>% dplyr::filter(ATIREL == "CONCOMITANT") - - result <- basic_table() %>% - split_cols_by(var = "ARM", split_fun = add_overall_level("All Patients", first = FALSE)) %>% - add_colcounts() %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one treatment", - nonunique = "Total number of treatments" - ) - ) %>% - split_rows_by("CMCLAS", - split_fun = drop_split_levels, child_labels = "visible", - nested = FALSE, - indent_mod = 1L - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one treatment", - nonunique = "Total number of treatments" - ) - ) %>% - count_occurrences(vars = "CMDECOD") %>% - build_table(adcm_c, alt_counts_df = adsl) %>% - sort_at_path(path = c("CMCLAS", "*", "CMDECOD"), scorefun = score_occurrences) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("CMT01 variant 1 (prior medications) is produced correctly", { - adcm_p <- adcm %>% dplyr::filter(ATIREL == "PRIOR") - - result <- basic_table() %>% - split_cols_by(var = "ARM", split_fun = add_overall_level("All Patients", first = FALSE)) %>% - add_colcounts() %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one treatment", - nonunique = "Total number of treatments" - ) - ) %>% - split_rows_by("CMCLAS", - split_fun = drop_split_levels, child_labels = "visible", - nested = FALSE, - indent_mod = 1L - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one treatment", - nonunique = "Total number of treatments" - ) - ) %>% - count_occurrences(vars = "CMDECOD") %>% - build_table(adcm_p, alt_counts_df = adsl) %>% - sort_at_path(path = c("CMCLAS", "*", "CMDECOD"), scorefun = score_occurrences) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("CMT01 variant 3 (Concomitant medications) is produced correctly", { - adcm_c <- adcm %>% dplyr::filter(ATIREL == "CONCOMITANT") - - result <- basic_table() %>% - split_cols_by(var = "ARM", split_fun = add_overall_level("All Patients", first = FALSE)) %>% - add_colcounts() %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one treatment", - nonunique = "Total number of treatments" - ) - ) %>% - split_rows_by("CMCLAS", - split_fun = drop_split_levels, - child_labels = "visible", - nested = FALSE, - indent_mod = 1L - ) %>% - summarize_num_patients( - var = "USUBJID", - .labels = c(unique = "Total number of patients with at least one treatment"), - .stats = "unique" - ) %>% - count_occurrences(vars = "CMDECOD") %>% - build_table(adcm_c, alt_counts_df = adsl) %>% - sort_at_path(path = c("CMCLAS", "*", "CMDECOD"), scorefun = score_occurrences) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("CMT01 variant 4 (Concomitant medications) is produced correctly", { - adcm_c <- adcm %>% dplyr::filter(ATIREL == "CONCOMITANT") - - result <- basic_table() %>% - split_cols_by(var = "ARM", split_fun = add_overall_level("All Patients", first = FALSE)) %>% - add_colcounts() %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c("Total number of patients with at least one treatment (%)", "Total number of treatments") - ) %>% - split_rows_by("CMCLAS", - split_fun = drop_split_levels, - child_labels = "visible", - indent_mod = 1L, - nested = FALSE - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c("Total number of patients with at least one treatment (%)", "Total number of treatments") - ) %>% - count_occurrences(vars = "CMDECOD") %>% - build_table(adcm_c, alt_counts_df = adsl) %>% - sort_at_path(path = c("CMCLAS", "*", "CMDECOD"), scorefun = score_occurrences, decreasing = TRUE) %>% - sort_at_path(path = c("CMCLAS"), scorefun = cont_n_onecol(4), decreasing = TRUE) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_cmt01a.R b/tests/testthat/test-table_cmt01a.R deleted file mode 100644 index 2f8c38e7..00000000 --- a/tests/testthat/test-table_cmt01a.R +++ /dev/null @@ -1,194 +0,0 @@ -adsl <- adsl_pharmaverse -adcm <- adcm_pharmaverse - -adcm$CMSEQ <- as.factor(adcm$CMSEQ) - -adsl <- df_explicit_na(adsl) -adcm <- df_explicit_na(adcm) - -adsl <- adsl %>% - filter(SAFFL == "Y") - -adcm <- adcm %>% - filter(SAFFL == "Y" & ATIREL == "CONCOMITANT") %>% - var_relabel(CMDECOD = "Other Treatment") - -testthat::test_that("CMT01A variant 1 is produced correctly", { - split_fun <- drop_split_levels - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - analyze_num_patients( - vars = "USUBJID", - count_by = "CMSEQ", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one treatment", - nonunique = "Total number of treatments" - ) - ) %>% - split_rows_by( - "ATC2", - child_labels = "visible", - nested = FALSE, - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adcm$ATC2) - ) %>% - summarize_num_patients( - var = "USUBJID", - count_by = "CMSEQ", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one treatment", - nonunique = "Total number of treatments" - ) - ) %>% - count_occurrences(vars = "CMDECOD", .indent_mods = -1L) %>% - append_varlabels(adcm, "CMDECOD", indent = 1L) - - result <- build_table(lyt = lyt, df = adcm, alt_counts_df = adsl) %>% - prune_table() %>% - # Sort lowest level terms by descending frequency. - sort_at_path( - path = c("ATC2", "*", "CMDECOD"), - scorefun = score_occurrences - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("CMT01A variant 2 is produced correctly", { - split_fun <- drop_split_levels - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - analyze_num_patients( - vars = "USUBJID", - count_by = "CMSEQ", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one treatment", - nonunique = "Total number of treatments" - ) - ) %>% - split_rows_by( - "ATC1", - child_labels = "visible", - nested = FALSE, - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adcm$ATC1) - ) %>% - summarize_num_patients( - var = "USUBJID", - count_by = "CMSEQ", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one treatment", - nonunique = "Total number of treatments" - ) - ) %>% - count_occurrences(vars = "CMDECOD", .indent_mods = -1L) %>% - append_varlabels(adcm, "CMDECOD", indent = 1L) - - result <- build_table(lyt = lyt, df = adcm, alt_counts_df = adsl) %>% - prune_table() %>% - # Sort lowest level terms by descending frequency. - sort_at_path( - path = c("ATC1", "*", "CMDECOD"), - scorefun = score_occurrences - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("CMT01A variant 3 is produced correctly", { - split_fun <- drop_split_levels - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - analyze_num_patients( - vars = "USUBJID", - count_by = "CMSEQ", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one treatment", - nonunique = "Total number of treatments" - ) - ) %>% - split_rows_by( - "ATC2", - child_labels = "visible", - nested = FALSE, - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adcm$ATC2) - ) %>% - summarize_num_patients( - var = "USUBJID", - count_by = "CMSEQ", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one treatment", - nonunique = "Total number of treatments" - ) - ) %>% - count_occurrences(vars = "CMDECOD", .indent_mods = -1L) %>% - append_varlabels(adcm, "CMDECOD", indent = 1L) - - result <- build_table(lyt = lyt, df = adcm, alt_counts_df = adsl) %>% - prune_table() %>% - sort_at_path(path = c("ATC2"), scorefun = cont_n_allcols) %>% - sort_at_path(path = c("ATC2", "*", "CMDECOD"), scorefun = score_occurrences) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("CMT01A variant 4 is produced correctly", { - split_fun <- drop_split_levels - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - analyze_num_patients( - vars = "USUBJID", - count_by = "CMSEQ", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one treatment", - nonunique = "Total number of treatments" - ) - ) %>% - split_rows_by( - "ATC2", - child_labels = "visible", - nested = FALSE, - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adcm$ATC2) - ) %>% - summarize_num_patients( - var = "USUBJID", - count_by = "CMSEQ", - .stats = c("unique"), - .labels = c( - unique = "Total number of patients with at least one treatment" - ) - ) %>% - count_occurrences(vars = "CMDECOD", .indent_mods = -1L) %>% - append_varlabels(adcm, "CMDECOD", indent = 1L) - - result <- build_table(lyt = lyt, df = adcm, alt_counts_df = adsl) %>% - prune_table() %>% - # Sort lowest level terms by descending frequency. - sort_at_path( - path = c("ATC2", "*", "CMDECOD"), - scorefun = score_occurrences - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_cmt01b.R b/tests/testthat/test-table_cmt01b.R deleted file mode 100644 index 0edae628..00000000 --- a/tests/testthat/test-table_cmt01b.R +++ /dev/null @@ -1,220 +0,0 @@ -adsl <- adsl_pharmaverse -adcm <- adcm_pharmaverse - -adcm$CMSEQ <- as.factor(adcm$CMSEQ) - -# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels. -adsl <- df_explicit_na(adsl) -adcm <- df_explicit_na(adcm) - -# Keep only safety-evaluable patients and concomitant medications -adsl <- adsl %>% - filter(SAFFL == "Y") - -adcm <- adcm %>% - filter(SAFFL == "Y" & ATIREL == "CONCOMITANT") - -testthat::test_that("CMT01B variant 1 is produced correctly", { - split_fun <- drop_split_levels - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARM") %>% - analyze_num_patients( - vars = "USUBJID", - count_by = "CMSEQ", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one treatment", - nonunique = "Total number of treatments" - ) - ) %>% - split_rows_by( - "ATC1", - child_labels = "visible", - nested = FALSE, - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adcm$ATC1) - ) %>% - split_rows_by( - "ATC2", - child_labels = "visible", - nested = TRUE, - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adcm$ATC2) - ) %>% - split_rows_by( - "ATC3", - child_labels = "visible", - nested = TRUE, - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adcm$ATC3) - ) %>% - split_rows_by( - "ATC4", - child_labels = "visible", - nested = TRUE, - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adcm$ATC4) - ) %>% - append_topleft(" Other Treatment") %>% - summarize_num_patients( - var = "USUBJID", - count_by = "CMSEQ", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one treatment", - nonunique = "Total number of treatments" - ) - ) %>% - count_occurrences(vars = "CMDECOD", .indent_mods = -1L) - - result <- build_table( - lyt = lyt, - df = adcm, - alt_counts_df = adsl - ) %>% - prune_table() %>% - # Sort lowest level terms by descending frequency. - sort_at_path( - path = c("ATC1", "*", "ATC2", "*", "ATC3", "*", "ATC4", "*", "CMDECOD"), - scorefun = score_occurrences - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("CMT01B variant 2 is produced correctly", { - split_fun <- drop_split_levels - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARM") %>% - analyze_num_patients( - vars = "USUBJID", - count_by = "CMSEQ", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one treatment", - nonunique = "Total number of treatments" - ) - ) %>% - split_rows_by( - "ATC3", - child_labels = "visible", - nested = FALSE, - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adcm$ATC3) - ) %>% - split_rows_by( - "ATC2", - child_labels = "visible", - nested = TRUE, - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adcm$ATC2) - ) %>% - summarize_num_patients( - var = "USUBJID", - count_by = "CMSEQ", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one treatment", - nonunique = "Total number of treatments" - ) - ) %>% - count_occurrences(vars = "CMDECOD", .indent_mods = -1L) %>% - append_topleft(" Other Treatment") - - result <- build_table( - lyt = lyt, - df = adcm, - alt_counts_df = adsl - ) %>% - prune_table() %>% - # Sort lowest level terms by descending frequency. - sort_at_path( - path = c("ATC3", "*", "ATC2", "*", "CMDECOD"), - scorefun = score_occurrences - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("CMT01B variant 4 is produced correctly", { - split_fun <- drop_split_levels - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARM") %>% - split_rows_by( - "ATC1", - child_labels = "visible", - nested = FALSE, - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adcm$ATC1) - ) %>% - split_rows_by( - "ATC2", - child_labels = "visible", - nested = TRUE, - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adcm$ATC2) - ) %>% - split_rows_by( - "ATC3", - child_labels = "visible", - nested = TRUE, - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adcm$ATC3) - ) %>% - summarize_num_patients( - var = "USUBJID", - count_by = "CMSEQ", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one treatment", - nonunique = "Total number of treatments" - ) - ) %>% - split_rows_by( - "ATC4", - child_labels = "visible", - nested = TRUE, - indent_mod = -1L, - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adcm$ATC4) - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = c("unique"), - .labels = c( - unique = "Total number of patients with at least one treatment" - ) - ) %>% - count_occurrences(vars = "CMDECOD", .indent_mods = -1L) %>% - append_topleft(" Other Treatment") - - result <- build_table( - lyt = lyt, - df = adcm, - alt_counts_df = adsl - ) %>% - prune_table() %>% - # Sort lowest level terms by descending frequency. - sort_at_path( - path = c("ATC1", "*", "ATC2", "*", "ATC3", "*", "ATC4", "*", "CMDECOD"), - scorefun = score_occurrences - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_cmt02_pt.R b/tests/testthat/test-table_cmt02_pt.R deleted file mode 100644 index 2a3b1505..00000000 --- a/tests/testthat/test-table_cmt02_pt.R +++ /dev/null @@ -1,43 +0,0 @@ -# Test single variant for CMT02_PT - -adsl <- adsl_pharmaverse -adcm <- adcm_pharmaverse - -adcm$CMSEQ <- as.factor(adcm$CMSEQ) - -adsl <- df_explicit_na(adsl, na_level = "No Coding Available") -adcm <- df_explicit_na(adcm, na_level = "No Coding Available") - -adsl <- adsl %>% - filter(SAFFL == "Y") - -adcm <- adcm %>% filter(ATIREL == "CONCOMITANT") - -testthat::test_that("CMT02_PT default variant is produced correctly", { - split_fun <- drop_split_levels - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - add_overall_col("All Patients") %>% - analyze_num_patients( - vars = "USUBJID", - count_by = "CMSEQ", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one treatment", - nonunique = "Total number of treatments" - ), - show_labels = "hidden" - ) %>% - count_occurrences(vars = "CMDECOD") %>% - append_topleft(paste("\nOther Treatment")) - - result <- build_table(lyt = lyt, df = adcm, alt_counts_df = adsl) %>% - sort_at_path( - path = c("CMDECOD"), - scorefun = score_occurrences - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_coxt01.R b/tests/testthat/test-table_coxt01.R deleted file mode 100644 index 9f919a53..00000000 --- a/tests/testthat/test-table_coxt01.R +++ /dev/null @@ -1,98 +0,0 @@ -adtte <- adtte_raw -saved_labels <- var_labels(adtte) -adtte_f <- adtte %>% - dplyr::filter( - PARAMCD == "OS", - ARMCD %in% c("ARM A", "ARM B"), - SEX %in% c("F", "M"), - RACE %in% c("ASIAN", "BLACK OR AFRICAN AMERICAN", "WHITE") - ) %>% - dplyr::mutate( - ARMCD = stats::relevel(droplevels(ARMCD), "ARM B"), - SEX = droplevels(SEX), - RACE = droplevels(RACE), - EVENT = 1 - CNSR - ) -var_labels(adtte_f) <- c(saved_labels, "Event") - -testthat::test_that("1. Cox Regression", { - variables <- list( - time = "AVAL", event = "EVENT", arm = "ARMCD", - covariates = c("SEX", "RACE", "AGE") - ) - - result <- basic_table() %>% - summarize_coxreg( - variables = variables - ) %>% - build_table(df = adtte_f) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("2. Cox Regression (with Interaction Term)", { - variables <- list( - time = "AVAL", event = "EVENT", arm = "ARMCD", - covariates = c("SEX", "RACE", "AGE") - ) - control <- control_coxreg(interaction = TRUE) - - result <- basic_table() %>% - summarize_coxreg( - variables = variables, - control = control, - .stats = c("n", "hr", "ci", "pval", "pval_inter") - ) %>% - build_table(df = adtte_f) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("3. Cox Regression (specifying covariates)", { - variables <- list( - time = "AVAL", event = "EVENT", arm = "ARMCD", - covariates = c("SEX", "RACE", "AGE") - ) - control <- control_coxreg(interaction = TRUE) - at <- list(AGE = c(30, 40, 50)) - - result <- basic_table() %>% - summarize_coxreg( - variables = variables, - control = control, - at = at, - .stats = c("n", "hr", "ci", "pval", "pval_inter") - ) %>% - build_table(df = adtte_f) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - - -testthat::test_that("4. Cox Regression (setting strata, ties, and alpha level)", { - variables <- list( - time = "AVAL", event = "EVENT", arm = "ARMCD", - covariates = c("SEX", "RACE", "AGE") - ) - control <- control_coxreg( - interaction = TRUE, - conf_level = 0.90, - ties = "efron" - ) - at <- list(AGE = c(30, 40, 50)) - - result <- basic_table() %>% - summarize_coxreg( - variables = variables, - control = control, - at = at, - .stats = c("n", "hr", "ci", "pval", "pval_inter") - ) %>% - build_table(df = adtte_f) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_coxt02.R b/tests/testthat/test-table_coxt02.R deleted file mode 100644 index f0b5e678..00000000 --- a/tests/testthat/test-table_coxt02.R +++ /dev/null @@ -1,49 +0,0 @@ -adtte <- adtte_raw -adtte_f <- adtte %>% - dplyr::filter( - PARAMCD == "OS", - SEX %in% c("F", "M"), - RACE %in% c("ASIAN", "BLACK OR AFRICAN AMERICAN", "WHITE") - ) %>% - dplyr::mutate( - ARMCD = stats::relevel(ARMCD, "ARM B"), - SEX = droplevels(SEX), - RACE = droplevels(RACE), - EVENT = 1 - CNSR - ) %>% - var_relabel( - SEX = "Sex", - AGE = "Age" - ) - -testthat::test_that("COXT02 default variant 1 is produced correctly", { - variables <- list( - time = "AVAL", event = "EVENT", arm = "ARMCD", - covariates = c("SEX", "AGE") - ) - - result <- basic_table() %>% - summarize_coxreg(variables = variables, multivar = TRUE) %>% - build_table(adtte_f) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("COXT02 variant 5 is produced correctly", { - variables <- list( - time = "AVAL", event = "EVENT", arm = "ARMCD", - covariates = c("SEX", "AGE"), strata = "RACE" - ) - control <- control_coxreg( - conf_level = 0.9, - ties = "efron" - ) - - result <- basic_table() %>% - summarize_coxreg(variables = variables, control = control, multivar = TRUE, .stats = c("hr", "ci")) %>% - build_table(adtte_f) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_disclosures.R b/tests/testthat/test-table_disclosures.R deleted file mode 100644 index bca47db4..00000000 --- a/tests/testthat/test-table_disclosures.R +++ /dev/null @@ -1,212 +0,0 @@ -adae <- adae_raw - -adsl_local <- local({ - set.seed(1) - # nolint start - adsl_f <- adsl_raw %>% - dplyr::filter(SAFFL == "Y") %>% # Safety Evaluable Population - dplyr::mutate( - STSTFL = dplyr::case_when( - is.na(RANDDT) ~ "N", # derive flag for "Started Study", - TRUE ~ "Y" - ), - COMPSTUD = dplyr::case_when( - EOSSTT == "COMPLETED" ~ "Y", # derive flag for "Completed Study" - TRUE ~ "N" - ), - DISCSTUD = dplyr::case_when( - EOSSTT == "DISCONTINUED" ~ "Y", # derive flag for "Discontinued study" - TRUE ~ "N" - ), - AGEGRP = dplyr::case_when( - AGE < 65 ~ "< 65 yrs", - AGE >= 65 ~ ">= 65 yrs" - ), - ETHNIC = sample( - c("Ethnicity 1", "Ethnicity 2", "Unknown"), - nrow(.), - replace = TRUE - ) - ) - columns <- c("STSTFL", "COMPSTUD", "DISCSTUD", "AGEGRP", "ETHNIC") - labels <- c("Start Study", "Study Completion Flag", "Study Discontinuation Flag", "Age Group", "Ethnicity") - var_labels(adsl_f)[columns] <- labels - - adsl_f$AGEGRP <- factor(adsl_f$AGEGRP, levels = c("< 65 yrs", ">= 65 yrs")) - adsl_f$ETHNIC <- factor(adsl_f$ETHNIC, levels = c("Ethnicity 1", "Ethnicity 2", "Unknown")) - # adsl_f <- df_explicit_na(adsl_f) - # nolint end - adsl_f -}) - -get_adae_trimmed <- function(adsl, adae, cutoff_rate) { - n_per_arm <- adsl %>% - dplyr::count(ARM) - - anl_terms <- adae %>% - dplyr::group_by(ARM, AEBODSYS, AEDECOD) %>% - dplyr::summarise( - unique_terms = dplyr::n_distinct(USUBJID), - .groups = "drop_last" - ) %>% - dplyr::ungroup() - - anl_terms <- dplyr::left_join( - anl_terms, - n_per_arm, - by = "ARM" - ) %>% - dplyr::mutate( - ae_rate = unique_terms / n - ) %>% - dplyr::filter(ae_rate >= cutoff_rate) %>% - dplyr::select(AEDECOD) %>% - unique() - - anl <- dplyr::left_join( - anl_terms, - adae, - by = "AEDECOD", - multiple = "all" - ) - anl -} - -testthat::test_that("Patient Disposition table is produced correctly", { - adsl <- adsl_local - - result <- basic_table() %>% - split_cols_by("ARM", split_fun = add_overall_level("All Patients", first = FALSE)) %>% - add_colcounts() %>% - count_values( - "STSTFL", - values = "Y", - .labels = c(count_fraction = "Started Study"), - .formats = c(count_fraction = "xx (xx.xx%)") - ) %>% - count_values( - "COMPSTUD", - values = "Y", - .labels = c(count_fraction = "Completed Study"), - .formats = c(count_fraction = "xx (xx.xx%)") - ) %>% - count_values( - "DISCSTUD", - values = "Y", - .labels = c(count_fraction = "Discontinued Study"), - .formats = c(count_fraction = "xx (xx.xx%)"), - ) %>% - analyze_vars( - "DCSREAS", - .stats = "count_fraction", - show_labels = "hidden", - .indent_mods = c(count_fraction = 2L), - .formats = c(count_fraction = "xx (xx.xx%)"), - denom = "N_col" - ) %>% - build_table(adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("Demographic table is produced correctly", { - adsl <- adsl_local - vars <- c("AGE", "AGEGRP", "SEX", "RACE", "ETHNIC") - var_labels <- c( - "Age (yr)", - "Age group (yr)", - "Sex", - "Race", - "Ethnicity" - ) - result <- basic_table() %>% - split_cols_by("ARM", split_fun = add_overall_level("All Patients", first = FALSE)) %>% - add_colcounts() %>% - analyze_vars(vars = vars, var_labels = var_labels) %>% - build_table(adsl) %>% - prune_table() - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("Enrollment by Country Table is produced correctly", { - adsl <- adsl_local - result <- basic_table() %>% - split_cols_by("ARM", split_fun = add_overall_level("All Patients", first = FALSE)) %>% - add_colcounts() %>% - analyze_vars("COUNTRY", .formats = c(count_fraction = "xx (xx.xx%)")) %>% - build_table(adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("Death table is produced correctly", { - adsl <- adsl_local - - result <- basic_table() %>% - split_cols_by("ARM", split_fun = add_overall_level("All Patients", first = FALSE)) %>% - add_colcounts() %>% - count_patients_with_event( - "USUBJID", - filters = c("AESDTH" = "Y"), - .labels = c(count_fraction = "Total Number of Deaths"), - .formats = c(count_fraction = "xx (xx.xx%)") - ) %>% - build_table(adae, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("Table of Serious Adverse Events is produced correctly (for one specific treatment arm)", { - adae_serious <- adae %>% dplyr::filter(AESER == "Y", SAFFL == "Y") - adae_serious_arm <- adae_serious %>% dplyr::filter(ARM == "A: Drug X") - - filters_list <- list( - related = with_label(c(AEREL = "Y"), "Events (Related)"), - fatal = with_label(c(AESDTH = "Y"), "Events (Fatal)"), - fatal_related = with_label(c(AEREL = "Y", AESDTH = "Y"), "Events (Fatal & Related)") - ) - - result <- basic_table() %>% - summarize_patients_events_in_cols( - filters_list = filters_list, - empty_stats = c("all", "related", "fatal", "fatal_related"), - custom_label = "Total number of patients with at least one serious adverse event" - ) %>% - split_rows_by("AEBODSYS", nested = FALSE, split_fun = drop_split_levels, indent_mod = -1L) %>% - split_rows_by("AEDECOD", split_fun = drop_split_levels) %>% - summarize_patients_events_in_cols( - filters_list = filters_list, - col_split = FALSE - ) %>% - build_table(adae_serious_arm) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("Table of Non-Serious Adverse Events is produced correctly", { - adsl <- adsl_local - adae_nonser <- adae %>% dplyr::filter(AESER != "Y", SAFFL == "Y") - adae_trim <- get_adae_trimmed(adsl, adae_nonser, cutoff_rate = 0.05) - - result <- basic_table() %>% - split_cols_by("ARM") %>% - add_colcounts() %>% - summarize_patients_events_in_cols( - custom_label = "Total number of patients with at least one non-SAE and number of events" - ) %>% - split_rows_by("AEBODSYS", nested = FALSE, split_fun = drop_split_levels, indent_mod = -1L) %>% - split_rows_by("AEDECOD", split_fun = drop_split_levels) %>% - summarize_patients_events_in_cols( - col_split = FALSE - ) %>% - build_table(adae_trim, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_dmt01.R b/tests/testthat/test-table_dmt01.R deleted file mode 100644 index e6593012..00000000 --- a/tests/testthat/test-table_dmt01.R +++ /dev/null @@ -1,170 +0,0 @@ -# Tests DMT01 -set.seed(1) - -adsl <- pharmaverseadam::adsl -adsl <- adsl %>% - mutate(BMRKR1 = rnorm(nrow(adsl), 3.5, 10)) %>% - mutate(STRATA1 = factor(sample(c("A", "B", "C"), nrow(adsl), TRUE))) -advs <- pharmaverseadam::advs -adsub <- adsub_raw - -adsl <- df_explicit_na(adsl) -advs <- df_explicit_na(advs) -adsub <- df_explicit_na(adsub) - -adsl <- adsl %>% - mutate( - SEX = factor(case_when( - SEX == "M" ~ "Male", - SEX == "F" ~ "Female", - SEX == "U" ~ "Unknown", - SEX == "UNDIFFERENTIATED" ~ "Undifferentiated" - )), - AGEGR1 = factor( - case_when( - between(AGE, 18, 40) ~ "18-40", - between(AGE, 41, 64) ~ "41-64", - AGE > 64 ~ ">=65" - ), - levels = c("18-40", "41-64", ">=65") - ), - BMRKR1_CAT = factor( - case_when( - BMRKR1 < 3.5 ~ "LOW", - BMRKR1 >= 3.5 & BMRKR1 < 10 ~ "MEDIUM", - BMRKR1 >= 10 ~ "HIGH" - ), - levels = c("LOW", "MEDIUM", "HIGH") - ) - ) %>% - var_relabel( - BMRKR1_CAT = "Biomarker 1 Categories" - ) - -get_param_advs <- function(pname, plabel) { - ds <- advs %>% - filter(PARAM == plabel & AVISIT == "BASELINE") %>% - select(USUBJID, AVAL) - - colnames(ds) <- c("USUBJID", pname) - - ds -} - -get_param_adsub <- function(pname, plabel) { - ds <- adsub %>% - filter(PARAM == plabel) %>% - select(USUBJID, AVAL) - - colnames(ds) <- c("USUBJID", pname) - - ds -} -adsl <- adsl %>% - left_join(get_param_advs("SBP", "Systolic Blood Pressure"), by = "USUBJID") %>% - left_join(get_param_advs("DBP", "Diastolic Blood Pressure"), by = "USUBJID") %>% - left_join(get_param_advs("WGT", "Weight"), by = "USUBJID") %>% - left_join(get_param_adsub("BBMISI", "Baseline BMI"), by = "USUBJID") - -testthat::test_that("DMT01 variant 1 is produced correctly", { - vars <- c("AGE", "AGEGR1", "SEX", "ETHNIC", "RACE", "BMRKR1") - var_labels <- c( - "Age (yr)", - "Age Group", - "Sex", - "Ethnicity", - "Race", - "Continous Level Biomarker 1" - ) - - result <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ACTARM") %>% - add_overall_col("All Patients") %>% - analyze_vars( - vars = vars, - var_labels = var_labels - ) %>% - build_table(adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("DMT01 variant 2 is produced correctly", { - vars <- c("AGE", "AGEGR1", "SEX", "ETHNIC", "RACE", "BMRKR1_CAT") - var_labels <- c( - "Age (yr)", - "Age Group", - "Sex", - "Ethnicity", - "Race", - "Biomarker 1 Categories" - ) - - result <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ACTARM") %>% - analyze_vars( - vars = vars, - var_labels = var_labels - ) %>% - build_table(adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("DMT01 variant 3 is produced correctly", { - split_fun <- drop_split_levels - - result <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ACTARM") %>% - analyze_vars( - vars = c("AGE", "SEX", "RACE"), - var_labels = c("Age", "Sex", "Race") - ) %>% - split_rows_by("STRATA1", - split_fun = split_fun - ) %>% - analyze_vars("BMRKR1") %>% - build_table(adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("DMT01 variant 4 is produced correctly", { - result <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ACTARM") %>% - analyze_vars( - vars = c("AGE", "SEX", "RACE", "DBP", "SBP"), - var_labels = c( - "Age (yr)", - "Sex", - "Race", - "Diastolic Blood Pressure", - "Systolic Blood Pressure" - ) - ) %>% - build_table(adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("DMT01 variant 5 is produced correctly", { - result <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ACTARM") %>% - analyze_vars( - vars = c("AGE", "SEX", "RACE", "BBMISI"), - var_labels = c( - "Age (yr)", - "Sex", - "Race", - "Baseline BMI" - ) - ) %>% - build_table(adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_dort01.R b/tests/testthat/test-table_dort01.R deleted file mode 100644 index 3f758a1b..00000000 --- a/tests/testthat/test-table_dort01.R +++ /dev/null @@ -1,245 +0,0 @@ -# Test variants of DORT01 - -preproc_adtte <- function(adtte) { - anl <- adtte %>% - dplyr::filter(PARAMCD == "CRSD" & BMEASIFL == "Y") %>% - dplyr::mutate( - AVAL = day2month(AVAL), - is_event = CNSR == 0, - is_not_event = CNSR == 1, - EVNT1 = factor( - dplyr::case_when( - is_event == TRUE ~ "Responders with subsequent event (%)", - is_event == FALSE ~ "Responders without subsequent event (%)" - ), - levels = c("Responders with subsequent event (%)", "Responders without subsequent event (%)") - ), - EVNTDESC = factor(EVNTDESC) - ) - anl -} - -adsl <- adsl_raw -adtte_local <- adtte_raw %>% - preproc_adtte() - -testthat::test_that("DORT01 variant 1 is produced correctly", { - adtte <- adtte_local - - result <- basic_table() %>% - split_cols_by(var = "ARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% - add_colcounts() %>% - count_values( - vars = "USUBJID", - values = unique(adtte$USUBJID), - .labels = c(count = "Responders"), - .stats = "count" - ) %>% - analyze_vars( - vars = "is_event", - .stats = "count_fraction", - .labels = c(count_fraction = "Responders with subsequent event (%)"), - .indent_mods = c(count_fraction = 1L), - show_labels = "hidden", - ) %>% - split_rows_by( - "EVNT1", - split_label = "Earliest contributing event", - split_fun = keep_split_levels("Responders with subsequent event (%)"), - label_pos = "visible", - child_labels = "hidden", - indent_mod = 2L, - ) %>% - split_rows_by("EVNTDESC", split_fun = drop_split_levels) %>% - summarize_row_groups(format = "xx") %>% - analyze_vars( - vars = "is_not_event", - .stats = "count_fraction", - .labels = c(count_fraction = "Responders without subsequent event (%)"), - .indent_mods = c(count_fraction = 1L), - nested = FALSE, - show_labels = "hidden" - ) %>% - surv_time( - vars = "AVAL", - var_labels = "Duration of response (Months)", - is_event = "is_event", - table_names = "duration_response" - ) %>% - surv_timepoint( - vars = "AVAL", - var_labels = "Months duration", - is_event = "is_event", - time_point = 12 - ) %>% - build_table(adtte, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("DORT01 variant 2 (selecting sectons) is produced correctly", { - adtte <- adtte_local - - result <- basic_table() %>% - split_cols_by(var = "ARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% - add_colcounts() %>% - count_values( - vars = "USUBJID", - values = unique(adtte$USUBJID), - .labels = c(count = "Responders"), - .stats = "count" - ) %>% - analyze_vars( - vars = "is_event", - .stats = "count_fraction", - .labels = c(count_fraction = "Responders with subsequent event (%)"), - .indent_mods = c(count_fraction = 1L), - show_labels = "hidden", - ) %>% - split_rows_by( - "EVNT1", - split_label = "Earliest contributing event", - split_fun = keep_split_levels("Responders with subsequent event (%)"), - label_pos = "visible", - child_labels = "hidden", - indent_mod = 2L, - ) %>% - split_rows_by("EVNTDESC", split_fun = drop_split_levels) %>% - summarize_row_groups(format = "xx") %>% - analyze_vars( - vars = "is_not_event", - .stats = "count_fraction", - .labels = c(count_fraction = "Responders without subsequent event (%)"), - .indent_mods = c(count_fraction = 1L), - nested = FALSE, - show_labels = "hidden" - ) %>% - surv_time( - vars = "AVAL", - var_labels = "Duration of response (Months)", - is_event = "is_event", - table_names = "duration_response" - ) %>% - coxph_pairwise( - vars = "AVAL", - is_event = "is_event", - var_labels = c("Unstratified Analysis"), - control = control_coxph(pval_method = "log-rank"), - table_names = "coxph_unstratified" - ) %>% - build_table(adtte, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("DORT01 variant 3 (modifying conftype and alpha level) is produced correctly", { - adtte <- adtte_local - - result <- basic_table() %>% - split_cols_by(var = "ARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% - add_colcounts() %>% - count_values( - vars = "USUBJID", - values = unique(adtte$USUBJID), - .labels = c(count = "Responders"), - .stats = "count" - ) %>% - analyze_vars( - vars = "is_event", - .stats = "count_fraction", - .labels = c(count_fraction = "Responders with subsequent event (%)"), - .indent_mods = c(count_fraction = 1L), - show_labels = "hidden", - ) %>% - split_rows_by( - "EVNT1", - split_label = "Earliest contributing event", - split_fun = keep_split_levels("Responders with subsequent event (%)"), - label_pos = "visible", - child_labels = "hidden", - indent_mod = 2L, - ) %>% - split_rows_by("EVNTDESC", split_fun = drop_split_levels) %>% - summarize_row_groups(format = "xx") %>% - analyze_vars( - vars = "is_not_event", - .stats = "count_fraction", - .labels = c(count_fraction = "Responders without subsequent event (%)"), - .indent_mods = c(count_fraction = 1L), - nested = FALSE, - show_labels = "hidden" - ) %>% - surv_time( - vars = "AVAL", - var_labels = "Duration of response (Months)", - is_event = "is_event", - control = control_surv_time(conf_level = 0.90, conf_type = "log-log") - ) %>% - surv_timepoint( - vars = "AVAL", - var_labels = "Months duration", - is_event = "is_event", - time_point = 12, - control = control_surv_timepoint(conf_level = 0.975) - ) %>% - build_table(adtte, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("DORT01 variant 4 (modifying time point for the “xx duration”) is produced correctly", { - adtte <- adtte_local - - result <- basic_table() %>% - split_cols_by(var = "ARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% - add_colcounts() %>% - count_values( - vars = "USUBJID", - values = unique(adtte$USUBJID), - .labels = c(count = "Responders"), - .stats = "count" - ) %>% - analyze_vars( - vars = "is_event", - .stats = "count_fraction", - .labels = c(count_fraction = "Responders with subsequent event (%)"), - .indent_mods = c(count_fraction = 1L), - show_labels = "hidden", - ) %>% - split_rows_by( - "EVNT1", - split_label = "Earliest contributing event", - split_fun = keep_split_levels("Responders with subsequent event (%)"), - label_pos = "visible", - child_labels = "hidden", - indent_mod = 2L, - ) %>% - split_rows_by("EVNTDESC", split_fun = drop_split_levels) %>% - summarize_row_groups(format = "xx") %>% - analyze_vars( - vars = "is_not_event", - .stats = "count_fraction", - .labels = c(count_fraction = "Responders without subsequent event (%)"), - .indent_mods = c(count_fraction = 1L), - nested = FALSE, - show_labels = "hidden" - ) %>% - surv_time( - vars = "AVAL", - var_labels = "Duration of response (Months)", - is_event = "is_event" - ) %>% - surv_timepoint( - vars = "AVAL", - var_labels = "Months duration", - is_event = "is_event", - time_point = 6 - ) %>% - build_table(adtte, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_dst01.R b/tests/testthat/test-table_dst01.R deleted file mode 100644 index 2796adec..00000000 --- a/tests/testthat/test-table_dst01.R +++ /dev/null @@ -1,90 +0,0 @@ -adsl <- adsl_raw - -adsl <- df_explicit_na(adsl) %>% - mutate(EOSSTT = factor(EOSSTT, levels = c("COMPLETED", "ONGOING", "DISCONTINUED"))) - -adsl_gp_added <- adsl %>% - mutate(DCSREASGP = case_when( - DCSREAS %in% c("ADVERSE EVENT", "DEATH") ~ "Safety", - (DCSREAS != "" & !DCSREAS %in% c("ADVERSE EVENT", "DEATH")) ~ "Non-Safety", - DCSREAS == "" ~ "" - ) %>% factor(levels = c("Safety", "Non-Safety", ""))) - -set.seed(1) -adsl_eotstt_added <- adsl_gp_added %>% - mutate( - EOTSTT = sample( - c("ONGOING", "COMPLETED", "DISCONTINUED"), - size = nrow(adsl), - replace = TRUE - ) %>% factor(levels = c("COMPLETED", "ONGOING", "DISCONTINUED")) - ) - -testthat::test_that("DST01 default variant is produced correctly", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by( - "ACTARM", - split_fun = add_overall_level("All Patients", first = FALSE) - ) %>% - count_occurrences( - "EOSSTT", - show_labels = "hidden" - ) %>% - analyze_vars( - "DCSREAS", - .stats = "count_fraction", - denom = "N_col", - show_labels = "hidden", - .indent_mods = c(count_fraction = 1L) - ) - - result1 <- build_table(lyt = lyt, df = adsl) - - res <- testthat::expect_silent(result1) - testthat::expect_snapshot(res) -}) - -testthat::test_that("DST01 variants 2 and 3 are produced correctly", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by( - "ACTARM", - split_fun = add_overall_level("All Patients", first = FALSE) - ) %>% - count_occurrences( - "EOSSTT", - show_labels = "hidden" - ) %>% - split_rows_by("DCSREASGP", indent_mod = 1L) %>% - analyze_vars( - "DCSREAS", - .stats = "count_fraction", - denom = "N_col", - show_labels = "hidden" - ) - - tbl <- build_table(lyt = lyt, df = adsl_gp_added) - result2 <- prune_table(tbl) # remove rows containing all zeros - - res <- testthat::expect_silent(result2) - testthat::expect_snapshot(res) - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by( - "ACTARM", - split_fun = add_overall_level("All Patients", first = FALSE) - ) %>% - count_occurrences( - "EOTSTT", - show_labels = "hidden" - ) - - tbl <- build_table(lyt = lyt, df = adsl_eotstt_added) - tbl <- prune_table(tbl) # remove rows containing all zeros - - # Combine tables - col_info(result2) <- col_info(tbl) - result3 <- rbind(result2, tbl) - - res <- testthat::expect_silent(result3) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_dtht01.R b/tests/testthat/test-table_dtht01.R deleted file mode 100644 index bae362d9..00000000 --- a/tests/testthat/test-table_dtht01.R +++ /dev/null @@ -1,159 +0,0 @@ -# Test variants of DTHT01 - -adsl <- adsl_raw - -adsl <- df_explicit_na(adsl) %>% filter(SAFFL == "Y") - -adsl$DTHCAT <- factor(adsl$DTHCAT, levels = c("ADVERSE EVENT", "PROGRESSIVE DISEASE", "OTHER", "")) - -testthat::test_that("DTHT01 variant 1 is produced correctly", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM", split_fun = add_overall_level("All Patients", first = FALSE)) %>% - count_values( - "DTHFL", - values = "Y", - .labels = c(count_fraction = "Total number of deaths"), - .formats = c(count_fraction = "xx (xx.x%)") - ) %>% - analyze_vars(vars = c("DTHCAT"), var_labels = c("Primary Cause of Death")) - - result <- build_table(lyt, df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("DTHT01 variant 2 is produced correctly", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM", split_fun = add_overall_level("All Patients", first = FALSE)) %>% - count_values( - "DTHFL", - values = "Y", - .labels = c(count_fraction = "Total number of deaths"), - .formats = c(count_fraction = "xx (xx.x%)") - ) %>% - analyze_vars(vars = c("DTHCAT"), var_labels = c("Primary Cause of Death")) %>% - split_rows_by("DTHCAT", split_fun = keep_split_levels("OTHER"), child_labels = "hidden") %>% - analyze_vars( - "DTHCAUS", - .stats = "count_fraction", - .indent_mods = c("count_fraction" = 2L), - show_labels = "hidden" - ) %>% - analyze_vars( - vars = "LDDTHGR1", - nested = FALSE, - var_labels = "Days from last drug administration", - show_labels = "visible" - ) %>% - split_rows_by( - "LDDTHGR1", - split_fun = remove_split_levels(""), - split_label = "Primary cause by days from last study drug administration", - label_pos = "visible" - ) %>% - analyze_vars("DTHCAT") - - result <- build_table(lyt, df = adsl) %>% prune_table() - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("DTHT01 variant 3 is produced correctly", { - dthcaus_levels <- levels(adsl[adsl$DTHCAT == "OTHER", ]$DTHCAUS) - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM", split_fun = add_overall_level("All Patients", first = FALSE)) %>% - count_values( - "DTHFL", - values = "Y", - .labels = c(count_fraction = "Total number of deaths"), - .formats = c(count_fraction = "xx (xx.x%)") - ) %>% - analyze_vars( - vars = c("DTHCAT"), - var_labels = c("Primary Cause of Death"), - table_names = "primary_cause" - ) %>% - split_rows_by( - "DTHCAT", - split_fun = keep_split_levels("OTHER"), - child_labels = "hidden" - ) %>% - count_values( - "DTHCAUS", - values = dthcaus_levels[5], - .labels = c(count_fraction = "Post-study reportings of death"), - .formats = c(count_fraction = "xx (xx.x%)"), - .indent_mods = c(count_fraction = 2L), - table_names = "post_study_deaths" - ) %>% - count_values( - "DTHCAUS", - values = dthcaus_levels[-5], - .labels = c(count_fraction = "All other causes"), - .formats = c(count_fraction = "xx (xx.x%)"), - .indent_mods = c(count_fraction = 2L), - table_names = "all_other_causes" - ) - - result <- build_table(lyt, df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("DTHT01 variant 4 is produced correctly", { - dthcaus_levels <- levels(adsl[adsl$DTHCAT == "OTHER", ]$DTHCAUS) - - # create a helper variable DTHCAUS_other - adsl <- adsl %>% - mutate( - DTHCAUS_other = factor(ifelse( - DTHCAT == "OTHER" & DTHCAUS != "Post-study reporting of death", as.character(DTHCAUS), NA - ), levels = c("LOST TO FOLLOW UP", "SUICIDE", "UNKNOWN", "MISSING")) %>% explicit_na(label = "") - ) - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM", split_fun = add_overall_level("All Patients", first = FALSE)) %>% - count_values( - "DTHFL", - values = "Y", - .labels = c(count_fraction = "Total number of deaths"), - .formats = c(count_fraction = "xx (xx.x%)") - ) %>% - analyze_vars( - vars = c("DTHCAT"), - var_labels = c("Primary Cause of Death"), - table_names = "primary_cause" - ) %>% - split_rows_by("DTHCAT", split_fun = keep_split_levels("OTHER"), child_labels = "hidden") %>% - count_values( - "DTHCAUS", - values = dthcaus_levels[5], - .labels = c(count_fraction = "Post-study reportings of death"), - .formats = c(count_fraction = "xx (xx.x%)"), - .indent_mods = c(count_fraction = 2L), - table_names = "post_study_deaths" - ) %>% - count_values( - "DTHCAUS", - values = dthcaus_levels[-5], - .labels = c(count_fraction = "All other causes"), - .formats = c(count_fraction = "xx (xx.x%)"), - .indent_mods = c(count_fraction = 2L), - table_names = "all_other_causes" - ) %>% - analyze_vars( - "DTHCAUS_other", - .stats = "count_fraction", - .indent_mods = c("count_fraction" = 3L), - show_labels = "hidden" - ) - - result <- build_table(lyt, df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_egt01.R b/tests/testthat/test-table_egt01.R deleted file mode 100644 index af1e272a..00000000 --- a/tests/testthat/test-table_egt01.R +++ /dev/null @@ -1,55 +0,0 @@ -# Test the single variant for EGT01 - -adsl <- adsl_pharmaverse -adeg <- adeg_pharmaverse - -adsl <- df_explicit_na(adsl) -adeg <- df_explicit_na(adeg) - -adeg_f <- adeg %>% - filter(ANL01FL == "Y") %>% - filter(PARAMCD %in% c("HR", "QT", "RR")) - -testthat::test_that("EGT01 default variant is produced correctly", { - split_fun <- drop_split_levels - - afun <- function(x, .var, .spl_context, ...) { - n_fun <- sum(!is.na(x), na.rm = TRUE) - if (n_fun == 0) { - mean_sd_fun <- c(NA, NA) - median_fun <- NA - min_max_fun <- c(NA, NA) - } else { - mean_sd_fun <- c(mean(x, na.rm = TRUE), sd(x, na.rm = TRUE)) - median_fun <- median(x, na.rm = TRUE) - min_max_fun <- c(min(x), max(x)) - } - is_chg <- .var == "CHG" - is_baseline <- .spl_context$value[which(.spl_context$split == "AVISIT")] == "BASELINE" - if (is_baseline && is_chg) n_fun <- mean_sd_fun <- median_fun <- min_max_fun <- NULL - - in_rows( - "n" = n_fun, - "Mean (SD)" = mean_sd_fun, - "Median" = median_fun, - "Min - Max" = min_max_fun, - .formats = list("n" = "xx", "Mean (SD)" = "xx.xx (xx.xx)", "Median" = "xx.xx", "Min - Max" = "xx.xx - xx.xx"), - .format_na_strs = list("n" = "NE", "Mean (SD)" = "NE (NE)", "Median" = "NE", "Min - Max" = "NE - NE") - ) - } - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - split_rows_by("PARAM", split_fun = split_fun, label_pos = "topleft", split_label = obj_label(adeg_f$PARAM)) %>% - split_rows_by("AVISIT", split_fun = split_fun, label_pos = "topleft", split_label = obj_label(adeg_f$AVISIT)) %>% - split_cols_by_multivar( - vars = c("AVAL", "CHG"), - varlabels = c("Value at Visit", "Change from\nBaseline") - ) %>% - analyze_colvars(afun = afun) - - result <- build_table(lyt, adeg_f, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_egt02.R b/tests/testthat/test-table_egt02.R deleted file mode 100644 index 487385b4..00000000 --- a/tests/testthat/test-table_egt02.R +++ /dev/null @@ -1,56 +0,0 @@ -# Tests the variants for EGT02 - -adsl <- adsl_pharmaverse -adeg <- adeg_pharmaverse - -adsl <- df_explicit_na(adsl) -adeg <- df_explicit_na(adeg) - -adeg_f <- adeg %>% - filter(ONTRTFL == "Y") %>% - filter(PARAMCD %in% c("HR", "QT", "RR")) %>% - filter(ANRIND != "") %>% - var_relabel( - PARAM = "Assessment", - ANRIND = "Abnormality" - ) - -testthat::test_that("(EGT02) 1. Regardless of Abnormality at Baseline", { - split_fun <- drop_split_levels - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ACTARM") %>% - split_rows_by( - "PARAM", - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adeg_f$PARAM) - ) %>% - count_abnormal("ANRIND", abnormal = list(Low = "LOW", High = "HIGH"), exclude_base_abn = FALSE) %>% - append_varlabels(adeg_f, "ANRIND", indent = 1L) - - result <- build_table(lyt = lyt, df = adeg_f, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("(EGT02) 2. Among Subjects Without Abnormality at Baseline", { - split_fun <- drop_split_levels - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ACTARM") %>% - split_rows_by( - "PARAM", - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adeg_f$PARAM) - ) %>% - count_abnormal("ANRIND", abnormal = list(Low = "LOW", High = "HIGH"), exclude_base_abn = TRUE) %>% - append_varlabels(adeg_f, "ANRIND", indent = 1L) - - result <- build_table(lyt = lyt, df = adeg_f, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_egt03.R b/tests/testthat/test-table_egt03.R deleted file mode 100644 index b8da0d53..00000000 --- a/tests/testthat/test-table_egt03.R +++ /dev/null @@ -1,124 +0,0 @@ -# Tests variant 1 for EGT03 - -adeg <- adeg_pharmaverse - -set.seed(123, kind = "Mersenne-Twister") -adeg_labels <- var_labels(adeg) - -# Filtering -# --------- -adeg_f <- subset( - adeg, - PARAMCD == "HR" & # Heart Rate - SAFFL == "Y" & # "Safety Population Flag" - ONTRTFL == "Y" & # "On Treatment Record Flag" - AVISIT == "Week 2" & # "Analysis Visit" - DTYPE == "AVERAGE" -) - -# Preprocessing - -# For the EGT03 template, data imputation should be avoided, and missing data -# explicit and accounted for, so the contingency table sum adds up to the group N. -# For illustration purpose, missing data are added to the example. -adeg_f$BNRIND[sample(seq_len(nrow(adeg_f)), size = 100)] <- "LOW" -adeg_f$ANRIND[sample(seq_len(nrow(adeg_f)), size = 100)] <- "LOW" - -adeg_f$BNRIND <- factor( # nolint - adeg_f$BNRIND, - levels = c("LOW", "NORMAL", "HIGH", "Missing"), - labels = c("LOW", "NORMAL", "HIGH", "Missing") -) - -adeg_f$BNRIND[sample(seq_len(nrow(adeg_f)), size = 5)] <- "Missing" - -testthat::test_that("EGT03 variant 1 is produced correctly", { - set.seed(123, kind = "Mersenne-Twister") - - # Preprocessing - adeg_f$ANRIND <- factor( # nolint - adeg_f$ANRIND, - levels = c("LOW", "NORMAL", "HIGH", "Missing"), - labels = c("LOW", "NORMAL", "HIGH", "Missing") - ) - - adeg_f$ANRIND[sample(seq_len(nrow(adeg_f)), size = 5)] <- "Missing" - var_labels(adeg_f) <- adeg_labels - - lyt <- basic_table() %>% - split_cols_by("ANRIND") %>% - split_rows_by("ARM") %>% - add_rowcounts() %>% - analyze_vars("BNRIND", denom = "N_row") - - result <- build_table(lyt = lyt, df = adeg_f) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("EGT03 variant 2 is produced correctly", { - var_labels(adeg_f) <- adeg_labels - - lyt <- basic_table() %>% - split_cols_by("ANRIND") %>% - split_rows_by("ARM") %>% - add_rowcounts() %>% - analyze_vars("BNRIND", denom = "N_row") - - result <- build_table(lyt = lyt, df = adeg_f) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("EGT03 variant 3 is produced correctly", { - set.seed(123, kind = "Mersenne-Twister") - - # Preprocessing - adeg_f$ANRIND <- factor( # nolint - adeg_f$ANRIND, - levels = c("LOW", "NORMAL", "HIGH", "Missing"), - labels = c("LOW", "NORMAL", "HIGH", "Missing") - ) - - adeg_f$ANRIND[sample(seq_len(nrow(adeg_f)), size = 5)] <- "Missing" - - var_labels(adeg_f) <- adeg_labels - - lyt <- basic_table() %>% - split_cols_by("ANRIND") %>% - split_rows_by("ARM") %>% - add_rowcounts() %>% - analyze_vars("BNRIND", denom = "N_row") - - result <- build_table(lyt = lyt, df = adeg_f) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("EGT03 variant 4 is produced correctly", { - set.seed(123, kind = "Mersenne-Twister") - - # Preprocessing - adeg_f$ANRIND <- factor( # nolint - adeg_f$ANRIND, - levels = c("LOW", "NORMAL", "HIGH", "Missing"), - labels = c("LOW", "NORMAL", "HIGH", "Missing") - ) - - adeg_f$ANRIND[sample(seq_len(nrow(adeg_f)), size = 5)] <- "Missing" - var_labels(adeg_f) <- adeg_labels - - lyt <- basic_table() %>% - split_cols_by("ANRIND") %>% - split_rows_by("ARM") %>% - add_rowcounts() %>% - analyze_vars("BNRIND", denom = "N_row") - - result <- build_table(lyt = lyt, df = adeg_f) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_egt04.R b/tests/testthat/test-table_egt04.R deleted file mode 100644 index 936a3892..00000000 --- a/tests/testthat/test-table_egt04.R +++ /dev/null @@ -1,61 +0,0 @@ -# Tests the single variant for EGT04 -set.seed(99) - -adsl <- adsl_pharmaverse -adeg <- adeg_pharmaverse %>% - group_by(USUBJID, AVISIT, PARAMCD) %>% - slice_head(n = 1) %>% - ungroup() %>% - mutate( - AVALU = EGSTRESU, - WORS02FL = sample(c("Y", ""), nrow(.), replace = TRUE, prob = c(0.25, 0.75)), - BASEC = sample(c("NORMAL", "ABNORMAL", "Missing"), nrow(.), replace = TRUE, prob = c(0.5, 0.3, 0.2)) - ) - -testthat::test_that("EGT04 default variant is produced correctly", { - adeg_labels <- var_labels(adeg) - adeg_f <- subset( - adeg, - PARAMCD == "EGINTP" & # Analysis in terms of "NORMAL"/"ABNORMAL" (AVALC) - SAFFL == "Y" & # "Safety Population Flag" - ONTRTFL == "Y" & # "On Treatment Record Flag" - WORS02FL == "Y" # "Worst Post-Baseline Observation" - ) - - # Preprocessing - # For the EGT04 template, data imputation shoud be avoided, and missing data - # explicit and accounted for, so the contingency table sum adds up to the group N. - # For illustration purpose, missing data are added to the example. - set.seed(123, kind = "Mersenne-Twister") - - adeg_f$AVALC[sample(seq_len(nrow(adeg_f)), size = 5)] <- "Missing" - adeg_f$BASEC[sample(seq_len(nrow(adeg_f)), size = 5)] <- "Missing" - - adeg_f$AVALC <- factor( # nolint - adeg_f$AVALC, - levels = c("NORMAL", "ABNORMAL", "Missing"), - labels = c("Normal", "Abnormal", "Missing") - ) - adeg_f$BASEC <- factor( # nolint - adeg_f$BASEC, - levels = c("NORMAL", "ABNORMAL", "Missing"), - labels = c("Normal", "Abnormal", "Missing") - ) - var_labels(adeg_f) <- adeg_labels - - l <- basic_table() %>% - split_cols_by("AVALC") %>% - split_rows_by("ARM") %>% - add_rowcounts() %>% - analyze_vars( - "BASEC", - denom = "N_row", - .stats = "count_fraction", - na.rm = FALSE - ) - - result <- build_table(l, adeg_f) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_egt05_qtcat.R b/tests/testthat/test-table_egt05_qtcat.R deleted file mode 100644 index 55667a2c..00000000 --- a/tests/testthat/test-table_egt05_qtcat.R +++ /dev/null @@ -1,89 +0,0 @@ -# Test the single variant for EGT05_QTCAT - -adsl <- adsl_pharmaverse -adeg <- adeg_pharmaverse - -adsl <- df_explicit_na(adsl) -adeg <- df_explicit_na(adeg) - -adeg_labels <- var_labels(adeg) -adeg_f <- adeg %>% - filter( - PARAMCD == "QT", - ANL01FL == "Y", - DTYPE == "AVERAGE" - ) %>% - mutate( - AVALCAT1 = case_when( - AVAL <= 450 ~ "<=450 msec", - AVAL <= 480 ~ ">450 to <=480 msec", - AVAL <= 500 ~ ">480 to <= 500 msec", - AVAL > 500 ~ ">500 msec", - is.na(AVAL) ~ "" - ), - CHGCAT1 = case_when( - CHG <= 30 ~ "<=30 msec", - CHG <= 60 ~ ">30 to <=60 msec", - CHG > 60 ~ ">60 msec", - is.na(CHG) ~ "" - ) - ) %>% - mutate( - AVALCAT1 = factor( - AVALCAT1, - levels = c( - "<=450 msec", - ">450 to <=480 msec", - ">480 to <= 500 msec", - ">500 msec", - "" - ) - ), - CHGCAT1 = factor( - CHGCAT1, - levels = c( - "<=30 msec", - ">30 to <=60 msec", - ">60 msec", - "" - ) - ) - ) %>% - var_relabel( - AVALCAT1 = "Value at Visit", - CHGCAT1 = "Change from Baseline" - ) - -levels(adeg_f$AVISIT) <- c( - "Baseline", "Week 2", "Week 4", "Week 6", "Week 8", "Week 12", "Week 16", "Week 20", "Week 24", "Week 26", "" -) - -testthat::test_that("EGT05_QTCAT default variant is produced correctly", { - split_fun <- drop_split_levels - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARM") %>% - split_rows_by( - "PARAM", - split_label = obj_label(adeg_f$PARAM), - split_fun = split_fun, - label_pos = "topleft" - ) %>% - split_rows_by( - "AVISIT", - split_label = obj_label(adeg_f$AVISIT), - split_fun = split_fun, - label_pos = "topleft" - ) %>% - analyze_vars( - vars = c("AVALCAT1", "CHGCAT1"), - var_labels = c("Value at Visit", "Change from Baseline") - ) %>% - append_topleft(" Category") - - result <- build_table(lyt = lyt, df = adeg_f, alt_counts_df = adsl) %>% - prune_table() - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_ent.R b/tests/testthat/test-table_ent.R deleted file mode 100644 index e447858f..00000000 --- a/tests/testthat/test-table_ent.R +++ /dev/null @@ -1,80 +0,0 @@ -# Tests all ENT variants - -adsl <- adsl_raw -adsl$REGION1 <- droplevels(adsl$REGION1) # nolint -adsl$COUNTRY <- droplevels(adsl$COUNTRY) # nolint -adsl <- adsl[order(adsl$REGION1, adsl$COUNTRY, adsl$INVID), ] - -testthat::test_that("ENT01_IT is produced correctly", { - l <- basic_table() %>% - split_cols_by("ARM") %>% - add_colcounts() %>% - add_overall_col(label = "All Patients") %>% - split_rows_by("REGION1") %>% - summarize_row_groups() %>% - split_rows_by("COUNTRY") %>% - summarize_row_groups() %>% - split_rows_by("INVID") %>% - summarize_row_groups() - - tbl <- build_table(l, adsl) - result <- prune_table(tbl, all_zero_or_na, stop_depth = 4) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("ENT01a_IT is produced correctly", { - l <- basic_table() %>% - split_cols_by("ARM") %>% - add_colcounts() %>% - add_overall_col(label = "All Patients") %>% - split_rows_by("COUNTRY") %>% - summarize_row_groups() %>% - split_rows_by("INVID") %>% - summarize_row_groups() - - result <- build_table(l, adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("ENT02_IT is produced correctly", { - adsl$INVID_INVNAM <- paste(adsl$INVID, adsl$INVNAM, sep = " / ") # nolint - - l <- basic_table() %>% - split_cols_by("ARM") %>% - add_colcounts() %>% - add_overall_col(label = "All Patients") %>% - split_rows_by("REGION1") %>% - summarize_row_groups() %>% - split_rows_by("COUNTRY") %>% - summarize_row_groups() %>% - split_rows_by("INVID_INVNAM") %>% - summarize_row_groups() - - tbl <- build_table(l, adsl) - result <- prune_table(tbl, all_zero_or_na, stop_depth = 4) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("ENT02a_IT is produced correctly", { - adsl$INVID_INVNAM <- paste(adsl$INVID, adsl$INVNAM, sep = " / ") # nolint - - l <- basic_table() %>% - split_cols_by("ARM") %>% - add_colcounts() %>% - add_overall_col(label = "All Patients") %>% - split_rows_by("COUNTRY") %>% - summarize_row_groups() %>% - split_rows_by("INVID_INVNAM") %>% - summarize_row_groups() - - result <- build_table(l, adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_eudrat01.R b/tests/testthat/test-table_eudrat01.R deleted file mode 100644 index 9e0a1c19..00000000 --- a/tests/testthat/test-table_eudrat01.R +++ /dev/null @@ -1,78 +0,0 @@ -adsl <- adsl_raw -adae <- adae_raw - -# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels. -adsl <- df_explicit_na(adsl) -adae <- df_explicit_na(adae) - -adae_nonser <- adae %>% filter(AESER != "Y", SAFFL == "Y") - -get_adae_trimmed <- function(adsl, adae, cutoff_rate) { - n_per_arm <- adsl %>% - dplyr::count(ARM) - - anl_terms <- adae %>% - dplyr::group_by(ARM, AEBODSYS, AEDECOD) %>% - dplyr::count( - unique_terms = n_distinct(USUBJID) - ) %>% - dplyr::select(-n) %>% - dplyr::ungroup() - - anl_terms <- dplyr::left_join( - anl_terms, - n_per_arm, - by = "ARM", - multiple = "all" - ) %>% - dplyr::mutate( - ae_rate = unique_terms / n - ) %>% - dplyr::filter(ae_rate >= cutoff_rate) %>% - dplyr::select(AEDECOD) %>% - unique() - - anl <- dplyr::left_join( - anl_terms, - adae, - by = "AEDECOD", - multiple = "all" - ) - anl -} - -adae_trim <- get_adae_trimmed(adsl, adae_nonser, cutoff_rate = 0.05) - -testthat::test_that("EUDRAT01 is produced correctly", { - split_fun <- drop_split_levels - - lyt <- basic_table() %>% - split_cols_by("ARM") %>% - summarize_patients_events_in_cols( - custom_label = paste( - "Total number of patients with at least one non-serious adverse event", - "occuring at a relative frequency of >=5% and number of events" - ) - ) %>% - split_rows_by("AEBODSYS", - nested = FALSE, - split_fun = split_fun, - indent_mod = -1L, - label_pos = "topleft", - split_label = obj_label(adae_trim$AEBODSYS) - ) %>% - split_rows_by( - "AEDECOD", - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adae_trim$AEDECOD) - ) %>% - summarize_patients_events_in_cols( - col_split = FALSE - ) - - result <- build_table(lyt, adae_trim) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_eudrat02.R b/tests/testthat/test-table_eudrat02.R deleted file mode 100644 index fda7508c..00000000 --- a/tests/testthat/test-table_eudrat02.R +++ /dev/null @@ -1,45 +0,0 @@ -adae <- adae_raw - -# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels. -adae <- df_explicit_na(adae) - -adae_serious <- adae %>% filter(AESER == "Y", SAFFL == "Y") -adae_serious_arm <- adae_serious %>% filter(ARM == "A: Drug X") - -filters_list <- list( - related = with_label(c(AEREL = "Y"), "Events (Related)"), - fatal = with_label(c(AESDTH = "Y"), "Events (Fatal)"), - fatal_related = with_label(c(AEREL = "Y", AESDTH = "Y"), "Events (Fatal & Related)") -) - -testthat::test_that("EUDRAT02 is produced correctly", { - split_fun <- drop_split_levels - - lyt <- basic_table() %>% - summarize_patients_events_in_cols( - filters_list = filters_list, - empty_stats = c("all", "related", "fatal", "fatal_related"), - custom_label = "Total number of patients with at least one serious adverse event" - ) %>% - split_rows_by("AEBODSYS", - nested = FALSE, - split_fun = split_fun, - indent_mod = -1L, - label_pos = "topleft", - split_label = obj_label(adae_serious_arm$AEBODSYS) - ) %>% - split_rows_by("AEDECOD", - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(adae_serious_arm$AEDECOD) - ) %>% - summarize_patients_events_in_cols( - filters_list = filters_list, - col_split = FALSE - ) - - result <- build_table(lyt, adae_serious_arm) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_ext01.R b/tests/testthat/test-table_ext01.R deleted file mode 100644 index eec503fe..00000000 --- a/tests/testthat/test-table_ext01.R +++ /dev/null @@ -1,179 +0,0 @@ -# Tests all variants of EXT01 -set.seed(99) - -adsl <- adsl_pharmaverse -adex <- adex_pharmaverse - -adsl <- df_explicit_na(adsl) -adex <- df_explicit_na(adex) - -adex_tndose <- adex %>% - filter(PARAMCD == "TDURD") %>% - mutate( - PARAMCD = "TNDOSE", - PARAM = "Total number of doses administered", - PARCAT1 = "OVERALL" - ) - -adex <- adex %>% - rbind(adex_tndose) %>% - filter(PARCAT1 == "OVERALL") %>% - select(STUDYID, USUBJID, ACTARM, PARAMCD, PARAM, AVAL, PARCAT2) %>% - mutate( - PARAMCD = as.character(PARAMCD), - AVALC = case_when( - 0 <= AVAL & AVAL <= 30 ~ "0 - 30", - 31 <= AVAL & AVAL <= 60 ~ "31 - 60", - 61 <= AVAL & AVAL <= 90 ~ "61 - 90", - TRUE ~ ">= 91" - ) - ) %>% - droplevels() - -tdurd_adsl <- adsl %>% - select(STUDYID, USUBJID, ACTARM) %>% - mutate( - PARAMCD = "TDURD", - PARAM = "Overall duration (days)", - AVAL = sample(1:150, size = nrow(adsl), replace = TRUE), - AVALC = case_when( - 0 <= AVAL & AVAL <= 30 ~ "0 - 30", - 31 <= AVAL & AVAL <= 60 ~ "31 - 60", - 61 <= AVAL & AVAL <= 90 ~ "61 - 90", - TRUE ~ ">= 91" - ) - ) -tdurd <- adex %>% - filter(PARAMCD == "TNDOSE") %>% - select(STUDYID, USUBJID, PARCAT2) %>% - left_join(tdurd_adsl, by = c("STUDYID", "USUBJID")) - -tndosmis_adsl <- adsl %>% - select(STUDYID, USUBJID, ACTARM) %>% - mutate( - PARAMCD = "TNDOSMIS", - PARAM = "Total number of missed doses during study", - AVAL = sample(0:20, size = nrow(adsl), replace = TRUE), - AVALC = "" - ) -tndosmis <- adex %>% - filter(PARAMCD == "TNDOSE") %>% - select(STUDYID, USUBJID, PARCAT2) %>% - left_join(tndosmis_adsl, by = c("STUDYID", "USUBJID")) - -adex <- dplyr::bind_rows(adex, tdurd, tndosmis) %>% - mutate(PARAM = factor( - PARAM, - levels = c( - "Overall duration (days)", "Total dose administered", "Total number of doses administered", - "Total number of missed doses during study" - ) - )) - -testthat::test_that("EXT01 default variant with numeric parameters is produced correctly", { - split_fun <- drop_split_levels - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - split_rows_by("PARCAT2", split_label = "\nParameter Category (Drug A/Drug B)", label_pos = "topleft") %>% - split_rows_by("PARAM", split_fun = split_fun) %>% - analyze_vars(vars = "AVAL") - - result <- build_table(lyt = lyt, df = adex, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("EXT01 variant: with both numeric and categorical parameters", { - adex_avalc_wide <- adex %>% - filter(PARAMCD == "TDURD") %>% - select(STUDYID, USUBJID, PARAMCD, AVALC, PARCAT2) %>% - tidyr::pivot_wider( - id_cols = c(STUDYID, USUBJID, PARCAT2), - names_from = PARAMCD, - values_from = AVALC - ) %>% - mutate( - TDURDC = factor(TDURD, levels = c("0 - 30", "31 - 60", "61 - 90", ">= 91")) - ) %>% - select(-TDURD) - - anl <- adex %>% - select(STUDYID, USUBJID, ACTARM, PARAMCD, AVAL, PARCAT2) %>% - tidyr::pivot_wider( - id_cols = c(STUDYID, USUBJID, ACTARM, PARCAT2), - names_from = PARAMCD, - values_from = AVAL - ) %>% - left_join(adex_avalc_wide, by = c("STUDYID", "USUBJID", "PARCAT2")) %>% - var_relabel( - TDOSE = "Total dose administered", - TNDOSE = "Total number of doses administered", - TDURD = "Overall duration (days)", - TNDOSMIS = "Total number of missed doses during study", - TDURDC = "Overall duration (days)" - ) - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - split_rows_by("PARCAT2", split_label = "\nParameter Category (Drug A/Drug B)", label_pos = "topleft") %>% - analyze_vars( - vars = c("TDURD", "TDURDC", "TDOSE", "TNDOSE"), - var_labels = var_labels(anl)[c("TDURD", "TDURDC", "TDOSE", "TNDOSE")] - ) - - result <- build_table(lyt = lyt, df = anl, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("EXT01 variant: with user specified categories for missed doses", { - adex_avalc_wide <- adex %>% - filter(PARAMCD == "TDURD") %>% - select(STUDYID, USUBJID, PARAMCD, AVALC, PARCAT2) %>% - tidyr::pivot_wider( - id_cols = c(STUDYID, USUBJID, PARCAT2), - names_from = PARAMCD, - values_from = AVALC - ) %>% - mutate( - TDURDC = factor(TDURD, levels = c("0 - 30", "31 - 60", "61 - 90", ">= 91")) - ) %>% - select(-TDURD) - - anl <- adex %>% - select(STUDYID, USUBJID, ACTARM, PARAMCD, AVAL, PARCAT2) %>% - tidyr::pivot_wider( - id_cols = c(STUDYID, USUBJID, ACTARM, PARCAT2), - names_from = PARAMCD, - values_from = AVAL - ) %>% - left_join(adex_avalc_wide, by = c("STUDYID", "USUBJID", "PARCAT2")) %>% - var_relabel( - TDOSE = "Total dose administered", - TNDOSE = "Total number of doses administered", - TDURD = "Overall duration (days)", - TNDOSMIS = "Total number of missed doses during study", - TDURDC = "Overall duration (days)" - ) - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - split_rows_by("PARCAT2", split_label = "\nParameter Category (Drug A/Drug B)", label_pos = "topleft") %>% - analyze_vars( - vars = c("TDURD", "TDURDC", "TDOSE", "TNDOSE"), - var_labels = var_labels(anl)[c("TDURD", "TDURDC", "TDOSE", "TNDOSE")] - ) %>% - count_missed_doses( - "TNDOSMIS", - thresholds = c(1, 5, 10, 15), - var_labels = "Missed Doses" - ) - - result <- build_table(lyt = lyt, df = anl, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_jnj_tbl1.R b/tests/testthat/test-table_jnj_tbl1.R deleted file mode 100644 index 285954d7..00000000 --- a/tests/testthat/test-table_jnj_tbl1.R +++ /dev/null @@ -1,56 +0,0 @@ -# extra special case situation to scenario from test-table_dmt01.R -# Tests DMT01 with corner case situation to demonstrate bug in analyze is resolved with empty factor data -# tern@1431-bug-s_summaryfactor -set.seed(1) - -adsl <- pharmaverseadam::adsl -adsl <- adsl %>% - mutate(BMRKR1 = rnorm(nrow(adsl), 3.5, 10)) %>% - mutate(STRATA1 = factor(sample(c("A", "B", "C"), nrow(adsl), TRUE))) - -adsl <- df_explicit_na(adsl) - -adsl <- adsl %>% - mutate( - SEX = factor(case_when( - SEX == "M" ~ "Male", - SEX == "F" ~ "Female", - SEX == "U" ~ "Unknown", - SEX == "UNDIFFERENTIATED" ~ "Undifferentiated" - )), - AGEGR1 = factor( - case_when( - between(AGE, 18, 40) ~ "18-40", - between(AGE, 41, 64) ~ "41-64", - AGE > 64 ~ ">=65" - ), - levels = c("18-40", "41-64", ">=65") - ), - BMRKR1_CAT = NA_character_ - ) %>% - var_relabel( - BMRKR1_CAT = "Biomarker 1 Categories" - ) - -adsl <- df_explicit_na(adsl, na_level = "") - - -testthat::test_that("DMT01 variant factor with only Missing values", { - vars <- c("AGE", "AGEGR1", "BMRKR1_CAT") - var_labels <- c( - "Age (yr)", - "Age Group", - "Biomarker 1 Categories" - ) - - result <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ACTARM") %>% - analyze_vars( - vars = vars, - var_labels = var_labels - ) %>% - build_table(adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_lbt01.R b/tests/testthat/test-table_lbt01.R deleted file mode 100644 index 9eb1a81a..00000000 --- a/tests/testthat/test-table_lbt01.R +++ /dev/null @@ -1,56 +0,0 @@ -# Test the single variant for LBT01 - -adsl <- adsl_pharmaverse -adlb <- adlb_pharmaverse - -adsl <- df_explicit_na(adsl) -adlb <- df_explicit_na(adlb) %>% - filter(ANL01FL == "Y") - -adlb_f <- adlb %>% - dplyr::filter(PARAM == "Alanine Aminotransferase (U/L)") - -testthat::test_that("LBT01 default variant is produced correctly", { - # Define the split function - split_fun <- drop_split_levels - - afun <- function(x, .var, .spl_context, ...) { - n_fun <- sum(!is.na(x), na.rm = TRUE) - if (n_fun == 0) { - mean_sd_fun <- c(NA, NA) - median_fun <- NA - min_max_fun <- c(NA, NA) - } else { - mean_sd_fun <- c(mean(x, na.rm = TRUE), sd(x, na.rm = TRUE)) - median_fun <- median(x, na.rm = TRUE) - min_max_fun <- c(min(x), max(x)) - } - is_chg <- .var == "CHG" - is_baseline <- .spl_context$value[which(.spl_context$split == "AVISIT")] == "BASELINE" - if (is_baseline && is_chg) n_fun <- mean_sd_fun <- median_fun <- min_max_fun <- NULL - - in_rows( - "n" = n_fun, - "Mean (SD)" = mean_sd_fun, - "Median" = median_fun, - "Min - Max" = min_max_fun, - .formats = list("n" = "xx", "Mean (SD)" = "xx.xx (xx.xx)", "Median" = "xx.xx", "Min - Max" = "xx.xx - xx.xx"), - .format_na_strs = list("n" = "NE", "Mean (SD)" = "NE (NE)", "Median" = "NE", "Min - Max" = "NE - NE") - ) - } - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - split_rows_by("PARAM", split_fun = split_fun, label_pos = "topleft", split_label = obj_label(adlb_f$PARAM)) %>% - split_rows_by("AVISIT", split_fun = split_fun, label_pos = "topleft", split_label = obj_label(adlb_f$AVISIT)) %>% - split_cols_by_multivar( - vars = c("AVAL", "CHG"), - varlabels = c("Value at Visit", "Change from\nBaseline") - ) %>% - analyze_colvars(afun = afun) - - result <- build_table(lyt, adlb_f) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_lbt02.R b/tests/testthat/test-table_lbt02.R deleted file mode 100644 index ac6156df..00000000 --- a/tests/testthat/test-table_lbt02.R +++ /dev/null @@ -1,19 +0,0 @@ -# Tests the single variant for LBT02 - -adsl <- adsl_pharmaverse -adlb <- adlb_pharmaverse - -testthat::test_that("LBT02 default variant is produced correctly", { - adlb <- subset(adlb, AVISIT != "SCREENING" & PARAMCD == "ALT") - - l <- basic_table() %>% - split_cols_by(var = "ARM") %>% - split_rows_by(var = "AVISIT") %>% - add_colcounts() %>% - analyze_vars(vars = "AVAL") - - result <- build_table(l, df = adlb, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_lbt03.R b/tests/testthat/test-table_lbt03.R deleted file mode 100644 index a06e07e5..00000000 --- a/tests/testthat/test-table_lbt03.R +++ /dev/null @@ -1,30 +0,0 @@ -# Tests the single variant for LBT03 - -adsl <- adsl_pharmaverse -adlb <- adlb_pharmaverse - -testthat::test_that("LBT03 default variant is produced correctly", { - adlb_f <- adlb %>% - dplyr::filter(AVISIT %in% c("Baseline", "Week 2", "Week 4") & PARAMCD == "ALT") %>% - dplyr::mutate( - ABLFL = ifelse(AVISIT == "Baseline", "Y", ""), # original adlb_pharmaverse ABLFL is unreliable - ABLFLL = ABLFL == "Y" - ) - - result <- basic_table() %>% - split_cols_by("ARM") %>% - add_colcounts() %>% - split_rows_by("AVISIT") %>% - summarize_change( - "CHG", - variables = list(value = "AVAL", baseline_flag = "ABLFLL"), - na.rm = TRUE - ) %>% - build_table( - df = adlb_f, - alt_counts_df = adsl - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_lbt04.R b/tests/testthat/test-table_lbt04.R deleted file mode 100644 index 19e2a13d..00000000 --- a/tests/testthat/test-table_lbt04.R +++ /dev/null @@ -1,35 +0,0 @@ -# Tests all variants of LBT04 - -adsl <- adsl_pharmaverse -adlb <- adlb_pharmaverse - -adsl <- df_explicit_na(adsl) -adlb <- df_explicit_na(adlb) - -adlb_f <- adlb %>% - filter(ONTRTFL == "Y", ANRIND != "") %>% - var_relabel( - PARAM = "Laboratory Test", - ANRIND = "Direction of Abnormality" - ) - -testthat::test_that("LBT04 default variant is produced correctly", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - split_rows_by("PARAM", - split_fun = drop_split_levels, - label_pos = "topleft", - split_label = obj_label(adlb_f$PARAM) - ) %>% - count_abnormal( - var = "ANRIND", - abnormal = list(Low = c("LOW", "LOW LOW"), High = c("HIGH", "HIGH HIGH")), - exclude_base_abn = TRUE - ) %>% - append_varlabels(adlb_f, "ANRIND", indent = 1L) - - result <- build_table(lyt = lyt, df = adlb_f, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_lbt05.R b/tests/testthat/test-table_lbt05.R deleted file mode 100644 index 20ff2432..00000000 --- a/tests/testthat/test-table_lbt05.R +++ /dev/null @@ -1,132 +0,0 @@ -adsl <- adsl_pharmaverse -adlb <- adlb_pharmaverse %>% - filter(!PARAMCD %in% c("BILI", "COLOR", "GLUC")) - -adsl <- df_explicit_na(adsl) -adlb <- df_explicit_na(adlb) - -qntls <- adlb %>% - group_by(PARAMCD) %>% - summarise(as_tibble(t(quantile(AVAL, probs = c(0.1, 0.9)))), .groups = "drop_last") %>% - rename(q1 = 2, q2 = 3) - -adlb <- adlb %>% - left_join(qntls, by = "PARAMCD") - -set.seed(1) - -# Modify ANRIND and create AVALCAT1/PARCAT2 -# PARCAT2 is just used for filtering, but in order to be the -# filtering as realistic as possible, will create the variable. -adlb <- adlb %>% - mutate( - ANRIND = factor( - case_when( - ANRIND == "LOW" & AVAL <= q1 ~ "LOW LOW", - ANRIND == "HIGH" & AVAL >= q2 ~ "HIGH HIGH", - TRUE ~ as.character(ANRIND) - ), - levels = c("", "HIGH", "HIGH HIGH", "LOW", "LOW LOW", "NORMAL") - ), - AVALCAT1 = factor( - case_when( - ANRIND %in% c("HIGH HIGH", "LOW LOW") ~ - sample(x = c("LAST", "REPLICATED", "SINGLE"), size = n(), replace = TRUE, prob = c(0.3, 0.6, 0.1)), - TRUE ~ "" - ), - levels = c("", c("LAST", "REPLICATED", "SINGLE")) - ), - PARCAT2 = factor(ifelse(ANRIND %in% c("HIGH HIGH", "LOW LOW"), "LS", - sample(c("SI", "CV", "LS"), size = n(), replace = TRUE) - )) - ) %>% - select(-q1, -q2) - -# Pre-processing steps -adlb_f <- adlb %>% - filter(ONTRTFL == "Y" & PARCAT2 == "LS" & SAFFL == "Y" & !is.na(AVAL)) %>% - mutate(abn_dir = factor(case_when( - ANRIND == "LOW LOW" ~ "Low", - ANRIND == "HIGH HIGH" ~ "High", - TRUE ~ "" - ), levels = c("Low", "High", ""))) %>% - df_explicit_na() - -# Construct analysis map -map <- expand.grid( - PARAM = levels(adlb$PARAM), - abn_dir = c("Low", "High"), - stringsAsFactors = FALSE -) %>% - arrange(PARAM, desc(abn_dir)) - -testthat::test_that("LBT05 variant 1 is produced correctly", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - split_rows_by( - "PARAM", - label_pos = "topleft", - split_label = "Laboratory Test" - ) %>% - summarize_num_patients(var = "USUBJID", .stats = "unique_count") %>% - split_rows_by("abn_dir", split_fun = trim_levels_to_map(map)) %>% - count_abnormal_by_marked( - var = "AVALCAT1", - variables = list(id = "USUBJID", param = "PARAM", direction = "abn_dir") - ) %>% - append_topleft(" Direction of Abnormality") - - result <- build_table(lyt, df = adlb_f, alt_counts_df = adsl) - - has_lbl <- function(lbl) CombinationFunction(function(tr) obj_label(tr) == lbl || sum(unlist(row_values(tr))) != 0) - result <- prune_table(result, keep_rows(has_lbl("Any Abnormality"))) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("LBT05 variant 2 is produced correctly", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - split_rows_by( - "PARAM", - label_pos = "topleft", - split_label = "Laboratory Test" - ) %>% - summarize_num_patients(var = "USUBJID", .stats = "unique_count") %>% - split_rows_by("abn_dir", split_fun = trim_levels_to_map(map)) %>% - count_abnormal_by_marked( - var = "AVALCAT1", - variables = list(id = "USUBJID", param = "PARAM", direction = "abn_dir") - ) %>% - append_topleft(" Direction of Abnormality") - - result <- build_table(lyt, df = adlb_f, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("LBT05 variant 4 is produced correctly", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - split_rows_by( - "PARAM", - label_pos = "topleft", - split_label = "Laboratory Test", - split_fun = trim_levels_in_group("abn_dir", drop_outlevs = TRUE) - ) %>% - summarize_num_patients(var = "USUBJID", .stats = "unique_count") %>% - split_rows_by("abn_dir") %>% - count_abnormal_by_marked( - var = "AVALCAT1", - variables = list(id = "USUBJID", param = "PARAM", direction = "abn_dir") - ) %>% - append_topleft(" Direction of Abnormality") - - result <- build_table(lyt, df = adlb_f, alt_counts_df = adsl) - result <- result %>% prune_table() - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_lbt06.R b/tests/testthat/test-table_lbt06.R deleted file mode 100644 index d2af1f4d..00000000 --- a/tests/testthat/test-table_lbt06.R +++ /dev/null @@ -1,33 +0,0 @@ -# Tests all variants of LBT06 - -adsl <- adsl_pharmaverse -adlb <- adlb_pharmaverse - -# modify necessary columns into factor to avoid warnings -testthat::test_that("LBT06 default variant is produced correctly", { - adlb <- adlb %>% - dplyr::filter(PARAMCD == "ALT") %>% - dplyr::filter(AVISIT %in% c("Week 2", "Week 4", "Week 6", "Week 8")) %>% - mutate( - AVISIT = factor(AVISIT), - ARM = factor(ARM), - PARAMCD = factor(PARAMCD), - PARAM = factor(PARAM), - ANRIND = factor(ANRIND), - BNRIND = factor(BNRIND) - ) - - result <- basic_table() %>% - split_cols_by("ARM") %>% - add_colcounts() %>% - split_rows_by("PARAM", split_fun = drop_split_levels) %>% - split_rows_by("AVISIT", split_fun = drop_split_levels) %>% - count_abnormal_by_baseline( - "ANRIND", - abnormal = c(Low = "LOW", High = "HIGH") - ) %>% - build_table(adlb, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_lbt07.R b/tests/testthat/test-table_lbt07.R deleted file mode 100644 index bdd4a317..00000000 --- a/tests/testthat/test-table_lbt07.R +++ /dev/null @@ -1,88 +0,0 @@ -# Tests LBT07 - -adsl <- adsl_pharmaverse -adlb <- adlb_pharmaverse %>% - mutate( - WGRLOFL = ifelse(AVISIT == "POST-BASELINE MINIMUM", "Y", ""), - WGRHIFL = ifelse(AVISIT == "POST-BASELINE MAXIMUM", "Y", "") - ) %>% - filter(ATOXGR != "") - -adlb_labels <- var_labels(adlb) - -# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels. -adsl <- df_explicit_na(adsl) -adlb <- df_explicit_na(adlb) - -# Select worst post-baseline records. -adlb_f <- adlb %>% - filter(ONTRTFL == "Y") %>% - filter(WGRLOFL == "Y" | WGRHIFL == "Y") - -var_labels(adlb_f) <- adlb_labels - -# Derive GRADE_DIR and GRADE_ANL to use in layout from ATOXGR -adlb_f <- adlb_f %>% - mutate( - GRADE_DIR = factor( - case_when( - ATOXGR %in% c("-1", "-2", "-3", "-4") & .data$WGRLOFL == "Y" ~ "LOW", - ATOXGR == "0" ~ "ZERO", - ATOXGR %in% c("1", "2", "3", "4") & .data$WGRHIFL == "Y" ~ "HIGH", - TRUE ~ "NONE" - ), - levels = c("LOW", "ZERO", "HIGH", "NONE") - ), - GRADE_ANL = forcats::fct_relevel( - forcats::fct_recode(ATOXGR, - `1` = "-1", `2` = "-2", `3` = "-3" - ), - c("0", "1", "2", "3") - ) - ) %>% - var_relabel( - GRADE_DIR = "Direction of Abnormality", - GRADE_ANL = "Analysis Grade" - ) - -# Construct analysis map -map <- expand.grid( - PARAM = levels(adlb$PARAM), - GRADE_DIR = c("LOW", "HIGH"), - GRADE_ANL = as.character(1:3), - stringsAsFactors = FALSE -) %>% - arrange(PARAM, desc(GRADE_DIR), GRADE_ANL) - -testthat::test_that("LBT07 is produced correctly", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - split_rows_by( - "PARAM", - label_pos = "topleft", - split_label = obj_label(adlb_f$PARAM) - ) %>% - summarize_num_patients( - var = "USUBJID", - required = "ATOXGR", - .stats = "unique_count" - ) %>% - split_rows_by( - "GRADE_DIR", - label_pos = "topleft", - split_label = obj_label(adlb_f$GRADE_DIR), - split_fun = trim_levels_to_map(map) - ) %>% - count_abnormal_by_worst_grade( - var = "GRADE_ANL", - variables = list(id = "USUBJID", param = "PARAM", grade_dir = "GRADE_DIR"), - .indent_mods = 4L - ) %>% - append_topleft(" Highest NCI CTCAE Grade") - - result <- build_table(lyt = lyt, df = adlb_f, alt_counts_df = adsl) - result <- result %>% prune_table() - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_lbt08.R b/tests/testthat/test-table_lbt08.R deleted file mode 100644 index 3c77f2f0..00000000 --- a/tests/testthat/test-table_lbt08.R +++ /dev/null @@ -1,44 +0,0 @@ -adsl <- adsl_pharmaverse -adlb <- adlb_pharmaverse %>% - mutate( - WGRLOFL = ifelse(AVISIT == "POST-BASELINE MINIMUM", "Y", ""), - WGRHIFL = ifelse(AVISIT == "POST-BASELINE MAXIMUM", "Y", "") - ) %>% - filter(ATOXGR != "") - -adlb <- adlb %>% - dplyr::mutate( - GRADDR = dplyr::case_when( - PARAMCD == "GLUC" ~ "L", - PARAMCD == "BILI" ~ "B", - PARAMCD == "ALKPH" ~ "H" - ) - ) %>% - dplyr::filter(SAFFL == "Y" & ONTRTFL == "Y" & GRADDR != "") - -testthat::test_that("LBT08 produce correctly", { - df <- h_adlb_worsen( - adlb, - worst_flag_low = c("WGRLOFL" = "Y"), - worst_flag_high = c("WGRHIFL" = "Y"), - direction_var = "GRADDR" - ) - - result <- basic_table() %>% - split_cols_by("ARMCD") %>% - add_colcounts() %>% - split_rows_by("PARAMCD", label_pos = "topleft") %>% - split_rows_by("GRADDR", label_pos = "topleft") %>% - count_abnormal_lab_worsen_by_baseline( - var = "ATOXGR", - variables = list( - id = "USUBJID", - baseline_var = "BTOXGR", - direction_var = "GRADDR" - ) - ) %>% - build_table(df = df, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_lbt09.R b/tests/testthat/test-table_lbt09.R deleted file mode 100644 index 02f290f2..00000000 --- a/tests/testthat/test-table_lbt09.R +++ /dev/null @@ -1,132 +0,0 @@ -adhy_liver <- full_join( - (pharmaverseadam::adlb %>% - filter(PARAMCD %in% c("BILI") & (AVISIT == "Baseline" | DTYPE == "MAXIMUM")) %>% - select(USUBJID, ARM, AVISIT, PARAMCD, AVAL, ANRHI) %>% - rename( - BILI = PARAMCD, - BILIVAL = AVAL, - BILIRHI = ANRHI - )), - (pharmaverseadam::adlb %>% - filter(PARAMCD %in% c("ALT", "AST") & (AVISIT == "Baseline" | DTYPE == "MAXIMUM")) %>% - select(USUBJID, ARM, AVISIT, PARAMCD, AVAL, ANRHI) %>% - rename( - ALTAST = PARAMCD, - ALTASTVAL = AVAL, - ALTASTRHI = ANRHI - )), - by = join_by(USUBJID, ARM, AVISIT) -) %>% - mutate( - TBILI_CAT = factor( - case_when( - BILIVAL <= 2 * BILIRHI ~ "Total Bilirubin <= 2xULN", - BILIVAL > 2 * BILIRHI ~ "Total Bilirubin > 2xULN" - ), - levels = c( - "Total Bilirubin <= 2xULN", - "Total Bilirubin > 2xULN" - ) - ), - ALTAST_CAT = factor( - case_when( - ALTAST %in% c("ALT") & (ALTASTVAL > 3 * ALTASTRHI) ~ "ALT >3 - <= 5xULN", - ALTAST %in% c("ALT") & (ALTASTVAL > 5 * ALTASTRHI) ~ "ALT >5 - <= 10xULN", - ALTAST %in% c("ALT") & (ALTASTVAL > 10 * ALTASTRHI) ~ "ALT >10 - <= 20xULN", - ALTAST %in% c("ALT") & (ALTASTVAL > 20 * ALTASTRHI) ~ "ALT >20xULN", - ALTAST %in% c("AST") & (ALTASTVAL > 3 * ALTASTRHI) ~ "AST >3 - <= 5xULN", - ALTAST %in% c("AST") & (ALTASTVAL > 5 * ALTASTRHI) ~ "ALT >5 - <= 10xULN", - ALTAST %in% c("AST") & (ALTASTVAL > 10 * ALTASTRHI) ~ "AST >10 - <= 20xULN", - ALTAST %in% c("AST") & (ALTASTVAL > 20 * ALTASTRHI) ~ "AST >20xULN", - TRUE ~ "Criteria not met" - ), - levels = c( - "ALT >3 - <= 5xULN", "ALT >5 - <= 10xULN", "ALT >10 - <= 20xULN", "ALT > 20xULN", - "AST >3 - <= 5xULN", "AST >5 - <= 10xULN", "AST >10 - <= 20xULN", "AST > 20xULN", - "Criteria not met" - ) - ), - ALTAST_ind = factor( - case_when( - ALTAST == "ALT" ~ "ALT", - ALTAST == "AST" ~ "AST" - ), - levels = c("ALT", "AST") - ) - ) - -map <- data.frame( - ALTAST_ind = c(rep("ALT", 5), rep("AST", 5)), - ALTAST_CAT = c( - "ALT >3 - <= 5xULN", - "ALT >5 - <= 10xULN", - "ALT >10 - <= 20xULN", - "20" = "ALT > 20xULN", - "Criteria not met", - "AST >3 - <= 5xULN", - "AST >5 - <= 10xULN", - "AST >10 - <= 20xULN", - "AST > 20xULN", - "Criteria not met" - ), - stringsAsFactors = FALSE -) - -testthat::test_that("LBT09 variant 1 works as expected", { - result <- basic_table() %>% - split_cols_by("ARM") %>% - split_cols_by("AVISIT") %>% - split_rows_by("TBILI_CAT") %>% - # below split helps us get the right denominator between ALT/AST but it can be hidden - split_rows_by("ALTAST_ind", split_fun = trim_levels_to_map(map), child_labels = "hidden") %>% - count_occurrences( - vars = "ALTAST_CAT", - .stats = "fraction", - denom = "n", - drop = FALSE - ) %>% - append_topleft("Liver Laboratory Test Criterion") %>% - build_table(df = adhy_liver) - - # trim away rows with criteria not met - criteria_fun <- function(tr) { - row_label <- obj_label(tr) - ifelse(row_label == "Criteria not met", TRUE, FALSE) - } - - result <- result %>% trim_rows(criteria = criteria_fun) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("LBT09 variant 2 works as expected", { - result <- basic_table() %>% - split_cols_by("ARM") %>% - split_cols_by("AVISIT") %>% - split_rows_by( - "TBILI_CAT", - split_fun = remove_split_levels("Total Bilirubin > 2xULN and Alkaline Phosphatase <= 2xULN") - ) %>% - # below split helps us get the right denominator between ALT/AST but it can be hidden - split_rows_by("ALTAST_ind", split_fun = trim_levels_to_map(map), child_labels = "hidden") %>% - count_occurrences( - vars = "ALTAST_CAT", - .stats = "fraction", - denom = "n", - drop = FALSE - ) %>% - append_topleft("Liver Laboratory Test Criterion") %>% - build_table(df = adhy_liver) - - # trim away rows with criteria not met - criteria_fun <- function(tr) { - row_label <- obj_label(tr) - ifelse(row_label == "Criteria not met", TRUE, FALSE) - } - - result <- result %>% trim_rows(criteria = criteria_fun) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_lbt10.R b/tests/testthat/test-table_lbt10.R deleted file mode 100644 index 1e0b7064..00000000 --- a/tests/testthat/test-table_lbt10.R +++ /dev/null @@ -1,111 +0,0 @@ -adsl <- adsl_pharmaverse -adhy <- full_join( - (pharmaverseadam::adlb %>% - filter(PARAMCD %in% c("BILI") & !(DTYPE %in% c("MINIMUM", "MAXIMUM"))) %>% - select(USUBJID, ACTARMCD, AVISIT, PARAMCD, AVAL, ANRHI) %>% - rename( - BILI = PARAMCD, - BILIVAL = AVAL, - BILIRHI = ANRHI - )), - (pharmaverseadam::adlb %>% - filter(PARAMCD %in% c("ALT", "AST") & !(DTYPE %in% c("MINIMUM", "MAXIMUM"))) %>% - select(USUBJID, ACTARMCD, AVISIT, PARAMCD, AVAL, ANRHI) %>% - rename( - ALTAST = PARAMCD, - ALTASTVAL = AVAL, - ALTASTRHI = ANRHI - )), - by = join_by(USUBJID, ACTARMCD, AVISIT) -) %>% - unique() %>% - mutate( - TBILI_CAT = factor( - case_when( - BILIVAL <= 1 * BILIRHI ~ "Total Bilirubin <= 2xULN", - BILIVAL > 1 * BILIRHI ~ "Total Bilirubin > 2xULN", - TRUE ~ "Criteria not met" - ), - levels = c( - "Total Bilirubin <= 2xULN", - "Total Bilirubin > 2xULN", - "Criteria not met" - ) - ), - ALTAST_CAT = factor( - case_when( - ALTAST %in% c("ALT") & (ALTASTVAL > 3 * ALTASTRHI) ~ "ALT >3 - <= 5xULN", - ALTAST %in% c("ALT") & (ALTASTVAL > 5 * ALTASTRHI) ~ "ALT >5 - <= 10xULN", - ALTAST %in% c("ALT") & (ALTASTVAL > 10 * ALTASTRHI) ~ "ALT >10 - <= 20xULN", - ALTAST %in% c("ALT") & (ALTASTVAL > 20 * ALTASTRHI) ~ "ALT >20xULN", - ALTAST %in% c("AST") & (ALTASTVAL > 3 * ALTASTRHI) ~ "AST >3 - <= 5xULN", - ALTAST %in% c("AST") & (ALTASTVAL > 5 * ALTASTRHI) ~ "ALT >5 - <= 10xULN", - ALTAST %in% c("AST") & (ALTASTVAL > 10 * ALTASTRHI) ~ "AST >10 - <= 20xULN", - ALTAST %in% c("AST") & (ALTASTVAL > 20 * ALTASTRHI) ~ "AST >20xULN", - TRUE ~ "Criteria not met" - ), - levels = c( - "ALT >3 - <= 5xULN", "ALT >5 - <= 10xULN", "ALT >10 - <= 20xULN", "ALT > 20xULN", - "AST >3 - <= 5xULN", "AST >5 - <= 10xULN", "AST >10 - <= 20xULN", "AST > 20xULN", - "Criteria not met" - ) - ) - ) - -anl <- adhy %>% - group_by(USUBJID, ACTARMCD, TBILI_CAT, .drop = FALSE) %>% - count(ALTAST_CAT) %>% - ungroup() %>% - mutate(AVALC_FORMAT = ifelse(n > 0, as.character(ALTAST_CAT), "Criteria not met")) %>% - df_explicit_na() - -# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels. -adsl <- df_explicit_na(adsl) - -testthat::test_that("LBT10 variant 1 works as expected", { - tbl <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARMCD") %>% - split_rows_by("TBILI_CAT") %>% - split_rows_by("ALTAST_CAT", split_fun = drop_split_levels, child_labels = "hidden") %>% - count_occurrences( - vars = "AVALC_FORMAT", - .stats = c("fraction"), - denom = "n", - drop = TRUE - ) %>% - build_table(anl, alt_counts_df = adsl) - - criteria_fun <- function(tr) { - row_label <- obj_label(tr) - ifelse(row_label == "Criteria not met", TRUE, FALSE) - } - - result <- tbl %>% trim_rows(criteria = criteria_fun) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("LBT10 variant 2 works as expected", { - tbl2 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARMCD") %>% - split_rows_by("TBILI_CAT", split_fun = remove_split_levels("Total Bilirubin > 2xULN")) %>% - split_rows_by("ALTAST_CAT", split_fun = drop_split_levels, child_labels = "hidden") %>% - count_occurrences( - vars = "AVALC_FORMAT", - .stats = c("fraction"), - denom = "n", - drop = TRUE - ) %>% - build_table(anl, alt_counts_df = adsl) - - criteria_fun <- function(tr) { - row_label <- obj_label(tr) - ifelse(row_label == "Criteria not met", TRUE, FALSE) - } - - result <- tbl2 %>% trim_rows(criteria = criteria_fun) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_lbt10_bl.R b/tests/testthat/test-table_lbt10_bl.R deleted file mode 100644 index f699cfad..00000000 --- a/tests/testthat/test-table_lbt10_bl.R +++ /dev/null @@ -1,70 +0,0 @@ -adsl <- adsl_raw -adhy <- adhy_raw - -adhy_liver <- adhy %>% - filter(PARAMCD %in% c( - "BL2AL2CB", "BL2AS2CB", "BG2AL2CB", "BG2AS2CB", "B2A2L2CB", "B2A2S2CB", "B2A5L2CB", "B2A5S2CB" - )) %>% - mutate(PARAMCAT = case_when( - PARAMCD %in% c("BL2AL2CB", "BL2AS2CB") ~ "Total Bilirubin <= 2xULN", - PARAMCD %in% c("BG2AL2CB", "BG2AS2CB") ~ "Total Bilirubin > 2xULN", - PARAMCD %in% c("B2A2L2CB", "B2A2S2CB") ~ "Total Bilirubin > 2xULN and Alkaline Phosphatase <= 2xULN", - PARAMCD %in% c("B2A5L2CB", "B2A5S2CB") ~ "Total Bilirubin > 2xULN and Alkaline Phosphatase <= 5xULN" - )) %>% - mutate(AVALC_FORMAT = case_when( - PARAMCD %in% c("BL2AL2CB", "BG2AL2CB", "B2A2L2CB", "B2A5L2CB") & AVALC == "Y" ~ "ALT >3xULN at 2 Visits", - PARAMCD %in% c("BL2AS2CB", "BG2AS2CB", "B2A2S2CB", "B2A5S2CB") & AVALC == "Y" ~ "AST >3xULN at 2 Visits", - TRUE ~ "Criteria not met" - )) - -# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels. -adsl <- df_explicit_na(adsl) -anl <- df_explicit_na(adhy_liver) - -testthat::test_that("LBT10_BL variant 1 works as expected", { - tbl <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARMCD") %>% - split_rows_by("PARAMCAT") %>% - split_rows_by("PARAM", split_fun = drop_split_levels, child_labels = "hidden") %>% - count_occurrences( - vars = "AVALC_FORMAT", - .stats = c("fraction"), - denom = "n", - drop = TRUE - ) %>% - build_table(anl, alt_counts_df = adsl) - - criteria_fun <- function(tr) { - row_label <- obj_label(tr) - ifelse(row_label == "Criteria not met", TRUE, FALSE) - } - - result <- tbl %>% trim_rows(criteria = criteria_fun) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("LBT10_BL variant 2 works as expected", { - tbl2 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARMCD") %>% - split_rows_by("PARAMCAT", split_fun = remove_split_levels("Total Bilirubin > 2xULN")) %>% - split_rows_by("PARAM", split_fun = drop_split_levels, child_labels = "hidden") %>% - count_occurrences( - vars = "AVALC_FORMAT", - .stats = c("fraction"), - denom = "n", - drop = TRUE - ) %>% - build_table(anl, alt_counts_df = adsl) - - criteria_fun <- function(tr) { - row_label <- obj_label(tr) - ifelse(row_label == "Criteria not met", TRUE, FALSE) - } - - result <- tbl2 %>% trim_rows(criteria = criteria_fun) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_lbt11.R b/tests/testthat/test-table_lbt11.R deleted file mode 100644 index e1dd2023..00000000 --- a/tests/testthat/test-table_lbt11.R +++ /dev/null @@ -1,136 +0,0 @@ -# Test variants for AET05. -adsl <- adsl_pharmaverse %>% - filter(SAFFL == "Y") -anl <- adlb_pharmaverse %>% - filter(PARAMCD %in% c("AST", "ALT", "BILI") & is.na(DTYPE)) %>% - mutate( - CRIT1 = case_when( - PARAMCD == "AST" ~ "AST >=3xULN", - PARAMCD == "ALT" ~ "ALT >=3xULN", - PARAMCD == "BILI" ~ "BILI >=2xULN" - ), - CRIT1FL = case_when( - (AVAL / ANRHI >= 3) & PARAMCD %in% c("AST", "ALT") ~ "Y", - (AVAL / ANRHI >= 2 & PARAMCD == "BILI") ~ "Y" - ) - ) %>% - select(STUDYID, USUBJID, ARMCD, ADT, CRIT1, CRIT1FL) %>% - pivot_wider(names_from = CRIT1, values_from = CRIT1FL) %>% - mutate( - HYLAW = ifelse((`AST >=3xULN` == "Y" | `ALT >=3xULN` == "Y") & `BILI >=2xULN` == "Y", "Y", NA_character_) - ) %>% - select(USUBJID, HYLAW, ADT) %>% - group_by(USUBJID, HYLAW) %>% - mutate( - LASTKNOWN = max(ADT), - HYDT = min(ADT) - ) %>% - ungroup() %>% - mutate(ADT2 = as.Date(ifelse(is.na(HYLAW), LASTKNOWN, HYDT))) %>% - select(USUBJID, HYLAW, ADT2) %>% - unique() %>% - left_join( - select(adsl, USUBJID, ARMCD, TRTSDT, SEX, RACE), - ., - by = "USUBJID" - ) %>% - mutate( - PARAM = "Time to Hy's Law Elevation in relation to ULN", - AVAL = as.numeric(difftime(ADT2, TRTSDT, units = "days")), - AVAL = ifelse(is.na(AVAL) & !is.na(ARMCD), 1, AVAL), - AVALU = ifelse(!is.na(AVAL), "DAYS", NA_character_), - AVALU = as.factor(AVALU), - CNSR = ifelse(is.na(HYLAW), 1, 0) # original pharmaverseadam data - ) - -anl$CNSR[1:80] <- 0 - -anl <- anl %>% - mutate( - is_event = CNSR == 0, - event_grp = factor( - dplyr::case_when( - CNSR == 0 ~ "Patients with LLT event (%)", - CNSR == 1 ~ "Patients without LLT event (%)" - ), - levels = c( - "Patients with LLT event (%)", - "Patients without LLT event (%)" - ) - ) - ) %>% - filter(AVAL > 0) - -testthat::test_that("LBT11 variant 1 works as expected", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARMCD", ref_group = "Pbo", split_fun = ref_group_position("first")) %>% - count_occurrences(vars = "event_grp") %>% - surv_time( - vars = "AVAL", - var_labels = paste0("Time to 1st LLT Event (", levels(anl$AVALU), ")"), - is_event = "is_event", - table_names = "time_to_event" - ) %>% - coxph_pairwise( - vars = "AVAL", - is_event = "is_event", - var_labels = "Unstratified Analysis", - control = control_coxph(pval_method = "log-rank"), - table_names = "coxph_unstratified" - ) - - result <- build_table(lyt, df = anl, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("LBT11 variant 2 works as expected", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARMCD", ref_group = "Pbo", split_fun = ref_group_position("first")) %>% - count_occurrences(vars = "event_grp") %>% - surv_time( - vars = "AVAL", - var_labels = paste0("Time to 1st LLT Event (", levels(anl$AVALU), ")"), - is_event = "is_event", - table_names = "time_to_event" - ) - - result <- build_table(lyt, df = anl, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("LBT11 variant 3 works as expected", { - strata <- c("RACE", "SEX") - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARMCD", ref_group = "Pbo", split_fun = ref_group_position("first")) %>% - count_occurrences(vars = "event_grp") %>% - surv_time( - vars = "AVAL", - var_labels = paste0("Time to 1st LLT Event (", levels(anl$AVALU), ")"), - is_event = "is_event", - table_names = "time_to_event" - ) %>% - coxph_pairwise( - vars = "AVAL", - is_event = "is_event", - var_labels = "Unstratified Analysis", - control = control_coxph(pval_method = "log-rank"), - table_names = "coxph_unstratified" - ) %>% - coxph_pairwise( - vars = "AVAL", - is_event = "is_event", - var_labels = paste0("Stratified By: ", paste(strata, collapse = ", ")), - strata = strata, - table_names = "coxph_stratified" - ) - - result <- build_table(lyt, df = anl, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_lbt11_bl.R b/tests/testthat/test-table_lbt11_bl.R deleted file mode 100644 index 53cbacd3..00000000 --- a/tests/testthat/test-table_lbt11_bl.R +++ /dev/null @@ -1,111 +0,0 @@ -adsl <- adsl_raw -adsaftte <- adaette_raw - -# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels. -adsl <- df_explicit_na(adsl) -adsaftte <- df_explicit_na(adsaftte) - -adsl_safl <- dplyr::filter(adsl, .data$SAFFL == "Y") - -anl <- adsaftte %>% - dplyr::filter( - SAFFL == "Y", - PARAMCD == "HYSTTEBL" - ) %>% - dplyr::mutate( - AVAL = .data$AVAL * dplyr::case_when( # convert to days, if possible - .data$AVALU == "WEEKS" ~ 7, - .data$AVALU == "MONTHS" ~ 30.4375, - .data$AVALU == "YEARS" ~ 365, - TRUE ~ 1 - ), - AVALU = factor(dplyr::case_when( - .data$AVALU %in% c("WEEKS", "MONTHS", "YEARS") ~ factor("DAYS"), - TRUE ~ .data$AVALU - ), levels = "DAYS"), - is_event = CNSR == 0, # this will be a LLT event - event_grp = factor( - dplyr::case_when( - CNSR == 0 ~ "Patients with LLT event (%)", - CNSR == 1 ~ "Patients without LLT event (%)" - ), - levels = c( - "Patients with LLT event (%)", - "Patients without LLT event (%)" - ) - ) - ) - -testthat::test_that("LBT11_BL variant 1 works as expected", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% - count_occurrences(vars = "event_grp") %>% - surv_time( - vars = "AVAL", - var_labels = paste0("Time to 1st LLT Event (", levels(anl$AVALU), ")"), - is_event = "is_event", - table_names = "time_to_event" - ) %>% - coxph_pairwise( - vars = "AVAL", - is_event = "is_event", - var_labels = "Unstratified Analysis", - control = control_coxph(pval_method = "log-rank"), - table_names = "coxph_unstratified" - ) - - result <- build_table(lyt, df = anl, alt_counts_df = adsl_safl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("LBT11_BL variant 2 works as expected", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% - count_occurrences(vars = "event_grp") %>% - surv_time( - vars = "AVAL", - var_labels = paste0("Time to 1st LLT Event (", levels(anl$AVALU), ")"), - is_event = "is_event", - table_names = "time_to_event" - ) - - result <- build_table(lyt, df = anl, alt_counts_df = adsl_safl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("LBT11_BL variant 3 works as expected", { - strata <- c("RACE", "SEX") - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% - count_occurrences(vars = "event_grp") %>% - surv_time( - vars = "AVAL", - var_labels = paste0("Time to 1st LLT Event (", levels(anl$AVALU), ")"), - is_event = "is_event", - table_names = "time_to_event" - ) %>% - coxph_pairwise( - vars = "AVAL", - is_event = "is_event", - var_labels = "Unstratified Analysis", - control = control_coxph(pval_method = "log-rank"), - table_names = "coxph_unstratified" - ) %>% - coxph_pairwise( - vars = "AVAL", - is_event = "is_event", - var_labels = paste0("Stratified By: ", paste(strata, collapse = ", ")), - strata = strata, - table_names = "coxph_stratified" - ) - - result <- build_table(lyt, df = anl, alt_counts_df = adsl_safl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_lbt12.R b/tests/testthat/test-table_lbt12.R deleted file mode 100644 index ececac14..00000000 --- a/tests/testthat/test-table_lbt12.R +++ /dev/null @@ -1,65 +0,0 @@ -adhy <- pharmaverseadam::adlb %>% - filter(PARAMCD %in% c("ALT", "AST") & !(DTYPE %in% c("MINIMUM", "MAXIMUM")) & AVISIT != "Baseline" & SAFFL == "Y") %>% - mutate( - APERIODC = ifelse( - AVISIT %in% c("Unscheduled 1.1", "Unscheduled 1.2", "Unscheduled 1.3", "Week 2"), - "PERIOD 1", - "PERIOD 2" - ), - AVAL2 = ifelse(AVAL > 3 * ANRHI, "Y", "N") - ) %>% - select(USUBJID, ACTARM, AVISIT, APERIODC, PARAMCD, AVAL2) - -adhy_altast <- adhy %>% - pivot_wider(., names_from = PARAMCD, values_from = AVAL2) %>% - mutate( - PARAMCD = "ALTAST", - AVAL2 = ifelse(ALT == "Y" | AST == "Y", "Y", "N") - ) %>% - select(USUBJID, ACTARM, AVISIT, APERIODC, PARAMCD, AVAL2) - -anl <- bind_rows(adhy, adhy_altast) -anl$APERIODC <- as.factor(anl$APERIODC) # to ensure the table is built even if there is no patients after filtering -anl$ACTARM <- as.factor(anl$ACTARM) # to ensure the table is built even if there is no patients after filtering - -anl <- anl %>% - mutate( - ARM_AVALC = factor( - case_when( - AVAL2 == "Y" ~ as.character(ACTARM), - TRUE ~ "Criteria not met" - ), - levels = c(levels(anl$ACTARM), "Criteria not met") - ), - PARAM = factor( - case_when( - PARAMCD == "ALT" ~ "AST >3x ULN", - PARAMCD == "AST" ~ "ALT >3x ULN", - PARAMCD == "ALTAST" ~ "AST >3x ULN or ALT >3x ULN" - ), - levels = c("AST >3x ULN", "ALT >3x ULN", "AST >3x ULN or ALT >3x ULN") - ), - TITLE = factor("First Elevated Result Occurring During") - ) - -anl <- df_explicit_na(anl) - -testthat::test_that("LBT12 works as expected", { - result <- basic_table() %>% - split_cols_by("TITLE") %>% - split_cols_by("APERIODC") %>% - split_rows_by("PARAM") %>% - split_rows_by("ACTARM", split_fun = drop_split_levels, child_labels = "hidden") %>% - count_occurrences("ARM_AVALC", .stats = "fraction", denom = "n", drop = TRUE) %>% - build_table(anl) - - criteria_fun <- function(tr) { - row_label <- obj_label(tr) - dplyr::if_else(row_label == "Criteria not met", TRUE, FALSE) - } - - result <- result %>% trim_rows(criteria = criteria_fun) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_lbt12_bl.R b/tests/testthat/test-table_lbt12_bl.R deleted file mode 100644 index 97d5f528..00000000 --- a/tests/testthat/test-table_lbt12_bl.R +++ /dev/null @@ -1,65 +0,0 @@ -adhy <- pharmaverseadam::adlb %>% - filter(PARAMCD %in% c("ALT", "AST") & !(DTYPE %in% c("MINIMUM", "MAXIMUM")) & AVISIT != "Baseline" & SAFFL == "Y") %>% - mutate( - APERIODC = ifelse( - AVISIT %in% c("Unscheduled 1.1", "Unscheduled 1.2", "Unscheduled 1.3", "Week 2"), - "PERIOD 1", - "PERIOD 2" - ), - AVAL2 = ifelse(AVAL > 3 * BASE, "Y", "N") - ) %>% - select(USUBJID, ACTARM, AVISIT, APERIODC, PARAMCD, AVAL2) - -adhy_altast <- adhy %>% - pivot_wider(., names_from = PARAMCD, values_from = AVAL2) %>% - mutate( - PARAMCD = "ALTAST", - AVAL2 = ifelse(ALT == "Y" | AST == "Y", "Y", "N") - ) %>% - select(USUBJID, ACTARM, AVISIT, APERIODC, PARAMCD, AVAL2) - -anl <- bind_rows(adhy, adhy_altast) -anl$APERIODC <- as.factor(anl$APERIODC) # to ensure the table is built even if there is no patients after filtering -anl$ACTARM <- as.factor(anl$ACTARM) # to ensure the table is built even if there is no patients after filtering - -anl <- anl %>% - mutate( - ARM_AVALC = factor( - case_when( - AVAL2 == "Y" ~ as.character(ACTARM), - TRUE ~ "Criteria not met" - ), - levels = c(levels(anl$ACTARM), "Criteria not met") - ), - PARAM = factor( - case_when( - PARAMCD == "ALT" ~ "AST >3x Baseline", - PARAMCD == "AST" ~ "ALT >3x Baseline", - PARAMCD == "ALTAST" ~ "AST >3x Baseline or ALT >3x Baseline" - ), - levels = c("AST >3x Baseline", "ALT >3x Baseline", "AST >3x Baseline or ALT >3x Baseline") - ), - TITLE = factor("First Elevated Result Occurring During") - ) - -anl <- df_explicit_na(anl) - -testthat::test_that("LBT12_BL works as expected", { - result <- basic_table() %>% - split_cols_by("TITLE") %>% - split_cols_by("APERIODC") %>% - split_rows_by("PARAM") %>% - split_rows_by("ACTARM", split_fun = drop_split_levels, child_labels = "hidden") %>% - count_occurrences("ARM_AVALC", .stats = "fraction", denom = "n", drop = TRUE) %>% - build_table(anl) - - criteria_fun <- function(tr) { - row_label <- obj_label(tr) - dplyr::if_else(row_label == "Criteria not met", TRUE, FALSE) - } - - result <- result %>% trim_rows(criteria = criteria_fun) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_lbt13.R b/tests/testthat/test-table_lbt13.R deleted file mode 100644 index accb4363..00000000 --- a/tests/testthat/test-table_lbt13.R +++ /dev/null @@ -1,369 +0,0 @@ -adsl <- adsl_pharmaverse -adlb <- adlb_pharmaverse %>% - mutate( - WGRLOVFL = ifelse(AVISIT == "POST-BASELINE MINIMUM", "Y", ""), - WGRHIVFL = ifelse(AVISIT == "POST-BASELINE MAXIMUM", "Y", "") - ) - -adsl <- df_explicit_na(adsl) -adlb <- df_explicit_na(adlb) - -# Please note that in real clinical data, population flag like SAFFL, and parameter category like PARCAT2 needs to be -# selected properly. -adsl_f <- adsl %>% filter(SAFFL == "Y") -adlb <- adlb %>% filter(PARAMCD == "ALB" & ANL01FL == "Y") - -testthat::test_that("LBT13 variant 1: LOW works as expected", { - adlb_f <- adlb %>% filter(WGRLOVFL == "Y") - - # Please note the step below can be skipped if you are using DTYPE PHANTOM - # you would use this adsl_adlb_merge_using_worst_flag - - # Create new grouping variables ATOXGR_GP, BTOXGR_GP - adlb_out <- adlb_f %>% - mutate( - ATOXGR_GP = case_when( - ATOXGR %in% c(0, 1, 2, 3, 4) ~ "Not Low", - ATOXGR == -1 ~ "1", - ATOXGR == -2 ~ "2", - ATOXGR == -3 ~ "3", - ATOXGR == -4 ~ "4", - ATOXGR == "" ~ "Missing" - ) - ) %>% - mutate( - BTOXGR_GP = case_when( - BTOXGR %in% c(0, 1, 2, 3, 4) ~ "Not Low", - BTOXGR == -1 ~ "1", - BTOXGR == -2 ~ "2", - BTOXGR == -3 ~ "3", - BTOXGR == -4 ~ "4", - BTOXGR == "" ~ "Missing" - ) - ) - - adlb_out <- adlb_out %>% mutate( - AVISIT = forcats::fct_reorder(AVISIT, AVISITN), - ATOXGR_GP = factor(ATOXGR_GP, levels = c("Not Low", "1", "2", "3", "4", "Missing")), - BTOXGR_GP = factor(BTOXGR_GP, levels = c("Not Low", "1", "2", "3", "4", "Missing")) - ) - - adlb_out <- adlb_out %>% - var_relabel( - PARAMCD = "Parameter Code", - AVISIT = "Visit", - ATOXGR_GP = "NCI CTCAE Grade at Visit", - BTOXGR_GP = "Baseline NCI CTCAE Grade" - ) - - result <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - split_rows_by( - "PARAMCD", - split_fun = drop_split_levels, label_pos = "topleft", split_label = obj_label(adlb_out$PARAMCD) - ) %>% - split_rows_by( - "AVISIT", - split_fun = drop_split_levels, label_pos = "topleft", split_label = obj_label(adlb_out$AVISIT) - ) %>% - split_rows_by( - "ATOXGR_GP", - split_fun = drop_split_levels, label_pos = "topleft", split_label = obj_label(adlb_out$ATOXGR_GP) - ) %>% - summarize_num_patients(var = "USUBJID", .stats = c("unique_count")) %>% - count_occurrences("BTOXGR_GP", denom = "n", drop = TRUE) %>% - append_varlabels(adlb_out, "BTOXGR_GP", indent = 3L) %>% - build_table(df = adlb_out, alt_counts_df = adsl_f) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("LBT13 variant 2: HIGH works as expected", { - adlb_f <- adlb %>% filter(WGRHIVFL == "Y") - - # Please note the step below can be skipped if you are using DTYPE PHANTOM - adlb_out <- adsl_f %>% - h_adsl_adlb_merge_using_worst_flag( - adlb_f, - worst_flag = c("WGRHIVFL" = "Y"), - by_visit = TRUE, - no_fillin_visits = c("SCREENING", "BASELINE", "UNSCHEDULED") - ) - - # Create new grouping variables ATOXGR_GP, BTOXGR_GP - adlb_out <- adlb_out %>% - mutate( - ATOXGR_GP = case_when( - ATOXGR %in% c(0, -1, -2, -3, -4) ~ "Not High", - ATOXGR == 1 ~ "1", - ATOXGR == 2 ~ "2", - ATOXGR == 3 ~ "3", - ATOXGR == 4 ~ "4", - ATOXGR == "" ~ "Missing" - ) - ) %>% - mutate( - BTOXGR_GP = case_when( - BTOXGR %in% c(0, -1, -2, -3, -4) ~ "Not High", - BTOXGR == 1 ~ "1", - BTOXGR == 2 ~ "2", - BTOXGR == 3 ~ "3", - BTOXGR == 4 ~ "4", - BTOXGR == "" ~ "Missing" - ) - ) - - adlb_out <- adlb_out %>% mutate( - AVISIT = forcats::fct_reorder(AVISIT, AVISITN), - ATOXGR_GP = factor(ATOXGR_GP, levels = c("Not High", "1", "2", "3", "4", "Missing")), - BTOXGR_GP = factor(BTOXGR_GP, levels = c("Not High", "1", "2", "3", "4", "Missing")) - ) - - adlb_out <- adlb_out %>% - var_relabel( - PARAMCD = "Parameter Code", - AVISIT = "Visit", - ATOXGR_GP = "NCI CTCAE Grade at Visit", - BTOXGR_GP = "Baseline NCI CTCAE Grade" - ) - - result <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - split_rows_by( - "PARAMCD", - split_fun = drop_split_levels, label_pos = "topleft", split_label = obj_label(adlb_out$PARAMCD) - ) %>% - split_rows_by( - "AVISIT", - split_fun = drop_split_levels, label_pos = "topleft", split_label = obj_label(adlb_out$AVISIT) - ) %>% - split_rows_by( - "ATOXGR_GP", - split_fun = drop_split_levels, label_pos = "topleft", split_label = obj_label(adlb_out$ATOXGR_GP) - ) %>% - summarize_num_patients(var = "USUBJID", .stats = c("unique_count")) %>% - count_occurrences("BTOXGR_GP", denom = "n", drop = TRUE) %>% - append_varlabels(adlb_out, "BTOXGR_GP", indent = 3L) %>% - build_table(df = adlb_out, alt_counts_df = adsl_f) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("LBT13 variant 3: LOW without baseline missing works as expected", { - adlb_f <- adlb %>% filter(WGRLOVFL == "Y") - - # Please note the step below can be skipped if you are using DTYPE PHANTOM - adlb_out <- adsl_f %>% - h_adsl_adlb_merge_using_worst_flag( - adlb_f, - worst_flag = c("WGRLOVFL" = "Y"), - by_visit = TRUE, - no_fillin_visits = c("SCREENING", "BASELINE", "UNSCHEDULED") - ) - - # Create new grouping variables ATOXGR_GP, BTOXGR_GP - adlb_out <- adlb_out %>% - filter(BTOXGR != "") %>% # filter out missing baseline grade - mutate( - ATOXGR_GP = case_when( - ATOXGR %in% c(0, 1, 2, 3, 4) ~ "Not Low", - ATOXGR == -1 ~ "1", - ATOXGR == -2 ~ "2", - ATOXGR == -3 ~ "3", - ATOXGR == -4 ~ "4", - ATOXGR == "" ~ "Missing" - ) - ) %>% - mutate( - BTOXGR_GP = case_when( - BTOXGR %in% c(0, 1, 2, 3, 4) ~ "Not Low", - BTOXGR == -1 ~ "1", - BTOXGR == -2 ~ "2", - BTOXGR == -3 ~ "3", - BTOXGR == -4 ~ "4" - ) - ) - - adlb_out <- adlb_out %>% mutate( - AVISIT = forcats::fct_reorder(AVISIT, AVISITN), - ATOXGR_GP = factor(ATOXGR_GP, levels = c("Not Low", "1", "2", "3", "4", "Missing")), - BTOXGR_GP = factor(BTOXGR_GP, levels = c("Not Low", "1", "2", "3", "4")) - ) - - adlb_out <- adlb_out %>% - var_relabel( - PARAMCD = "Parameter Code", - AVISIT = "Visit", - ATOXGR_GP = "NCI CTCAE Grade at Visit", - BTOXGR_GP = "Baseline NCI CTCAE Grade" - ) - - result <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - split_rows_by( - "PARAMCD", - split_fun = drop_split_levels, label_pos = "topleft", split_label = obj_label(adlb_out$PARAMCD) - ) %>% - split_rows_by( - "AVISIT", - split_fun = drop_split_levels, label_pos = "topleft", split_label = obj_label(adlb_out$AVISIT) - ) %>% - split_rows_by( - "ATOXGR_GP", - split_fun = drop_split_levels, label_pos = "topleft", split_label = obj_label(adlb_out$ATOXGR_GP) - ) %>% - summarize_num_patients(var = "USUBJID", .stats = c("unique_count")) %>% - count_occurrences("BTOXGR_GP", denom = "n", drop = TRUE) %>% - append_varlabels(adlb_out, "BTOXGR_GP", indent = 3L) %>% - build_table(df = adlb_out, alt_counts_df = adsl_f) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("LBT13 variant 4: HIGH with missing baseline considered as grade 0 works as expected", { # nolint - adlb_f <- adlb %>% filter(WGRHIVFL == "Y") - - # Please note the step below can be skipped if you are using DTYPE PHANTOM - adlb_out <- adsl_f %>% - h_adsl_adlb_merge_using_worst_flag( - adlb_f, - worst_flag = c("WGRHIVFL" = "Y"), - by_visit = TRUE, - no_fillin_visits = c("SCREENING", "BASELINE", "UNSCHEDULED") - ) - - # Create new grouping variables ATOXGR_GP, BTOXGR_GP - adlb_out <- adlb_out %>% - mutate( - ATOXGR_GP = case_when( - ATOXGR %in% c(0, -1, -2, -3, -4) ~ "Not High", - ATOXGR == 1 ~ "1", - ATOXGR == 2 ~ "2", - ATOXGR == 3 ~ "3", - ATOXGR == 4 ~ "4", - ATOXGR == "" ~ "Missing" - ) - ) %>% - mutate( - BTOXGR_GP = case_when( - BTOXGR %in% c(0, -1, -2, -3, -4, "") ~ "Not High", # Missing BTOXGR now grouped to "Not High" - BTOXGR == 1 ~ "1", - BTOXGR == 2 ~ "2", - BTOXGR == 3 ~ "3", - BTOXGR == 4 ~ "4" - ) - ) - - adlb_out <- adlb_out %>% mutate( - AVISIT = forcats::fct_reorder(AVISIT, AVISITN), - ATOXGR_GP = factor(ATOXGR_GP, levels = c("Not High", "1", "2", "3", "4", "Missing")), - BTOXGR_GP = factor(BTOXGR_GP, levels = c("Not High", "1", "2", "3", "4", "Missing")) - ) - - adlb_out <- adlb_out %>% - var_relabel( - PARAMCD = "Parameter Code", - AVISIT = "Visit", - ATOXGR_GP = "NCI CTCAE Grade at Visit", - BTOXGR_GP = "Baseline NCI CTCAE Grade" - ) - - result <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - split_rows_by( - "PARAMCD", - split_fun = drop_split_levels, label_pos = "topleft", split_label = obj_label(adlb_out$PARAMCD) - ) %>% - split_rows_by( - "AVISIT", - split_fun = drop_split_levels, label_pos = "topleft", split_label = obj_label(adlb_out$AVISIT) - ) %>% - split_rows_by( - "ATOXGR_GP", - split_fun = drop_split_levels, label_pos = "topleft", split_label = obj_label(adlb_out$ATOXGR_GP) - ) %>% - summarize_num_patients(var = "USUBJID", .stats = c("unique_count")) %>% - count_occurrences("BTOXGR_GP", denom = "n", drop = TRUE) %>% - append_varlabels(adlb_out, "BTOXGR_GP", indent = 3L) %>% - build_table(df = adlb_out, alt_counts_df = adsl_f) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("LBT14 variant 5: HIGH with filled in grades works as expected", { - adlb_f <- adlb %>% filter(WGRHIVFL == "Y") - - # Please note the step below can be skipped if you are using DTYPE PHANTOM - adlb_out <- adsl_f %>% - h_adsl_adlb_merge_using_worst_flag( - adlb_f, - worst_flag = c("WGRHIVFL" = "Y"), - by_visit = TRUE, - no_fillin_visits = c("SCREENING", "BASELINE", "UNSCHEDULED") - ) - - # Create new grouping variables ATOXGR_GP, BTOXGR_GP - adlb_out <- adlb_out %>% - mutate( - ATOXGR_GP = case_when( - ATOXGR %in% c(0, -1, -2, -3, -4) ~ "Not High", - ATOXGR == 1 ~ "1", - ATOXGR == 2 ~ "2", - ATOXGR == 3 ~ "3", - ATOXGR == 4 ~ "4", - ATOXGR == "" ~ "Missing" - ) - ) %>% - mutate( - BTOXGR_GP = case_when( - BTOXGR %in% c(0, -1, -2, -3, -4) ~ "Not High", - BTOXGR == 1 ~ "1", - BTOXGR == 2 ~ "2", - BTOXGR == 3 ~ "3", - BTOXGR == 4 ~ "4", - BTOXGR == "" ~ "Missing" - ) - ) - - adlb_out <- adlb_out %>% mutate( - AVISIT = forcats::fct_reorder(AVISIT, AVISITN), - ATOXGR_GP = factor(ATOXGR_GP, levels = c("Not High", "1", "2", "3", "4", "Missing")), - BTOXGR_GP = factor(BTOXGR_GP, levels = c("Not High", "1", "2", "3", "4", "Missing")) - ) - - adlb_out <- adlb_out %>% - var_relabel( - PARAMCD = "Parameter Code", - AVISIT = "Visit", - ATOXGR_GP = "NCI CTCAE Grade at Visit", - BTOXGR_GP = "Baseline NCI CTCAE Grade" - ) - - result <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - split_rows_by( - "PARAMCD", - split_fun = drop_split_levels, label_pos = "topleft", split_label = obj_label(adlb_out$PARAMCD) - ) %>% - split_rows_by( - "AVISIT", - split_fun = drop_split_levels, label_pos = "topleft", split_label = obj_label(adlb_out$AVISIT) - ) %>% - split_rows_by( - "ATOXGR_GP", - split_fun = keep_split_levels(c("Not High", "1", "2", "3", "4", "Missing")), - label_pos = "topleft", - split_label = obj_label(adlb_out$ATOXGR_GP) - ) %>% - summarize_num_patients(var = "USUBJID", .stats = c("unique_count")) %>% - count_occurrences("BTOXGR_GP", denom = "n", drop = FALSE) %>% - append_varlabels(adlb_out, "BTOXGR_GP", indent = 3L) %>% - build_table(df = adlb_out, alt_counts_df = adsl_f) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_lbt14.R b/tests/testthat/test-table_lbt14.R deleted file mode 100644 index 1f3093bd..00000000 --- a/tests/testthat/test-table_lbt14.R +++ /dev/null @@ -1,275 +0,0 @@ -adsl <- adsl_pharmaverse -adlb <- adlb_pharmaverse %>% - mutate( - WGRLOFL = ifelse(AVISIT == "POST-BASELINE MINIMUM", "Y", ""), - WGRHIFL = ifelse(AVISIT == "POST-BASELINE MAXIMUM", "Y", "") - ) - -adsl <- df_explicit_na(adsl) -adlb <- df_explicit_na(adlb) - -adsl_f <- adsl %>% filter(SAFFL == "Y") -adlb <- adlb %>% filter(SAFFL == "Y") - -testthat::test_that("LBT14 variant 1: HIGH works as expected", { - adlb_f <- adlb %>% filter(WGRHIFL == "Y") - - # Please note the step below can be skipped if you are using DTYPE PHANTOM - adlb_out <- h_adsl_adlb_merge_using_worst_flag(adsl_f, adlb_f, worst_flag = c("WGRHIFL" = "Y")) - - # Create new grouping variables ATOXGR_GP, BTOXGR_GP - adlb_out <- adlb_out %>% - mutate( - ATOXGR_GP = factor(case_when( - ATOXGR %in% c(0, -1, -2, -3, -4) ~ "Not High", - ATOXGR == 1 ~ "1", - ATOXGR == 2 ~ "2", - ATOXGR == 3 ~ "3", - ATOXGR == 4 ~ "4", - ATOXGR == "" ~ "Missing" - ), levels = c("Not High", "1", "2", "3", "4", "Missing")) - ) %>% - mutate( - BTOXGR_GP = factor(case_when( - BTOXGR %in% c(0, -1, -2, -3, -4) ~ "Not High", - BTOXGR == 1 ~ "1", - BTOXGR == 2 ~ "2", - BTOXGR == 3 ~ "3", - BTOXGR == 4 ~ "4", - BTOXGR == "" ~ "Missing" - ), levels = c("Not High", "1", "2", "3", "4", "Missing")) - ) - - result <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - split_rows_by( - "PARAM", - split_fun = drop_split_levels, - label_pos = "topleft", - split_label = "Parameter" - ) %>% - split_rows_by( - "BTOXGR_GP", - label_pos = "topleft", - split_label = " Baseline NCI-CTCAE Grade", - indent_mod = 2L - ) %>% - summarize_num_patients(var = "USUBJID", .stats = c("unique_count"), unique_count_suffix = FALSE) %>% - count_occurrences_by_grade("ATOXGR_GP", denom = "n", drop = FALSE, .indent_mods = 3L) %>% - append_topleft(" Post-baseline NCI-CTCAE Grade") %>% - build_table(df = adlb_out, alt_counts_df = adsl_f) %>% - prune_table() - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("LBT14 variant 2: LOW works as expected", { - adlb_f <- adlb %>% filter(WGRLOFL == "Y") - - # Please note the step below can be skipped if you are using DTYPE PHANTOM - adlb_out <- h_adsl_adlb_merge_using_worst_flag(adsl_f, adlb_f, worst_flag = c("WGRLOFL" = "Y")) - - # Create new grouping variables ATOXGR_GP, BTOXGR_GP - adlb_out <- adlb_out %>% - mutate( - ATOXGR_GP = factor(case_when( - ATOXGR %in% c(0, 1, 2, 3, 4) ~ "Not Low", - ATOXGR == -1 ~ "1", - ATOXGR == -2 ~ "2", - ATOXGR == -3 ~ "3", - ATOXGR == -4 ~ "4", - ATOXGR == "" ~ "Missing" - ), levels = c("Not Low", "1", "2", "3", "4", "Missing")) - ) %>% - mutate( - BTOXGR_GP = factor(case_when( - BTOXGR %in% c(0, 1, 2, 3, 4) ~ "Not Low", - BTOXGR == -1 ~ "1", - BTOXGR == -2 ~ "2", - BTOXGR == -3 ~ "3", - BTOXGR == -4 ~ "4", - BTOXGR == "" ~ "Missing" - ), levels = c("Not Low", "1", "2", "3", "4", "Missing")) - ) - - result <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - split_rows_by( - "PARAM", - split_fun = drop_split_levels, - label_pos = "topleft", - split_label = "Parameter" - ) %>% - split_rows_by( - "BTOXGR_GP", - label_pos = "topleft", - split_label = " Baseline NCI-CTCAE Grade", - indent_mod = 2L - ) %>% - summarize_num_patients(var = "USUBJID", .stats = c("unique_count"), unique_count_suffix = FALSE) %>% - count_occurrences_by_grade("ATOXGR_GP", denom = "n", drop = FALSE, .indent_mods = 3L) %>% - append_topleft(" Post-baseline NCI-CTCAE Grade") %>% - build_table(df = adlb_out, alt_counts_df = adsl_f) %>% - prune_table() - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("LBT14 variant 3: LOW without baseline missing works as expected", { - adlb_f <- adlb %>% filter(WGRHIFL == "Y") - - # Please note the step below can be skipped if you are using DTYPE PHANTOM - adlb_out <- h_adsl_adlb_merge_using_worst_flag(adsl_f, adlb_f, worst_flag = c("WGRHIFL" = "Y")) - - # Create new grouping variables ATOXGR_GP, BTOXGR_GP - adlb_out <- adlb_out %>% - filter(BTOXGR != "") %>% - mutate( - ATOXGR_GP = factor(case_when( - ATOXGR %in% c(0, -1, -2, -3, -4) ~ "Not High", - ATOXGR == 1 ~ "1", - ATOXGR == 2 ~ "2", - ATOXGR == 3 ~ "3", - ATOXGR == 4 ~ "4", - ATOXGR == "" ~ "Missing" - ), levels = c("Not High", "1", "2", "3", "4", "Missing")) - ) %>% - mutate( - BTOXGR_GP = factor(case_when( - BTOXGR %in% c(0, -1, -2, -3, -4) ~ "Not High", - BTOXGR == 1 ~ "1", - BTOXGR == 2 ~ "2", - BTOXGR == 3 ~ "3", - BTOXGR == 4 ~ "4" - ), levels = c("Not High", "1", "2", "3", "4")) - ) - - result <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - split_rows_by( - "PARAM", - split_fun = drop_split_levels, - label_pos = "topleft", - split_label = "Parameter" - ) %>% - split_rows_by( - "BTOXGR_GP", - label_pos = "topleft", - split_label = " Baseline NCI-CTCAE Grade", - indent_mod = 2L - ) %>% - summarize_num_patients(var = "USUBJID", .stats = c("unique_count"), unique_count_suffix = FALSE) %>% - count_occurrences_by_grade("ATOXGR_GP", denom = "n", drop = FALSE, .indent_mods = 3L) %>% - append_topleft(" Post-baseline NCI-CTCAE Grade") %>% - build_table(df = adlb_out, alt_counts_df = adsl_f) %>% - prune_table() - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("LBT14 variant 4: LOW and force 1 missing both baseline and post-baseline, then force the missing baseline as 0 as expected", { # nolint - adlb_f <- adlb %>% filter(WGRLOFL == "Y") - - # Please note the step below can be skipped if you are using DTYPE PHANTOM - adlb_out <- h_adsl_adlb_merge_using_worst_flag(adsl_f, adlb_f, worst_flag = c("WGRLOFL" = "Y")) - - # Create new grouping variables ATOXGR_GP, BTOXGR_GP - adlb_out <- adlb_out %>% - mutate( - ATOXGR_GP = factor(case_when( - ATOXGR %in% c(0, 1, 2, 3, 4) ~ "Not Low", - ATOXGR == -1 ~ "1", - ATOXGR == -2 ~ "2", - ATOXGR == -3 ~ "3", - ATOXGR == -4 ~ "4", - ATOXGR == "" ~ "Missing" - ), levels = c("Not Low", "1", "2", "3", "4")) - ) %>% - mutate( - BTOXGR_GP = factor(case_when( - BTOXGR %in% c(0, 1, 2, 3, 4, "") ~ "Not Low", - BTOXGR == -1 ~ "1", - BTOXGR == -2 ~ "2", - BTOXGR == -3 ~ "3", - BTOXGR == -4 ~ "4" - ), levels = c("Not Low", "1", "2", "3", "4", "Missing")) - ) - - result <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - split_rows_by( - "PARAM", - split_fun = drop_split_levels, - label_pos = "topleft", - split_label = "Parameter" - ) %>% - split_rows_by( - "BTOXGR_GP", - label_pos = "topleft", - split_label = " Baseline NCI-CTCAE Grade", - indent_mod = 2L - ) %>% - summarize_num_patients(var = "USUBJID", .stats = c("unique_count"), unique_count_suffix = FALSE) %>% - count_occurrences_by_grade("ATOXGR_GP", denom = "n", drop = FALSE, .indent_mods = 3L) %>% - append_topleft(" Post-baseline NCI-CTCAE Grade") %>% - build_table(df = adlb_out, alt_counts_df = adsl_f) %>% - prune_table() - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("LBT14 variant 5: HIGH with fillings works as expected", { - adlb_f <- adlb %>% filter(WGRHIFL == "Y") - - # Please note the step below can be skipped if you are using DTYPE PHANTOM - adlb_out <- h_adsl_adlb_merge_using_worst_flag(adsl_f, adlb_f, worst_flag = c("WGRHIFL" = "Y")) - - # Create new grouping variables ATOXGR_GP, BTOXGR_GP - adlb_out <- adlb_out %>% - mutate( - ATOXGR_GP = factor(case_when( - ATOXGR %in% c(0, -1, -2, -3, -4) ~ "Not High", - ATOXGR == 1 ~ "1", - ATOXGR == 2 ~ "2", - ATOXGR == 3 ~ "3", - ATOXGR == 4 ~ "4", - ATOXGR == "" ~ "Missing" - ), levels = c("Not High", "1", "2", "3", "4", "Missing")) - ) %>% - mutate( - BTOXGR_GP = factor(case_when( - BTOXGR %in% c(0, -1, -2, -3, -4) ~ "Not High", - BTOXGR == 1 ~ "1", - BTOXGR == 2 ~ "2", - BTOXGR == 3 ~ "3", - BTOXGR == 4 ~ "4", - BTOXGR == "" ~ "Missing" - ), levels = c("Not High", "1", "2", "3", "4", "Missing")) - ) - - result <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - split_rows_by( - "PARAM", - split_fun = drop_split_levels, - label_pos = "topleft", - split_label = "Parameter" - ) %>% - split_rows_by( - "BTOXGR_GP", - label_pos = "topleft", - split_label = " Baseline NCI-CTCAE Grade", - indent_mod = 2L - ) %>% - summarize_num_patients(var = "USUBJID", .stats = c("unique_count"), unique_count_suffix = FALSE) %>% - count_occurrences_by_grade("ATOXGR_GP", denom = "n", drop = FALSE, .indent_mods = 3L) %>% - append_topleft(" Post-baseline NCI-CTCAE Grade") %>% - build_table(df = adlb_out, alt_counts_df = adsl_f) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_lbt15.R b/tests/testthat/test-table_lbt15.R deleted file mode 100644 index 04008db7..00000000 --- a/tests/testthat/test-table_lbt15.R +++ /dev/null @@ -1,90 +0,0 @@ -adsl <- adsl_pharmaverse -adlb <- adlb_pharmaverse - -adlb <- adlb %>% - mutate( - BTOXGR = case_when( - as.character(BTOXGR) == "" ~ "0", - TRUE ~ as.character(BTOXGR) - ) - ) %>% - filter(ATOXGR %in% as.character(c(-4:4))) %>% - filter(BTOXGR %in% as.character(c(-4:4))) %>% - mutate( - BTOXGR = factor(BTOXGR, levels = c(-4:4)), - ATOXGR = factor(ATOXGR, levels = c(-4:4)), - PARCAT1 = LBCAT - ) - -adlb <- adlb %>% - mutate( - ATOXGR_CAT = forcats::fct_collapse(ATOXGR, - "LOW" = c("-3", "-4"), - "MODERATE/NORMAL" = c("-2", "-1", "0", "1", "2"), - "HIGH" = c("3", "4") - ), - BTOXGR_CAT = forcats::fct_collapse(BTOXGR, - "LOW" = c("-3", "-4"), - "MODERATE/NORMAL" = c("-2", "-1", "0", "1", "2"), - "HIGH" = c("3", "4") - ) - ) %>% - filter(ONTRTFL == "Y") - -adlb_alt_cut <- adlb %>% - mutate( - ATOXGR_CAT = forcats::fct_collapse(ATOXGR, - "LOW" = c("-2", "-3", "-4"), - "MODERATE/NORMAL" = c("-1", "0", "1"), - "HIGH" = c("2", "3", "4") - ), - BTOXGR_CAT = forcats::fct_collapse(BTOXGR, - "LOW" = c("-2", "-3", "-4"), - "MODERATE/NORMAL" = c("-1", "0", "1"), - "HIGH" = c("2", "3", "4") - ) - ) %>% - filter(ONTRTFL == "Y") - -adlb <- adlb %>% var_relabel( - PARCAT1 = "Category for Lab Test", - PARAM = "Parameter" -) - -lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARM") %>% - add_overall_col("All Patients") %>% - split_rows_by( - "PARCAT1", - split_fun = drop_split_levels, - label_pos = "topleft", - split_label = obj_label(adlb$PARCAT1) - ) %>% - split_rows_by( - "PARAM", - split_fun = drop_split_levels, - label_pos = "topleft", - split_label = obj_label(adlb$PARAM) - ) %>% - count_abnormal( - var = "ATOXGR_CAT", - abnormal = list(low = "LOW", high = "HIGH"), - variables = list(id = "USUBJID", baseline = "BTOXGR_CAT"), - exclude_base_abn = TRUE, - .indent_mods = 4L - ) %>% - append_topleft(" Direction of Abnormality") - -testthat::test_that("LBT15 variant 1 works as expected", { - result <- build_table(lyt, adlb, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("LBT15 variant 2 works as expected", { - result <- build_table(lyt, adlb_alt_cut, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_lgrt02.R b/tests/testthat/test-table_lgrt02.R deleted file mode 100644 index 9dd26330..00000000 --- a/tests/testthat/test-table_lgrt02.R +++ /dev/null @@ -1,131 +0,0 @@ -# Tests variants of LGRT02 - -adsl <- adsl_raw -adrs <- adrs_raw - -adsl_cached <- adsl %>% - dplyr::filter(SEX %in% c("F", "M")) %>% - reapply_varlabels(var_labels(adsl)) -adrs_cached <- adrs %>% - dplyr::filter(SEX %in% c("F", "M")) %>% - reapply_varlabels(var_labels(adrs)) - -get_adrs <- function() { - adrs_f <- adrs_cached %>% - dplyr::filter( - PARAMCD == "BESRSPI" - ) %>% - dplyr::mutate( - Response = dplyr::case_when(AVALC %in% c("PR", "CR") ~ 1, TRUE ~ 0), - SEX = factor(SEX, c("M", "F")), - RACE = as.character(RACE), - RACE = factor( - RACE, - levels = c( - "AMERICAN INDIAN OR ALASKA NATIVE", "ASIAN", "BLACK OR AFRICAN AMERICAN", - "WHITE", "MULTIPLE", "NATIVE HAWAIIAN OR OTHER PACIFIC ISLANDER" - ) - ) - ) - var_labels(adrs_f) <- c(var_labels(adrs_cached), Response = "Response") # nolint - adrs_f -} - -testthat::test_that("LGRT02 without interaction term is produced correctly", { - adrs <- get_adrs() - model <- fit_logistic( - adrs, - variables = list(response = "Response", arm = "ARMCD", covariates = c("SEX", "RACE", "AGE")) - ) - conf_level <- 0.95 - df <- broom::tidy(model, conf_level = conf_level) %>% - df_explicit_na(na_level = "_") - - result <- basic_table() %>% - summarize_logistic( - conf_level = conf_level, - drop_and_remove_str = "_" - ) %>% - build_table(df = df) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("LGRT02 with categorical interaction is produced correctly", { - adrs <- get_adrs() - model <- fit_logistic( - adrs, - variables = list( - response = "Response", - arm = "ARMCD", - covariates = c("SEX", "AGE"), - interaction = "SEX" - ) - ) - conf_level <- 0.95 - df <- broom::tidy(model, conf_level = conf_level) %>% - df_explicit_na(na_level = "_") - - result <- basic_table() %>% - summarize_logistic( - conf_level = conf_level, - drop_and_remove_str = "_" - ) %>% - build_table(df = df) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("LGRT02 with continuous interaction is produced correctly", { - adrs <- get_adrs() - model <- fit_logistic( - adrs, - variables = list( - response = "Response", - arm = "ARMCD", - covariates = c("SEX", "AGE"), - interaction = "AGE" - ) - ) - conf_level <- 0.95 - df <- broom::tidy(model, conf_level = conf_level, at = c(18, 65)) %>% - df_explicit_na(na_level = "_") - - result <- basic_table() %>% - summarize_logistic( - conf_level = conf_level, - drop_and_remove_str = "_" - ) %>% - build_table(df = df) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("LGRT02 with setting values indicating an event and custom alpha level is produced correctly", { - adrs <- get_adrs() - model <- fit_logistic( - adrs, - variables = list( - response = "Response", - arm = "ARMCD", - covariates = c("SEX", "AGE", "RACE") - ), - response_definition = "1 - response" - ) - conf_level <- 0.9 - df <- broom::tidy(model, conf_level = conf_level) %>% - df_explicit_na(na_level = "_") - - result <- basic_table() %>% - summarize_logistic( - conf_level = conf_level, - drop_and_remove_str = "_" - ) %>% - build_table(df = df) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_mht01.R b/tests/testthat/test-table_mht01.R deleted file mode 100644 index b5b60071..00000000 --- a/tests/testthat/test-table_mht01.R +++ /dev/null @@ -1,131 +0,0 @@ -# Tests the single variant for MHT01 - -adsl <- adsl_raw -admh <- admh_raw - -adsl <- df_explicit_na(adsl) -admh <- df_explicit_na(admh) - -adsl_f <- adsl %>% - filter(SAFFL == "Y") %>% - select(USUBJID, ACTARM) - -admh_f <- admh %>% - filter(SAFFL == "Y" & MHBODSYS != "" & MHDECOD != "") %>% - var_relabel( - MHBODSYS = "MedDRA System Organ Class", - MHDECOD = "MedDRA Preferred Term" - ) - -split_fun <- drop_split_levels - -lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c("Total number of patients with at least one condition", "Total number of conditions") - ) %>% - split_rows_by( - var = "MHBODSYS", - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(admh_f$MHBODSYS) - ) %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c("Total number of patients with at least one condition", "Total number of conditions"), - show_labels = "hidden" - ) %>% - count_occurrences(vars = "MHDECOD") %>% - append_varlabels(admh_f, "MHDECOD", indent = 1L) - -testthat::test_that("MHT01 variant 1 is produced accurately", { - result <- build_table(lyt, admh_f, alt_counts_df = adsl_f) %>% - prune_table() - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("MHT01 variant 2 is produced accurately", { - admh_f_prior <- admh_f %>% - filter(ASTDY <= 0) - - result <- build_table(lyt, admh_f_prior, alt_counts_df = adsl_f) %>% - prune_table() - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("MHT01 variant 3 is produced accurately", { - split_fun <- drop_split_levels - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique"), - .labels = c("Total number of patients with at least one condition") - ) %>% - split_rows_by( - var = "MHBODSYS", - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(admh_f$MHBODSYS) - ) %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique"), - .labels = c("Total number of patients with at least one condition"), - show_labels = "hidden" - ) %>% - count_occurrences(vars = "MHDECOD") %>% - append_varlabels(admh_f, "MHDECOD", indent = 1L) - - result <- build_table(lyt, admh_f, alt_counts_df = adsl) %>% - prune_table() - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("MHT01 variant 5 is produced accurately", { - split_fun <- drop_split_levels - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - add_overall_col("All Patients") %>% - analyze_num_patients( - "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c(unique = "Total number of patients with at least one event", nonunique = "Total number of conditions") - ) %>% - split_rows_by( - var = "MHBODSYS", - split_fun = split_fun, - child_labels = "visible", - label_pos = "topleft", - split_label = obj_label(admh_f$MHBODSYS) - ) %>% - summarize_num_patients( - "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c(unique = "Total number of patients with at least one event", nonunique = "Total number of conditions") - ) %>% - count_occurrences(vars = "MHDECOD", .indent_mods = -1L) %>% - append_varlabels(admh_f, "MHDECOD", indent = 1L) - - scorefun_hlt <- cont_n_allcols - scorefun_llt <- score_occurrences_cols(col_indices = nlevels(adsl_f$ACTARM) + 1) - - result <- build_table(lyt, admh_f, alt_counts_df = adsl_f) %>% - prune_table() %>% - sort_at_path(path = c("MHBODSYS"), scorefun = scorefun_hlt) %>% - sort_at_path(path = c("MHBODSYS", "*", "MHDECOD"), scorefun = scorefun_llt) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_onct05.R b/tests/testthat/test-table_onct05.R deleted file mode 100644 index a6dfe032..00000000 --- a/tests/testthat/test-table_onct05.R +++ /dev/null @@ -1,123 +0,0 @@ -preprocess_adrs <- function(adrs, n_records = 20) { - adrs_labels <- var_labels(adrs) - adrs <- adrs %>% - dplyr::filter(PARAMCD == "BESRSPI") %>% - dplyr::filter(ARM %in% c("A: Drug X", "B: Placebo")) %>% - dplyr::slice(seq_len(n_records)) %>% - droplevels() %>% - dplyr::mutate( - # Reorder levels of factor to make the placebo group the reference arm. - ARM = forcats::fct_relevel(ARM, "B: Placebo"), - rsp = AVALC == "CR" - ) - var_labels(adrs) <- c(adrs_labels, "Response") - - adrs -} - -adrs <- adrs_raw - -testthat::test_that("ONCT05 variant 1 (Objective Response Rate by Subgroup) is produced correctly", { - adrs <- adrs %>% - preprocess_adrs(n_records = 200) - - df <- extract_rsp_subgroups( - variables = list(rsp = "rsp", arm = "ARM", subgroups = c("SEX", "STRATA2")), - data = adrs - ) - - result <- basic_table() %>% - tabulate_rsp_subgroups(df) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("ONCT05 variant 2 (Specifying class variables) is produced correctly", { - adrs <- adrs %>% - preprocess_adrs(n_records = 200) - - adrs <- adrs %>% - dplyr::mutate( - # Reorder levels of SEX. - SEX = forcats::fct_relevel(SEX, "M", "F"), - # Reorder levels of STRATA1 by frequency. - STRATA1 = forcats::fct_infreq(STRATA1) - ) - - df <- extract_rsp_subgroups( - variables = list(rsp = "rsp", arm = "ARM", subgroups = c("SEX", "STRATA1")), - data = adrs - ) - - result <- basic_table() %>% - tabulate_rsp_subgroups(df) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("ONCT05 variant 3 (selecting columns and changing the alpha level) is produced correctly", { - adrs <- adrs %>% - preprocess_adrs(n_records = 200) - - df <- extract_rsp_subgroups( - variables = list(rsp = "rsp", arm = "ARM", subgroups = c("SEX", "STRATA2")), - data = adrs, - conf_level = 0.9, - method = "chisq" - ) - - result <- basic_table() %>% - tabulate_rsp_subgroups(df, vars = c("n_tot", "or", "ci", "pval")) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("ONCT05 variant 4 (setting values indicating response) is produced correctly", { - # Define new criteria for responder. - adrs <- adrs %>% - preprocess_adrs(n_records = 200) %>% - dplyr::mutate( - new_rsp = AVALC %in% c("CR", "PR") - ) - - df <- extract_rsp_subgroups( - variables = list(rsp = "new_rsp", arm = "ARM", subgroups = c("SEX", "STRATA2")), - data = adrs - ) - - # Response table. - result <- basic_table() %>% - tabulate_rsp_subgroups(df) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("ONCT05 (with risk difference column) is produced correctly", { - adrs <- adrs %>% - preprocess_adrs(n_records = 200) - - df <- extract_rsp_subgroups( - variables = list(rsp = "rsp", arm = "ARM", subgroups = c("SEX", "STRATA2")), - data = adrs - ) - - # Response table. - result <- basic_table() %>% - tabulate_rsp_subgroups( - df = df, - vars = c("n", "prop", "n_tot", "or", "ci"), - riskdiff = control_riskdiff( - arm_x = levels(df$prop$arm)[1], - arm_y = levels(df$prop$arm)[2], - pct = FALSE, - col_label = "Risk Diff. (95% CI)" - ) - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_pdt01.R b/tests/testthat/test-table_pdt01.R deleted file mode 100644 index 3a6791f9..00000000 --- a/tests/testthat/test-table_pdt01.R +++ /dev/null @@ -1,41 +0,0 @@ -adsl <- adsl_raw -addv <- addv_raw - -adsl <- df_explicit_na(adsl) -addv <- df_explicit_na(addv) - -addv <- addv %>% - var_relabel( - DVDECOD = "Category", - DVTERM = "Description" - ) - -testthat::test_that("PDT01 is produced correctly", { - split_fun <- drop_split_levels - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one major protocol deviation", - nonunique = "Total number of major protocol deviations" - ) - ) %>% - split_rows_by( - "DVDECOD", - split_fun = split_fun, - label_pos = "topleft", - split_label = obj_label(addv$DVDECOD) - ) %>% - count_occurrences(vars = "DVTERM") %>% - append_varlabels(addv, "DVTERM", indent = 1L) - - result <- build_table(lyt = lyt, df = addv, alt_counts_df = adsl) %>% - prune_table() %>% - sort_at_path(path = c("DVDECOD", "*", "DVTERM"), scorefun = score_occurrences) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_pdt02.R b/tests/testthat/test-table_pdt02.R deleted file mode 100644 index 07284555..00000000 --- a/tests/testthat/test-table_pdt02.R +++ /dev/null @@ -1,44 +0,0 @@ -adsl <- adsl_raw -addv <- addv_raw - -adsl <- df_explicit_na(adsl) -addv <- df_explicit_na(addv) - -addv_pan <- addv %>% - filter(AEPRELFL == "Y" & DVCAT == "MAJOR") %>% - var_relabel( - DVREAS = "Primary Reason", - DVTERM = "Description" - ) - -testthat::test_that("PDT02 is produced correctly", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - analyze_num_patients( - vars = "USUBJID", - .stats = c("unique", "nonunique"), - .labels = c( - unique = "Total number of patients with at least one major protocol deviation related to epidemic/pandemic", - nonunique = "Total number of major protocol deviations related to epidemic/pandemic" - ) - ) %>% - split_rows_by( - "DVREAS", - split_fun = drop_split_levels, - nested = FALSE, - label_pos = "topleft", - split_label = obj_label(addv_pan$DVREAS) - ) %>% - summarize_num_patients( - var = "USUBJID", - .stats = c("unique"), - .labels = "Site action due to epidemic/pandemic" - ) %>% - count_occurrences(vars = "DVTERM") %>% - append_varlabels(addv_pan, "DVTERM", indent = 1L) - - result <- build_table(lyt, addv_pan, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_pkct01.R b/tests/testthat/test-table_pkct01.R deleted file mode 100644 index 071bb089..00000000 --- a/tests/testthat/test-table_pkct01.R +++ /dev/null @@ -1,143 +0,0 @@ -adpc <- adpc_pharmaverse - -testthat::test_that("PKCT01 is produced correctly", { - l <- basic_table() %>% - split_rows_by( - var = "ARM", - split_fun = keep_split_levels(c( - "Xanomeline High Dose", - "Xanomeline Low Dose" - )) - ) %>% - split_rows_by(var = "PARAM", child_labels = "hidden") %>% - analyze_vars_in_cols(vars = "AVAL") - - result <- build_table(l, df = adpc) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) - - l2 <- basic_table() %>% - split_rows_by( - var = "ARM", - split_fun = keep_split_levels(c( - "Xanomeline High Dose", - "Xanomeline Low Dose" - )) - ) %>% - split_rows_by(var = "PARAM", child_labels = "hidden") %>% - analyze_vars_in_cols( - vars = "AVALCAT1", var_type = "character", .stats = c("n_blq"), - .labels = c(n_blq = "n_blq") - ) - - adpc <- adpc %>% mutate(AVALCAT1 = as.factor(AVALCAT1)) - result <- build_table(l2, df = adpc) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("Specific PKCT01 features are present", { - # Helper function - threesigfmt <- function(x, ...) { - as.character(signif(x, 3)) - } - - # Setting up the data - adpc_1 <- adpc %>% - mutate( - NFRLT = as.factor(NFRLT), - AVALCAT1 = as.factor(AVALCAT1) - ) %>% - filter(ACTARM %in% c("Xanomeline High Dose")) %>% - mutate(ACTARM = factor(ACTARM, levels = c("Xanomeline High Dose"))) %>% - select(NFRLT, ACTARM, VISIT, AVAL, PARAM, AVALCAT1) - - # Row structure - l_rows <- basic_table() %>% - split_rows_by( - var = "ACTARM", - split_label = "Cohort/Treatment", - label_pos = "topleft" - ) %>% - split_rows_by( - var = "VISIT", - split_label = "Visit", - label_pos = "topleft" - ) %>% - split_rows_by( - var = "NFRLT", - split_label = "Norminal Time from First Dose", - label_pos = "topleft", - child_labels = "hidden" - ) - - # Column results for numeric values - lyt <- l_rows %>% - analyze_vars_in_cols( - vars = c("AVAL", "AVALCAT1", rep("AVAL", 8)), - .stats = c( - "n", "n_blq", "mean", "sd", "cv", - "geom_mean", "geom_cv", # "geom_mean_ci", - "median", "min", "max" - ), - .formats = c( - n = "xx.", - n_blq = "xx.", - mean = threesigfmt, - sd = threesigfmt, - cv = "xx.x", - median = threesigfmt, - geom_mean = threesigfmt, - geom_cv = "xx.x", - min = threesigfmt, - max = threesigfmt - ), - .labels = c( - n = "n", - n_blq = "Number\nof\ns", - mean = "Mean", - sd = "SD", - cv = "CV (%) Mean", - geom_mean = "Geometric Mean", - geom_cv = "CV % Geometric Mean", - median = "Median", - min = "Minimum", - max = "Maximum" - ), - na_str = "NE" - ) - result <- build_table(lyt, df = adpc_1) %>% prune_table() - - # Decorating - main_title(result) <- "Summary of PK Concentrations by Nominal Time and Treatment: PK Evaluable\n Protocol: xxxxx" - subtitles(result) <- paste("Analyte: ", unique(unique(adpc$PARAM)), "Treatment:", unique(unique(adpc$ACTARM))) - main_footer(result) <- "NE: Not Estimable" - - # Values are correct - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) - - # Comparing - string_res <- strsplit(toString(matrix_form(result, TRUE)), "\n")[[1]] - - # Checking NAs are NEs - testthat::expect_false(any(sapply(string_res, grepl, pattern = "NA"))) - testthat::expect_equal(sum(sapply(string_res, grepl, pattern = "NE")), 3L) - - # Checking significative digits (DISCLAIMER: this is an hack and is NOT well supported) - mean_vals <- cell_values(result, - rowpath = NULL, - colpath = c("multivars", "AVAL._[[2]]_.") - ) %>% - unlist() - names(mean_vals) <- NULL - tmp_result <- sapply(seq_len(nrow(result)), function(x) matrix_form(result[x, 3])$strings[2, 2]) - tmp_result <- tmp_result[tmp_result != ""] - testthat::expect_equal(tmp_result, as.character(signif(mean_vals, 3))) - - # Pagination works roughly - pag_works <- paginate_table(result, verbose = FALSE, lpp = 21) - testthat::expect_equal(length(pag_works), 6L) -}) diff --git a/tests/testthat/test-table_pkpt02.R b/tests/testthat/test-table_pkpt02.R deleted file mode 100644 index 426f1657..00000000 --- a/tests/testthat/test-table_pkpt02.R +++ /dev/null @@ -1,45 +0,0 @@ -# Data generation -adpp <- adpp_pharmaverse -adpp_plasma <- adpp %>% - dplyr::filter(PPSPEC == "PLASMA") %>% - mutate(PARAM = paste0(PARAMCD, " (", PPORRESU, ")")) # temp fix for potential bug in h_pkparam_sort() - -# Define template layout -l <- basic_table() %>% - split_cols_by( - var = "ARMCD", - split_fun = trim_levels_in_group("ARMCD"), - # label_pos = "topleft", # nolint - split_label = "Treatment Arm" - ) %>% - split_rows_by( - var = "PKPARAM", - label_pos = "topleft", - split_label = "PK Parameter" - ) %>% - analyze_vars( - vars = "AVAL", - .stats = c("n", "mean_sd", "cv", "geom_mean", "geom_cv", "median", "range"), - .formats = c( - n = "xx.", - mean_sd = sprintf_format("%.3e (%.3e)"), - cv = "xx.x", - geom_mean = sprintf_format("%.3e"), - geom_cv = "xx.x", - median = sprintf_format("%.3e"), - range = sprintf_format("%.3e - %.3e") - ) - ) - -# PKPT02 XANOMELINE -testthat::test_that("PKPT02 is produced correctly for Drug X", { - adpp0 <- adpp_plasma %>% - filter(PPCAT == "XANOMELINE") %>% - h_pkparam_sort() %>% - mutate(PKPARAM = factor(paste0(TLG_DISPLAY, " (", PPORRESU, ")"))) - - result <- build_table(l, df = adpp0) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_pkpt03.R b/tests/testthat/test-table_pkpt03.R deleted file mode 100644 index 82e29c38..00000000 --- a/tests/testthat/test-table_pkpt03.R +++ /dev/null @@ -1,70 +0,0 @@ -# Data generation -adpp <- adpp_pharmaverse -adpp_plasma <- adpp %>% - dplyr::filter(PPSPEC == "PLASMA") %>% - mutate(PARAM = paste0(PARAMCD, " (", PPORRESU, ")")) - -# Helper function -threesigfmt <- function(x, ...) { - as.character(signif(x, 3)) -} - -# Define template layout -l <- basic_table() %>% - split_rows_by( - var = "ARMCD", - split_fun = trim_levels_in_group("ARMCD"), - label_pos = "topleft", - split_label = "Treatment Arm" - ) %>% - split_rows_by( - var = "PKPARAM", - label_pos = "topleft", - split_label = "PK Parameter", - child_labels = "hidden" - ) %>% - analyze_vars_in_cols( - vars = "AVAL", - .stats = c( - "n", "mean", "sd", "cv", - "geom_mean", "geom_cv", "median", - "min", "max" - ), - .labels = c( - n = "n", - mean = "Mean", - sd = "SD", - cv = "CV (%)", - geom_mean = "Geometric Mean", - geom_cv = "CV % Geometric Mean", - median = "Median", - min = "Minimum", - max = "Maximum" - ), - .formats = c( - n = "xx.", - mean = threesigfmt, - sd = threesigfmt, - cv = "xx.x", - median = threesigfmt, - geom_mean = threesigfmt, - geom_cv = "xx.x", - min = threesigfmt, - max = threesigfmt - ) - ) - -# PKPT03 -testthat::test_that("PKPT03 Drug X is produced correctly", { - # Plasma XANOMELINE - adpp0 <- adpp_plasma %>% - dplyr::filter(PPCAT == "XANOMELINE") %>% - h_pkparam_sort() %>% - dplyr::mutate(PKPARAM = factor(paste0(TLG_DISPLAY, " (", PPORRESU, ")"))) - result <- build_table(l, df = adpp0) - main_title(result) <- paste("Summary of", unique(adpp0$PPSPEC), "PK Parameter by Treatment Arm, PK Population") - subtitles(result) <- paste("Analyte:", unique(adpp0$PPCAT), "\nVisit:", unique(adpp0$AVISIT)) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_pkpt04.R b/tests/testthat/test-table_pkpt04.R deleted file mode 100644 index a33cdfc4..00000000 --- a/tests/testthat/test-table_pkpt04.R +++ /dev/null @@ -1,42 +0,0 @@ -# Data generation -adpp <- adpp_pharmaverse -adpp_urine <- adpp %>% dplyr::filter(PPSPEC == "URINE", AVISIT == "Day 1") - -# Define template layout -l <- basic_table() %>% - split_cols_by( - var = "ARMCD", - split_fun = trim_levels_in_group("ARMCD"), - # label_pos = "topleft", # nolint - split_label = "Treatment Arm" - ) %>% - split_rows_by( - var = "PPTEST", - label_pos = "topleft", - split_label = "PK Parameter" - ) %>% - analyze_vars( - vars = "AVAL", - .stats = c("n", "mean_sd", "cv", "geom_mean", "geom_cv", "median", "range"), - .formats = c( - n = "xx.", - mean_sd = sprintf_format("%.3e (%.3e)"), - cv = "xx.x", - geom_mean = sprintf_format("%.3e"), - geom_cv = "xx.x", - median = sprintf_format("%.3e"), - range = sprintf_format("%.3e - %.3e") - ) - ) - -# PKPT04 Drug X -testthat::test_that("PKPT04 is produced correctly for Drug X", { - adpp0 <- adpp_urine %>% - filter(PPCAT == "XANOMELINE") %>% - mutate(PKPARAM = factor(paste0(PPTEST, " (", AVALU, ")"))) - - result <- build_table(l, df = adpp0) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_pkpt05.R b/tests/testthat/test-table_pkpt05.R deleted file mode 100644 index b12b00b0..00000000 --- a/tests/testthat/test-table_pkpt05.R +++ /dev/null @@ -1,66 +0,0 @@ -# Data generation -adpp <- adpp_pharmaverse -adpp_urine <- adpp %>% dplyr::filter(PPSPEC == "URINE", AVISIT == "Day 1") - -# Helper function -threesigfmt <- function(x, ...) { - as.character(signif(x, 3)) -} - -# Define template layout -l <- basic_table() %>% - split_rows_by( - var = "ARMCD", - split_fun = trim_levels_in_group("ARMCD"), - label_pos = "topleft", - split_label = "Treatment Arm" - ) %>% - split_rows_by( - var = "PPTEST", - label_pos = "topleft", - split_label = "PK Parameter", - child_labels = "hidden" - ) %>% - analyze_vars_in_cols( - vars = "AVAL", - .stats = c( - "n", "mean", "sd", "cv", - "geom_mean", "geom_cv", "median", - "min", "max" - ), - .labels = c( - n = "n", - mean = "Mean", - sd = "SD", - cv = "CV (%)", - geom_mean = "Geometric Mean", - geom_cv = "CV % Geometric Mean", - median = "Median", - min = "Minimum", - max = "Maximum" - ), - .formats = c( - n = "xx.", - mean = threesigfmt, - sd = threesigfmt, - cv = "xx.x", - median = threesigfmt, - geom_mean = threesigfmt, - geom_cv = "xx.x", - min = threesigfmt, - max = threesigfmt - ) - ) - -# PKPT05 Drug X -testthat::test_that("PKPT05 Drug X is produced correctly", { - adpp0 <- adpp_urine %>% - filter(PPCAT == "XANOMELINE") %>% - dplyr::mutate(PKPARAM = factor(paste0(PPTEST, " (", AVALU, ")"))) - result <- build_table(l, df = adpp0) - main_title(result) <- paste("Summary of", unique(adpp0$PPSPEC), "PK Parameter by Treatment Arm, PK Population") - subtitles(result) <- paste("Analyte:", unique(adpp0$PPCAT), "\nVisit:", unique(adpp0$AVISIT)) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_pkpt06.R b/tests/testthat/test-table_pkpt06.R deleted file mode 100644 index e545bb94..00000000 --- a/tests/testthat/test-table_pkpt06.R +++ /dev/null @@ -1,62 +0,0 @@ -# Data generation -adpp <- adpp_raw -adpp_norm_dose <- adpp %>% dplyr::filter( - AVISIT == "CYCLE 1 DAY 1", - stringr::str_detect( - tolower(PARAM), - stringr::regex("norm by dose", ignore_case = TRUE) - ) -) - -# Define template layout -l <- basic_table() %>% - split_cols_by( - var = "ARMCD", - split_fun = trim_levels_in_group("ARMCD"), - # label_pos = "topleft", # nolint - split_label = "Treatment Arm" - ) %>% - split_rows_by( - var = "PKPARAM", - label_pos = "topleft", - split_label = "PK Parameter" - ) %>% - analyze_vars( - vars = "AVAL", - .stats = c("n", "mean_sd", "cv", "geom_mean", "geom_cv", "median", "range"), - .formats = c( - n = "xx.", - mean_sd = sprintf_format("%.3e (%.3e)"), - cv = "xx.x", - geom_mean = sprintf_format("%.3e"), - geom_cv = "xx.x", - median = sprintf_format("%.3e"), - range = sprintf_format("%.3e - %.3e") - ) - ) - -# PKPT06 Drug X -testthat::test_that("PKPT06 is produced correctly for Drug X", { - adpp0 <- adpp_norm_dose %>% - filter(PPCAT == "Plasma Drug X") %>% - h_pkparam_sort() %>% - mutate(PKPARAM = factor(paste0(TLG_DISPLAY, " (", AVALU, ")"))) - - result <- build_table(l, df = adpp0) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -# PKPT06 Drug Y -testthat::test_that("PKPT06 is produced correctly for Drug Y", { - adpp1 <- adpp_norm_dose %>% - filter(PPCAT == "Plasma Drug Y") %>% - h_pkparam_sort() %>% - mutate(PKPARAM = factor(paste0(TLG_DISPLAY, " (", AVALU, ")"))) - - result <- build_table(l, df = adpp1) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_pkpt07.R b/tests/testthat/test-table_pkpt07.R deleted file mode 100644 index 5bd58469..00000000 --- a/tests/testthat/test-table_pkpt07.R +++ /dev/null @@ -1,89 +0,0 @@ -# Data generation -adpp <- adpp_raw -adpp_norm_dose <- adpp %>% dplyr::filter( - AVISIT == "CYCLE 1 DAY 1", - stringr::str_detect( - tolower(PARAM), - stringr::regex("norm by dose", ignore_case = TRUE) - ) -) - -# Helper function -threesigfmt <- function(x, ...) { - as.character(signif(x, 3)) -} - -# Define template layout -l <- basic_table() %>% - split_rows_by( - var = "ARMCD", - split_fun = trim_levels_in_group("ARMCD"), - label_pos = "topleft", - split_label = "Treatment Arm" - ) %>% - split_rows_by( - var = "PKPARAM", - label_pos = "topleft", - split_label = "PK Parameter", - child_labels = "hidden" - ) %>% - analyze_vars_in_cols( - vars = "AVAL", - .stats = c( - "n", "mean", "sd", "cv", - "geom_mean", "geom_cv", "median", - "min", "max" - ), - .labels = c( - n = "n", - mean = "Mean", - sd = "SD", - cv = "CV (%)", - geom_mean = "Geometric Mean", - geom_cv = "CV % Geometric Mean", - median = "Median", - min = "Minimum", - max = "Maximum" - ), - .formats = c( - n = "xx.", - mean = threesigfmt, - sd = threesigfmt, - cv = "xx.x", - median = threesigfmt, - geom_mean = threesigfmt, - geom_cv = "xx.x", - min = threesigfmt, - max = threesigfmt - ) - ) - -# PKPT07 Drug X -testthat::test_that("PKPT07 Drug X is produced correctly", { - # Plasma Drug X__ - adpp0 <- adpp_norm_dose %>% - dplyr::filter(PPCAT == "Plasma Drug X") %>% - h_pkparam_sort() %>% - dplyr::mutate(PKPARAM = factor(paste0(TLG_DISPLAY, " (", AVALU, ")"))) - result <- build_table(l, df = adpp0) - main_title(result) <- paste("Summary of", unique(adpp0$PPSPEC), "PK Parameter by Treatment Arm, PK Population") - subtitles(result) <- paste("Analyte:", unique(adpp0$PPCAT), "\nVisit:", unique(adpp0$AVISIT)) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -# PKPT07 Drug Y -testthat::test_that("PKPT07 Drug Y is produced correctly", { - # Plasma Drug Y - adpp1 <- adpp_norm_dose %>% - dplyr::filter(PPCAT == "Plasma Drug Y") %>% - h_pkparam_sort() %>% - dplyr::mutate(PKPARAM = factor(paste0(TLG_DISPLAY, " (", AVALU, ")"))) - result <- build_table(l, df = adpp1) - main_title(result) <- paste("Summary of", unique(adpp1$PPSPEC), "PK Parameter by Treatment Arm, PK Population") - subtitles(result) <- paste("Analyte:", unique(adpp1$PPCAT), "\nVisit:", unique(adpp1$AVISIT)) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_ratet01.R b/tests/testthat/test-table_ratet01.R deleted file mode 100644 index 221463d0..00000000 --- a/tests/testthat/test-table_ratet01.R +++ /dev/null @@ -1,106 +0,0 @@ -anl <- adtte_raw %>% filter(PARAMCD == "TNE") - -# Ensure number of exacerbation is a factor and NAs are explicit missing levels. -anl$AVAL_f <- as.factor(anl$AVAL) -anl <- df_explicit_na(anl) - -testthat::test_that("RATET01 is produced correctly", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARM", - ref_group = "B: Placebo", - split_fun = ref_group_position("first") - ) %>% - analyze_vars( - "AVAL_f", - var_labels = "Number of exacerbations per patient", - .stats = c("count_fraction"), - .formats = c("count_fraction" = "xx (xx.xx%)"), - .labels = c("Number of exacerbations per patient") - ) %>% - summarize_glm_count( - vars = "AVAL", - variables = list(arm = "ARM", offset = "lgTMATRSK", covariates = NULL), - conf_level = 0.95, - distribution = "poisson", - rate_mean_method = "emmeans", - var_labels = "Unadjusted exacerbation rate (per year) with offset", - table_names = "unadj-offest", - .stats = c("rate"), - .labels = c(rate = "Rate") - ) %>% - summarize_glm_count( - vars = "AVAL", - variables = list(arm = "ARM", covariates = NULL), - conf_level = 0.95, - distribution = "poisson", - rate_mean_method = "emmeans", - var_labels = "Unadjusted exacerbation rate (per year)", - table_names = "unadj", - .stats = c("rate"), - .labels = c(rate = "Rate") - ) %>% - summarize_glm_count( - vars = "AVAL", - variables = list(arm = "ARM", offset = "lgTMATRSK", covariates = c("REGION1")), - conf_level = 0.95, - distribution = "quasipoisson", - rate_mean_method = "ppmeans", - var_labels = "Adjusted (QP) exacerbation rate (per year) with offset", - table_names = "adj-qp-offest", - .stats = c("rate", "rate_ci", "rate_ratio", "rate_ratio_ci", "pval"), - .labels = c( - rate = "Rate", rate_ci = "Rate CI", rate_ratio = "Rate Ratio", - rate_ratio_ci = "Rate Ratio CI", pval = "p-value" - ) - ) %>% - summarize_glm_count( - vars = "AVAL", - variables = list(arm = "ARM", covariates = c("REGION1")), - conf_level = 0.95, - distribution = "quasipoisson", - rate_mean_method = "emmeans", - var_labels = "Adjusted (QP) exacerbation rate (per year)", - table_names = "adj-qp", - .stats = c("rate", "rate_ci", "rate_ratio", "rate_ratio_ci", "pval"), - .labels = c( - rate = "Rate", rate_ci = "Rate CI", rate_ratio = "Rate Ratio", - rate_ratio_ci = "Rate Ratio CI", pval = "p-value" - ) - ) %>% - summarize_glm_count( - vars = "AVAL", - variables = list(arm = "ARM", offset = "lgTMATRSK", covariates = c("REGION1")), - conf_level = 0.95, - distribution = "negbin", - rate_mean_method = "emmeans", - var_labels = "Adjusted (NB) exacerbation rate (per year) with offset", - table_names = "adj-nb-offest", - .stats = c("rate", "rate_ci", "rate_ratio", "rate_ratio_ci", "pval"), - .labels = c( - rate = "Rate", rate_ci = "Rate CI", rate_ratio = "Rate Ratio", - rate_ratio_ci = "Rate Ratio CI", pval = "p-value" - ) - ) %>% - summarize_glm_count( - vars = "AVAL", - variables = list(arm = "ARM", covariates = c("REGION1")), - conf_level = 0.95, - distribution = "negbin", - rate_mean_method = "emmeans", - var_labels = "Adjusted (NB) exacerbation rate (per year)", - table_names = "adj-nb", - .stats = c("rate", "rate_ci", "rate_ratio", "rate_ratio_ci", "pval"), - .labels = c( - rate = "Rate", rate_ci = "Rate CI", rate_ratio = "Rate Ratio", - rate_ratio_ci = "Rate Ratio CI", pval = "p-value" - ) - ) - - result <- build_table( - lyt = lyt, - df = anl - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_rmpt01.R b/tests/testthat/test-table_rmpt01.R deleted file mode 100644 index e34a56eb..00000000 --- a/tests/testthat/test-table_rmpt01.R +++ /dev/null @@ -1,59 +0,0 @@ -adsl <- adsl_raw -adex <- adex_raw - -# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels. -adsl <- df_explicit_na(adsl) -adex <- df_explicit_na(adex) - -# Simulate ADEX records with PARAMCD == "TDURD" as they are not in sample scda dataset. -set.seed(1, kind = "Mersenne-Twister") -adex2 <- adex %>% - distinct(USUBJID, .keep_all = TRUE) %>% - mutate( - PARAMCD = "TDURD", - PARAM = "Overall duration (days)", - AVAL = sample(x = seq(1, 200), size = n(), replace = TRUE) - ) %>% - bind_rows(adex) - -# Now pre-processing steps are carried out. -anl <- adex2 %>% - filter( - PARAMCD == "TDURD", - PARCAT2 == "Drug A", - SAFFL == "Y" - ) %>% - mutate( - aval_months = day2month(AVAL), - aval_months_cat = factor(case_when( - aval_months < 1 ~ "< 1 month", - aval_months >= 1 & aval_months < 3 ~ "1 to <3 months", - aval_months >= 3 & aval_months < 6 ~ "3 to <6 months", - TRUE ~ ">=6 months" - ), levels = c("< 1 month", "1 to <3 months", "3 to <6 months", ">=6 months")) - ) - -adsl_f <- adsl %>% filter(adsl$SAFFL == "Y") - -testthat::test_that("RMPT01 is produced correctly", { - lyt <- basic_table( - title = "Duration of Exposure: Safety-Evaluable Patients", - main_footer = "* Patient Time is the sum of exposure across all patients in days.", - show_colcounts = TRUE - ) %>% - summarize_patients_exposure_in_cols( - var = "AVAL", col_split = TRUE, - .labels = c(n_patients = "Number of Patients", sum_exposure = "Patient Time*"), - custom_label = "Total Number of Patients and Patient Time" - ) %>% - analyze_patients_exposure_in_cols( - var = "aval_months_cat", - col_split = FALSE - ) %>% - append_topleft(c("", "Duration of exposure")) - - result <- build_table(lyt, df = anl, alt_counts_df = adsl_f) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_rmpt03.R b/tests/testthat/test-table_rmpt03.R deleted file mode 100644 index 967c2230..00000000 --- a/tests/testthat/test-table_rmpt03.R +++ /dev/null @@ -1,92 +0,0 @@ -adsl <- adsl_raw -adex <- adex_raw - -# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels. -adsl <- df_explicit_na(adsl) -adex <- df_explicit_na(adex) - -# Simulate ADEX records with PARAMCD == "TDURD" as they are not in sample scda dataset. -set.seed(1, kind = "Mersenne-Twister") -adex2 <- adex %>% - distinct(USUBJID, .keep_all = TRUE) %>% - mutate( - PARAMCD = "TDURD", - PARAM = "Overall duration (days)", - AVAL = sample(x = seq(1, 200), size = n(), replace = TRUE) - ) %>% - bind_rows(adex) - -# Now pre-processing steps are carried out. -anl <- adex2 %>% - filter( - PARAMCD == "TDURD", - PARCAT2 == "Drug A", - SAFFL == "Y" - ) %>% - mutate( - AGEGR1 = factor(ifelse(AGE < 65, "<65", ">=65")), - AGEGR2 = factor(case_when( - AGE < 18 ~ "< 18", - AGE >= 18 & AGE <= 40 ~ "18 - 40", - AGE > 40 & AGE <= 64 ~ "41 - 64", - TRUE ~ ">=65" - ), levels = c("< 18", "18 - 40", "41 - 64", ">=65")), - SEX = factor(case_when( - SEX == "F" ~ "Female", - SEX == "M" ~ "Male" - )) - ) - -adsl_f <- adsl %>% - filter(adsl$SAFFL == "Y") %>% - mutate(SEX = factor(case_when( - SEX == "F" ~ "Female", - SEX == "M" ~ "Male" - ))) - -testthat::test_that("RMPT03 variant 1 is produced correctly", { - lyt <- basic_table( - title = "Extent of Exposure by Age Group and Gender: Safety-Evaluable Patients", - main_footer = "* Patient Time is the sum of exposure across all patients in days." - ) %>% - split_cols_by("SEX", split_fun = add_overall_level("Total", first = FALSE)) %>% - summarize_patients_exposure_in_cols( - var = "AVAL", col_split = TRUE, - .labels = c(n_patients = "Number of Patients", sum_exposure = "Patient Time*"), - custom_label = "Total Number of Patients and Patient Time" - ) %>% - analyze_patients_exposure_in_cols( - var = "AGEGR1", - col_split = FALSE - ) %>% - append_topleft(c("", "Age group (years)")) - - result <- build_table(lyt, df = anl, alt_counts_df = adsl_f) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("RMPT03 variant 2 is produced correctly", { - lyt <- basic_table( - title = "Duration of Exposure: Safety-Evaluable Patients", - main_footer = "* Patient Time is the sum of exposure across all patients in days." - ) %>% - split_cols_by("SEX", split_fun = add_overall_level("Total", first = FALSE)) %>% - summarize_patients_exposure_in_cols( - var = "AVAL", col_split = TRUE, - .labels = c(n_patients = "Number of Patients", sum_exposure = "Patient Time*"), - custom_label = "Total Number of Patients and Patient Time" - ) %>% - analyze_patients_exposure_in_cols( - var = "AGEGR2", - col_split = FALSE - ) %>% - append_topleft(c("", "Age group (years)")) - - result <- build_table(lyt, df = anl, alt_counts_df = adsl_f) %>% - prune_table() - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_rmpt04.R b/tests/testthat/test-table_rmpt04.R deleted file mode 100644 index 5652a998..00000000 --- a/tests/testthat/test-table_rmpt04.R +++ /dev/null @@ -1,51 +0,0 @@ -adsl <- adsl_raw -adex <- adex_raw - -# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels. -adsl <- df_explicit_na(adsl) -adex <- df_explicit_na(adex) - -# Simulate ADEX records with PARAMCD == "TDURD" as they are not in sample scda dataset. -set.seed(1, kind = "Mersenne-Twister") -adex2 <- adex %>% - distinct(USUBJID, .keep_all = TRUE) %>% - mutate( - PARAMCD = "TDURD", - PARAM = "Overall duration (days)", - AVAL = sample(x = seq(1, 200), size = n(), replace = TRUE) - ) %>% - bind_rows(adex) - - -# Now pre-processing steps are carried out. -anl <- adex2 %>% - filter( - PARAMCD == "TDURD", - PARCAT2 == "Drug A", - SAFFL == "Y" - ) - -adsl_f <- adsl %>% filter(adsl$SAFFL == "Y") - -testthat::test_that("RMPT04 variant 1 is produced correctly", { - lyt <- basic_table( - title = "Extent of Exposure by Ethnic Origin: Safety-Evaluable Patients", - main_footer = "* Patient Time is the sum of exposure across all patients in days.", - show_colcounts = TRUE - ) %>% - summarize_patients_exposure_in_cols( - var = "AVAL", col_split = TRUE, - .labels = c(n_patients = "Number of Patients", sum_exposure = "Patient Time*"), - custom_label = "Total Number of Patients and Patient Time" - ) %>% - analyze_patients_exposure_in_cols( - var = "ETHNIC", - col_split = FALSE - ) %>% - append_topleft(c("", "Ethnicity")) - - result <- build_table(lyt, df = anl, alt_counts_df = adsl_f) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_rmpt05.R b/tests/testthat/test-table_rmpt05.R deleted file mode 100644 index ab08d483..00000000 --- a/tests/testthat/test-table_rmpt05.R +++ /dev/null @@ -1,50 +0,0 @@ -adsl <- adsl_raw -adex <- adex_raw - -# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels. -adsl <- df_explicit_na(adsl) -adex <- df_explicit_na(adex) - -# Simulate ADEX records with PARAMCD == "TDURD" as they are not in the sample dataset. -set.seed(1) -adex2 <- adex %>% - distinct(USUBJID, .keep_all = TRUE) %>% - mutate( - PARAMCD = "TDURD", - PARAM = "Overall duration (days)", - AVAL = sample(x = seq(1, 200), size = n(), replace = TRUE) - ) %>% - bind_rows(adex) - -# Now pre-processing steps are carried out. -anl <- adex2 %>% - filter( - PARAMCD == "TDURD", - PARCAT2 == "Drug A", - SAFFL == "Y" - ) %>% - mutate() - -adsl_f <- adsl %>% filter(adsl$SAFFL == "Y") - -testthat::test_that("RMPT05 is produced correctly", { - lyt <- basic_table( - title = "Extent of Exposure by Race: Safety-Evaluable Patients", - main_footer = "* Person time is the sum of exposure across all patients in unit: days.", - show_colcounts = TRUE - ) %>% - summarize_patients_exposure_in_cols( - var = "AVAL", col_split = TRUE, - .labels = c(n_patients = "Patients", sum_exposure = "Person time*") - ) %>% - analyze_patients_exposure_in_cols( - var = "RACE", - col_split = FALSE - ) %>% - append_topleft(c("", obj_label(adex$RACE))) - - result <- build_table(lyt, df = anl, alt_counts_df = adsl_f) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_rmpt06.R b/tests/testthat/test-table_rmpt06.R deleted file mode 100644 index 6ef800a9..00000000 --- a/tests/testthat/test-table_rmpt06.R +++ /dev/null @@ -1,278 +0,0 @@ -adsl <- adsl_raw -adae <- adae_raw - -adsl <- df_explicit_na(adsl) -adae <- df_explicit_na( - adae, - omit_columns = c("SMQ01NAM", "SMQ01SC", "SMQ02NAM", "SMQ02SC", "CQ01NAM", "STUDYID", "USUBJID") -) - -df_max <- aggregate(as.numeric(AETOXGR) ~ USUBJID, data = adae, FUN = max, drop = FALSE) -colnames(df_max) <- c("USUBJID", "WTOXGR") - -adae <- adae %>% - left_join(df_max, by = c("USUBJID")) %>% - mutate( - WTOXGR = factor(WTOXGR, levels = c("1", "2", "3", "4", "5")), - fl_ser = AESER == "Y" - ) %>% - mutate( - WTOXGR = forcats::fct_recode( - WTOXGR, - "Grade 1" = "1", - "Grade 2" = "2", - "Grade 3" = "3", - "Grade 4" = "4", - "Grade 5" = "5" - ), - AEOUT = forcats::fct_recode( - AEOUT, - "Fatal outcome" = "FATAL", - "Unresolved" = "NOT RECOVERED/NOT RESOLVED", - "Recovered/Resolved" = "RECOVERED/RESOLVED", - "Resolved with sequelae" = "RECOVERED/RESOLVED WITH SEQUELAE", - "Recovering/Resolving" = "RECOVERING/RESOLVING", - "Unknown outcome" = "UNKNOWN" - ) - ) %>% - var_relabel( - WTOXGR = "Worst overall grade", - fl_ser = "Number of patients with at least one serious AE" - ) - -# Add AE flag to adsl. -adsl1 <- adsl %>% - mutate(AEFL = ifelse(USUBJID %in% adae$USUBJID, TRUE, FALSE)) %>% - var_relabel(AEFL = "At least one AE") - -testthat::test_that("RMPT06 variant 1 is produced correctly", { - lyt_adsl <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - estimate_proportion( - vars = "AEFL", - method = "clopper-pearson", - .labels = c( - n_prop = "Number of patients with at least one adverse event", - prop_ci = "95% CI for % of patients with at least one AE (Clopper-Pearson)" - ), - table_names = "est_prop" - ) - - result_adsl <- build_table(lyt_adsl, df = adsl1, alt_counts_df = adsl1) - - # Layout for variables from adae dataset. - lyt_adae <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - count_values( - "STUDYID", - values = as.character(unique(adae$STUDYID)), - .stats = "count", - .labels = c(count = "Total number of AEs"), - table_names = "total_aes" - ) %>% - count_occurrences( - "WTOXGR", - var_labels = "Number of patients with at least one AE by worst grade", - show_labels = "visible" - ) %>% - count_patients_with_flags( - "USUBJID", - flag_variables = "fl_ser" - ) %>% - count_occurrences( - "AEOUT", - denom = "n", - var_labels = "Number of patients with at least one AE by outcome", - show_labels = "visible" - ) - - result_adae <- build_table(lyt_adae, df = adae, alt_counts_df = adsl) - - # Combine tables. - col_info(result_adsl) <- col_info(result_adae) - result <- rbind( - result_adsl, - result_adae[seq_len(nrow(result_adae)), ] - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("RMPT06 variant 2 is produced correctly", { - lyt_adsl <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - estimate_proportion( - vars = "AEFL", - method = "clopper-pearson", - .labels = c( - n_prop = "Number of patients with at least one adverse event", - prop_ci = "95% CI for % of patients with at least one AE (Clopper-Pearson)" - ), - table_names = "est_prop" - ) - - result_adsl <- build_table(lyt_adsl, df = adsl1, alt_counts_df = adsl1) - - # Layout for variables from adae dataset. - lyt_adae <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - count_values( - "STUDYID", - values = as.character(unique(adae$STUDYID)), - .stats = "count", - .labels = c(count = "Total number of AEs"), - table_names = "total_aes" - ) %>% - count_occurrences( - "WTOXGR", - var_labels = "Number of patients with at least one AE by worst grade", - show_labels = "visible" - ) %>% - count_patients_with_flags( - "USUBJID", - flag_variables = "fl_ser", - denom = "N_col" - ) - - result_adae <- build_table(lyt_adae, df = adae, alt_counts_df = adsl) - - # Combine tables. - col_info(result_adsl) <- col_info(result_adae) - result <- rbind( - result_adsl, - result_adae[seq_len(nrow(result_adae)), ] - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("RMPT06 variant 3 is produced correctly", { - lyt_adsl <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% - estimate_proportion( - vars = "AEFL", - method = "clopper-pearson", - .labels = c( - n_prop = "Number of patients with at least one adverse event", - prop_ci = "95% CI for % of patients with at least one AE" - ), - table_names = "est_prop" - ) %>% - estimate_proportion_diff( - vars = "AEFL", - .labels = c( - diff = "Difference in % of patients with at least one AE", - diff_ci = "95% CI of difference (Wald, with correction)" - ), - table_names = "est_prop_diff" - ) - - result_adsl <- build_table(lyt_adsl, df = adsl1, alt_counts_df = adsl1) - - # Layout for variables from adae dataset. - lyt_adae <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - count_values( - "STUDYID", - values = as.character(unique(adae$STUDYID)), - .stats = "count", - .labels = c(count = "Total number of AEs"), - table_names = "total_aes" - ) %>% - count_occurrences( - "WTOXGR", - var_labels = "Number of patients with at least one AE by worst grade", - show_labels = "visible" - ) %>% - count_patients_with_flags( - "USUBJID", - flag_variables = "fl_ser", - denom = "N_col" - ) %>% - count_occurrences( - "AEOUT", - denom = "n", - var_labels = "Number of patients with at least one AE by outcome", - show_labels = "visible" - ) - - result_adae <- build_table(lyt_adae, df = adae, alt_counts_df = adsl) - - # Combine tables. - col_info(result_adsl) <- col_info(result_adae) - result <- rbind( - result_adsl, - result_adae[seq_len(nrow(result_adae)), ] - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("RMPT06 variant 4 is produced correctly", { - lyt_adsl <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% - estimate_proportion( - vars = "AEFL", - conf_level = 0.90, - method = "clopper-pearson", - .labels = c( - n_prop = "Number of patients with at least one adverse event", - prop_ci = "90% CI for % of patients with at least one AE (Clopper-Pearson)" - ), - table_names = "est_prop" - ) %>% - estimate_proportion_diff( - vars = "AEFL", - conf_level = 0.90, - method = "newcombe", - .labels = c( - diff = "Difference in % of patients with at least one AE", - diff_ci = "90% CI of difference (Newcombe)" - ), - table_names = "est_prop_diff" - ) - - result_adsl <- build_table(lyt_adsl, df = adsl1, alt_counts_df = adsl1) - - # Layout for variables from adae dataset. - lyt_adae <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - count_values( - "STUDYID", - values = as.character(unique(adae$STUDYID)), - .stats = "count", - .labels = c(count = "Total number of AEs"), - table_names = "total_aes" - ) %>% - count_occurrences( - "WTOXGR", - var_labels = "Number of patients with at least one AE by worst grade", - show_labels = "visible" - ) %>% - count_patients_with_flags( - "USUBJID", - flag_variables = "fl_ser", - denom = "N_col" - ) %>% - count_occurrences( - "AEOUT", - denom = "n", - var_labels = "Number of patients with at least one AE by outcome", - show_labels = "visible" - ) - - result_adae <- build_table(lyt_adae, df = adae, alt_counts_df = adsl) - - # Combine tables. - col_info(result_adsl) <- col_info(result_adae) - result <- rbind( - result_adsl, - result_adae[seq_len(nrow(result_adae)), ] - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_rspt01.R b/tests/testthat/test-table_rspt01.R deleted file mode 100644 index cba22128..00000000 --- a/tests/testthat/test-table_rspt01.R +++ /dev/null @@ -1,253 +0,0 @@ -# Preparation of the test case. -adrs <- adrs_raw - -# Select a response parameter endpoint. -adrs <- adrs %>% dplyr::filter(PARAMCD == "INVET") - -# Recode multinomial response with standard oncology labels. -levels(adrs$AVALC) <- d_onco_rsp_label(levels(adrs$AVALC)) - -# Response variable. -adrs <- adrs %>% - dplyr::select(ARMCD, AVALC, SEX, STRATA1, STRATA2) %>% - dplyr::mutate( - is_rsp = AVALC %in% c("Complete Response (CR)", "Partial Response (PR)"), - STRATA1 = factor(STRATA1) - ) - -testthat::test_that("RSPT01: 1. Best Overall Response", { - l <- basic_table() %>% - split_cols_by(var = "ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% - add_colcounts() %>% - estimate_proportion( - vars = "is_rsp", - table_names = "prop_est" - ) %>% - estimate_proportion_diff( - vars = "is_rsp", - show_labels = "visible", - var_labels = "Unstratified Analysis", - table_names = "prop_diff" - ) %>% - test_proportion_diff( - vars = "is_rsp", - method = "schouten", - table_names = "test_diff" - ) %>% - estimate_odds_ratio( - vars = "is_rsp", - table_names = "est_or" - ) %>% - estimate_multinomial_response(var = "AVALC") - - result <- build_table(l, adrs) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("RSPT01: 2. Best Overall Response (selecting sections to display)", { - l <- basic_table() %>% - split_cols_by(var = "ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% - add_colcounts() %>% - estimate_proportion( - vars = "is_rsp", - table_names = "prop_est" - ) %>% - estimate_proportion_diff( - vars = "is_rsp", - show_labels = "visible", - var_labels = "Unstratified Analysis", - table_names = "prop_diff" - ) %>% - test_proportion_diff( - vars = "is_rsp", - method = "schouten", - table_names = "test_diff" - ) %>% - estimate_multinomial_response(var = "AVALC") - - result <- build_table(l, adrs) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("RSPT01: 3. Best Overall Response (modifying settings)", { - conf_level <- 0.90 - method_prop <- "clopper-pearson" - l <- basic_table() %>% - split_cols_by(var = "ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% - add_colcounts() %>% - estimate_proportion( - vars = "is_rsp", - method = method_prop, - conf_level = conf_level, - table_names = "prop_est" - ) %>% - estimate_proportion_diff( - vars = "is_rsp", - show_labels = "visible", - var_labels = "Unstratified Analysis", - method = "ha", - conf_level = conf_level, - table_names = "prop_diff" - ) %>% - test_proportion_diff( - vars = "is_rsp", - method = "fisher", - table_names = "test_diff" - ) %>% - estimate_odds_ratio( - vars = "is_rsp", - conf_level = conf_level, - table_names = "est_or" - ) %>% - estimate_multinomial_response( - var = "AVALC", - method = method_prop, - conf_level = conf_level - ) - - result <- build_table(l, adrs) - result <- result[-nrow(result), ] - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("RSPT01: 4. Best Overall Response (with stratified analysis)", { - l <- basic_table() %>% - split_cols_by(var = "ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% - add_colcounts() %>% - estimate_proportion( - vars = "is_rsp", - table_names = "prop_est" - ) %>% - estimate_proportion_diff( - vars = "is_rsp", - show_labels = "visible", - var_labels = "Unstratified Analysis", - table_names = "prop_diff" - ) %>% - test_proportion_diff( - vars = "is_rsp", - method = "schouten", - table_names = "test_diff" - ) %>% - estimate_odds_ratio( - vars = "is_rsp", - table_names = "est_or" - ) %>% - estimate_proportion_diff( - vars = "is_rsp", - show_labels = "visible", - variables = list(strata = "STRATA1"), - method = "cmh", - var_labels = "Stratified Analysis", - table_names = "prop_diff_strat" - ) %>% - test_proportion_diff( - vars = "is_rsp", - method = "cmh", - variables = list(strata = "STRATA1"), - table_names = "test_diff_strat" - ) %>% - estimate_odds_ratio( - vars = "is_rsp", - variables = list(arm = "ARMCD", strata = "STRATA1"), - table_names = "est_or_strat" - ) %>% - estimate_multinomial_response(var = "AVALC") - - # https://github.com/therneau/survival/issues/240 - withr::with_options( - opts_partial_match_old, - result <- build_table(l, adrs) - ) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("RSPT01: 5. Best Overall Response (modifying the definition of overall response)", { - l <- basic_table() %>% - split_cols_by(var = "ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% - add_colcounts() %>% - estimate_proportion( - vars = "is_rsp", - table_names = "prop_est" - ) %>% - estimate_proportion_diff( - vars = "is_rsp", - show_labels = "visible", - var_labels = "Unstratified Analysis", - table_names = "prop_diff" - ) %>% - test_proportion_diff( - vars = "is_rsp", - method = "schouten", - table_names = "test_diff" - ) %>% - estimate_odds_ratio( - vars = "is_rsp", - table_names = "est_or" - ) %>% - estimate_multinomial_response(var = "AVALC") - - adrs$is_rsp <- adrs$AVALC == "Complete Response (CR)" - result <- build_table(l, adrs) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - - -testthat::test_that("RSPT01: 6. Best Overall Response (define new sections to display)", { - # Define study-specific response category "No Progression". - adrs <- adrs %>% - dplyr::mutate( - AVALC_NEW = dplyr::case_when( - AVALC %in% c( - "Complete Response (CR)", "Partial Response (PR)", - "Stable Disease (SD)" - ) ~ "No Progression", - TRUE ~ as.character(AVALC) - ) - ) %>% - dplyr::mutate( - AVALC_NEW = factor( - AVALC_NEW, - levels = c("No Progression", "Progressive Disease (PD)", "Not Evaluable (NE)") - ) - ) - - l <- basic_table() %>% - split_cols_by(var = "ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% - add_colcounts() %>% - estimate_proportion( - vars = "is_rsp", - table_names = "prop_est" - ) %>% - estimate_proportion_diff( - vars = "is_rsp", - show_labels = "visible", - var_labels = "Unstratified Analysis", - table_names = "prop_diff" - ) %>% - test_proportion_diff( - vars = "is_rsp", - method = "schouten", - table_names = "test_diff" - ) %>% - estimate_odds_ratio( - vars = "is_rsp", - table_names = "est_or" - ) %>% - estimate_multinomial_response(var = "AVALC_NEW") - - result <- build_table(l, adrs) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_ttet01.R b/tests/testthat/test-table_ttet01.R deleted file mode 100644 index 89bb7724..00000000 --- a/tests/testthat/test-table_ttet01.R +++ /dev/null @@ -1,441 +0,0 @@ -# Tests the variants for TTET01. - -preproc_adtte <- function(adtte) { - anl <- adtte %>% - dplyr::filter(PARAMCD == "OS") %>% - dplyr::mutate( - AVAL = day2month(AVAL), - is_event = CNSR == 0, - is_not_event = CNSR == 1, - EVNT1 = factor( - dplyr::case_when( - is_event == TRUE ~ "Patients with event (%)", - is_event == FALSE ~ "Patients without event (%)" - ), - levels = c("Patients with event (%)", "Patients without event (%)") - ), - EVNTDESC = factor(EVNTDESC) - ) - anl -} - -adsl <- adsl_raw -adtte <- adtte_raw - -testthat::test_that("TTET01 default variant is produced correctly", { - adtte <- adtte %>% - preproc_adtte() - - l <- basic_table() %>% - split_cols_by("ARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% - add_colcounts() %>% - analyze_vars( - vars = "is_event", - .stats = "count_fraction", - .labels = c(count_fraction = "Patients with event (%)") - ) %>% - split_rows_by( - "EVNT1", - split_label = "Earliest contributing event", - split_fun = keep_split_levels("Patients with event (%)"), - label_pos = "visible", - child_labels = "hidden", - indent_mod = 1L, - ) %>% - split_rows_by("EVNTDESC", split_fun = drop_split_levels) %>% - summarize_row_groups(format = "xx") %>% - analyze_vars( - vars = "is_not_event", - .stats = "count_fraction", - .labels = c(count_fraction = "Patients without event (%)"), - nested = FALSE, - show_labels = "hidden" - ) %>% - surv_time( - vars = "AVAL", - var_labels = "Time to Event (Months)", - is_event = "is_event", - table_names = "time_to_event" - ) %>% - coxph_pairwise( - vars = "AVAL", - is_event = "is_event", - var_labels = c("Unstratified Analysis"), - control = control_coxph(pval_method = "log-rank"), - table_names = "coxph_unstratified" - ) %>% - surv_timepoint( - vars = "AVAL", - var_labels = "Months", - time_point = c(6, 12), - is_event = "is_event", - method = "both", - control = control_surv_timepoint() - ) - - result <- build_table(l, df = adtte, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - - -testthat::test_that("TTET01 default variant with Placebo arm", { - adtte <- adtte %>% - preproc_adtte() - - l <- basic_table() %>% - split_cols_by("ARM", - ref_group = "B: Placebo", - split_fun = ref_group_position("last") - ) %>% - add_colcounts() %>% - analyze_vars( - vars = "is_event", - .stats = "count_fraction", - .labels = c(count_fraction = "Patients with event (%)") - ) %>% - split_rows_by( - "EVNT1", - split_label = "Earliest contributing event", - split_fun = keep_split_levels("Patients with event (%)"), - label_pos = "visible", - child_labels = "hidden", - indent_mod = 1L, - ) %>% - split_rows_by("EVNTDESC", split_fun = drop_split_levels) %>% - summarize_row_groups(format = "xx") %>% - analyze_vars( - vars = "is_not_event", - .stats = "count_fraction", - .labels = c(count_fraction = "Patients without event (%)"), - nested = FALSE, - show_labels = "hidden" - ) %>% - surv_time( - vars = "AVAL", - var_labels = "Time to Event (Months)", - is_event = "is_event", - table_names = "time_to_event" - ) %>% - coxph_pairwise( - vars = "AVAL", - is_event = "is_event", - var_labels = c("Unstratified Analysis"), - control = control_coxph(pval_method = "log-rank"), - table_names = "coxph_unstratified" - ) %>% - surv_timepoint( - vars = "AVAL", - var_labels = "Months", - time_point = c(6, 12), - is_event = "is_event", - method = "both", - control = control_surv_timepoint() - ) - - result <- build_table(l, df = adtte, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("TTET01 variant 2: selecting sections to display", { - adtte <- adtte %>% - preproc_adtte() - - l <- basic_table() %>% - split_cols_by("ARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% - add_colcounts() %>% - analyze_vars( - vars = "is_event", - .stats = "count_fraction", - .labels = c(count_fraction = "Patients with event (%)") - ) %>% - analyze_vars( - "is_not_event", - .stats = "count_fraction", - .labels = c(count_fraction = "Patients without event (%)"), - nested = FALSE, - show_labels = "hidden" - ) %>% - surv_time( - vars = "AVAL", - var_labels = "Time to Event (Months)", - is_event = "is_event", - table_names = "time_to_event" - ) %>% - coxph_pairwise( - vars = "AVAL", - is_event = "is_event", - var_labels = c("Unstratified Analysis"), - control = control_coxph(pval_method = "log-rank"), - table_names = "coxph_unstratified" - ) %>% - surv_timepoint( - vars = "AVAL", - var_labels = "Months", - is_event = "is_event", - method = "surv", - time_point = c(12) - ) - result <- build_table(l, df = adtte, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("TTET01 variant 3: modifying analysis details like conftype, ties, alpha level", { - adtte <- adtte %>% - preproc_adtte() - - l <- basic_table() %>% - split_cols_by("ARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% - add_colcounts() %>% - analyze_vars( - vars = "is_event", - .stats = "count_fraction", - .labels = c(count_fraction = "Patients with event (%)") - ) %>% - split_rows_by( - "EVNT1", - split_label = "Earliest contributing event", - split_fun = keep_split_levels("Patients with event (%)"), - label_pos = "visible", - child_labels = "hidden", - indent_mod = 1L, - ) %>% - split_rows_by("EVNTDESC", split_fun = drop_split_levels) %>% - summarize_row_groups(format = "xx") %>% - analyze_vars( - vars = "is_not_event", - .stats = "count_fraction", - .labels = c(count_fraction = "Patients without event (%)"), - nested = FALSE, - show_labels = "hidden" - ) %>% - surv_time( - vars = "AVAL", - var_labels = "Time to Event (Months)", - is_event = "is_event", - control = control_surv_time(conf_level = 0.9, conf_type = "log-log"), - table_names = "time_to_event" - ) %>% - coxph_pairwise( - vars = "AVAL", - is_event = "is_event", - var_labels = c("Unstratified Analysis"), - control = control_coxph(pval_method = "log-rank", conf_level = 0.95, ties = "efron"), - table_names = "coxph_unstratified" - ) %>% - surv_timepoint( - vars = "AVAL", - var_labels = "Months", - is_event = "is_event", - time_point = 12, - control = control_surv_timepoint(conf_level = 0.9, conf_type = "log-log"), - table_names_suffix = "_log_log" - ) %>% - surv_timepoint( - vars = "AVAL", - show_labels = "hidden", - is_event = "is_event", - time_point = 12, - method = "surv_diff", - control = control_surv_timepoint(conf_level = 0.975), - table_names_suffix = "_975_pct" - ) - result <- build_table(l, df = adtte, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("TTET01 variant 4: with stratified analysis", { - adtte <- adtte %>% - preproc_adtte() - - l <- basic_table() %>% - split_cols_by("ARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% - add_colcounts() %>% - analyze_vars( - vars = "is_event", - .stats = "count_fraction", - .labels = c(count_fraction = "Patients with event (%)") - ) %>% - split_rows_by( - "EVNT1", - split_label = "Earliest contributing event", - split_fun = keep_split_levels("Patients with event (%)"), - label_pos = "visible", - child_labels = "hidden", - indent_mod = 1L, - ) %>% - split_rows_by("EVNTDESC", split_fun = drop_split_levels) %>% - summarize_row_groups(format = "xx") %>% - analyze_vars( - vars = "is_not_event", - .stats = "count_fraction", - .labels = c(count_fraction = "Patients without event (%)"), - nested = FALSE, - show_labels = "hidden" - ) %>% - surv_time( - vars = "AVAL", - var_labels = "Time to Event (Months)", - is_event = "is_event", - table_names = "time_to_event" - ) %>% - coxph_pairwise( - vars = "AVAL", - is_event = "is_event", - var_labels = "Unstratified Analysis", - table_names = "coxph_unstratified" - ) %>% - coxph_pairwise( - vars = "AVAL", - is_event = "is_event", - var_labels = "Stratified Analysis", - strata = "SEX", - table_names = "coxph_stratified" - ) %>% - surv_timepoint( - vars = "AVAL", - var_labels = "Months", - is_event = "is_event", - method = "both", - time_point = 12 - ) - result <- build_table(l, df = adtte, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("TTET01 variant 5: modifying time point", { - adtte <- adtte %>% - preproc_adtte() - - l <- basic_table() %>% - split_cols_by("ARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% - add_colcounts() %>% - analyze_vars( - vars = "is_event", - .stats = "count_fraction", - .labels = c(count_fraction = "Patients with event (%)") - ) %>% - split_rows_by( - "EVNT1", - split_label = "Earliest contributing event", - split_fun = keep_split_levels("Patients with event (%)"), - label_pos = "visible", - child_labels = "hidden", - indent_mod = 1L, - ) %>% - split_rows_by("EVNTDESC", split_fun = drop_split_levels) %>% - summarize_row_groups(format = "xx") %>% - analyze_vars( - vars = "is_not_event", - .stats = "count_fraction", - .labels = c(count_fraction = "Patients without event (%)"), - nested = FALSE, - show_labels = "hidden" - ) %>% - surv_time( - vars = "AVAL", - var_labels = "Time to Event (Months)", - is_event = "is_event", - table_names = "time_to_event" - ) %>% - coxph_pairwise( - vars = "AVAL", - is_event = "is_event", - var_labels = c("Unstratified Analysis"), - control = control_coxph(pval_method = "log-rank"), - table_names = "coxph_unstratified" - ) %>% - surv_timepoint( - vars = "AVAL", - var_labels = "Months", - is_event = "is_event", - time_point = 6, - method = "both" - ) - result <- build_table(l, df = adtte, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("TTET01 variant 6: requesting more than one p-value", { - adtte <- adtte %>% - preproc_adtte() - - l <- basic_table() %>% - split_cols_by("ARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% - add_colcounts() %>% - analyze_vars( - vars = "is_event", - .stats = "count_fraction", - .labels = c(count_fraction = "Patients with event (%)") - ) %>% - split_rows_by( - "EVNT1", - split_label = "Earliest contributing event", - split_fun = keep_split_levels("Patients with event (%)"), - label_pos = "visible", - child_labels = "hidden", - indent_mod = 1L, - ) %>% - split_rows_by("EVNTDESC", split_fun = drop_split_levels) %>% - summarize_row_groups(format = "xx") %>% - analyze_vars( - vars = "is_not_event", - .stats = "count_fraction", - .labels = c(count_fraction = "Patients without event (%)"), - nested = FALSE, - show_labels = "hidden" - ) %>% - surv_time( - vars = "AVAL", - var_labels = "Time to Event (Months)", - is_event = "is_event", - table_names = "time_to_event" - ) %>% - coxph_pairwise( - vars = "AVAL", - is_event = "is_event", - var_labels = c("Unstratified Analysis"), - control = control_coxph(pval_method = "log-rank"), - .stats = "pvalue", - table_names = "coxph_unstratified" - ) %>% - coxph_pairwise( - vars = "AVAL", - is_event = "is_event", - show_labels = "hidden", - control = control_coxph(pval_method = "wald"), - .stats = "pvalue", - .indent_mods = c(pvalue = 1L), - table_names = "coxph_wald_pvalue" - ) %>% - coxph_pairwise( - vars = "AVAL", - is_event = "is_event", - show_labels = "hidden", - control = control_coxph(pval_method = "likelihood"), - .indent_mods = c(pvalue = 1L, hr = 2L, hr_ci = 3L), - table_names = "coxph_likelihood_pvalue" - ) %>% - surv_timepoint( - vars = "AVAL", - var_labels = "Months", - is_event = "is_event", - time_point = 12, - method = "both" - ) - result <- build_table(l, df = adtte, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_vst01.R b/tests/testthat/test-table_vst01.R deleted file mode 100644 index 0281ea8c..00000000 --- a/tests/testthat/test-table_vst01.R +++ /dev/null @@ -1,101 +0,0 @@ -# Test the single variant for VST01 - -adsl <- adsl_pharmaverse -advs <- advs_pharmaverse - -adsl <- df_explicit_na(adsl) -advs <- df_explicit_na(advs) - -advs_label <- var_labels(advs) - -advs <- advs %>% - filter(PARAMCD == "DIABP") %>% - mutate( - PARAMCD = droplevels(PARAMCD), - PARAM = droplevels(PARAM) - ) - -advs_pb <- advs %>% - filter(ABLFL != "Y") - -advs_pb_max <- advs_pb %>% - group_by(PARAM, USUBJID) %>% - arrange(desc(AVAL)) %>% - slice(1) %>% - ungroup() %>% - mutate(AVISIT = "Post-Baseline Maximum") - -advs_pb_min <- advs_pb %>% - group_by(PARAM, USUBJID) %>% - arrange(AVAL) %>% - slice(1) %>% - ungroup() %>% - mutate(AVISIT = "Post-Baseline Minimum") - -advs_pb_last <- advs_pb %>% - group_by(PARAM, USUBJID) %>% - arrange(desc(AVISITN)) %>% - slice(1) %>% - ungroup() %>% - mutate(AVISIT = "Post-Baseline Last") - -advs_f <- rbind( - advs, - advs_pb_last, - advs_pb_min, - advs_pb_max -) - -advs_f <- advs_f %>% - mutate(AVISIT = droplevels(AVISIT)) -levels(advs_f$AVISIT) <- c( - "Baseline", "Week 2", "Week 4", "Week 6", "Week 8", "Week 12", "Week 16", "Week 20", "Week 24", "Week 26", - "End of Treatment", "Post-Baseline Minimum", "Post-Baseline Maximum", "Post-Baseline Last", "" -) - -var_labels(advs_f) <- advs_label - -testthat::test_that("VST01 default variant is produced correctly", { - skip_if_too_deep(3) - - split_fun <- drop_split_levels - - afun <- function(x, .var, .spl_context, ...) { - n_fun <- sum(!is.na(x), na.rm = TRUE) - if (n_fun == 0) { - mean_sd_fun <- c(NA, NA) - median_fun <- NA - min_max_fun <- c(NA, NA) - } else { - mean_sd_fun <- c(mean(x, na.rm = TRUE), sd(x, na.rm = TRUE)) - median_fun <- median(x, na.rm = TRUE) - min_max_fun <- c(min(x), max(x)) - } - is_chg <- .var == "CHG" - is_baseline <- .spl_context$value[which(.spl_context$split == "AVISIT")] == "BASELINE" - if (is_baseline && is_chg) n_fun <- mean_sd_fun <- median_fun <- min_max_fun <- NULL - - in_rows( - "n" = n_fun, - "Mean (SD)" = mean_sd_fun, - "Median" = median_fun, - "Min - Max" = min_max_fun, - .formats = list("n" = "xx", "Mean (SD)" = "xx.xx (xx.xx)", "Median" = "xx.xx", "Min - Max" = "xx.xx - xx.xx"), - .format_na_strs = list("n" = "NE", "Mean (SD)" = "NE (NE)", "Median" = "NE", "Min - Max" = "NE - NE") - ) - } - - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM") %>% - split_rows_by("AVISIT", split_fun = split_fun, label_pos = "topleft", split_label = "\n\nAnalysis Visit") %>% - split_cols_by_multivar( - vars = c("AVAL", "CHG"), - varlabels = c("Value at Visit", "Change from\nBaseline") - ) %>% - analyze_colvars(afun = afun) - - result <- build_table(lyt = lyt, df = advs_f, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) diff --git a/tests/testthat/test-table_vst02.R b/tests/testthat/test-table_vst02.R deleted file mode 100644 index 30de36dc..00000000 --- a/tests/testthat/test-table_vst02.R +++ /dev/null @@ -1,52 +0,0 @@ -# Test the single variant for VST02 - -adsl <- adsl_pharmaverse -advs <- advs_pharmaverse - -adsl <- df_explicit_na(adsl) -advs <- df_explicit_na(advs) - -advs_f <- advs %>% - filter(ONTRTFL == "Y", ANRIND != "") %>% - var_relabel( - PARAM = "Assessment", - ANRIND = "Abnormality" - ) - -split_fun <- drop_split_levels - -testthat::test_that("1. Vital Sign Abnormalities (Regardless of Abnormality at Baseline, VST02_1)", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ACTARM") %>% - add_overall_col("All Patients") %>% - split_rows_by("PARAM", split_fun = split_fun, label_pos = "topleft", split_label = obj_label(advs_f$PARAM)) %>% - count_abnormal( - "ANRIND", - abnormal = list(Low = c("LOW", "LOW LOW"), High = c("HIGH", "HIGH HIGH")), - exclude_base_abn = FALSE - ) %>% - append_varlabels(advs_f, "ANRIND", indent = 1L) - - result <- build_table(lyt = lyt, df = advs_f, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) - -testthat::test_that("2. Vital Sign Abnormalities (Among Subject Without Abnormality at Baseline, VST02_2)", { - lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ACTARM") %>% - add_overall_col("All Patients") %>% - split_rows_by("PARAM", split_fun = split_fun, label_pos = "topleft", split_label = obj_label(advs_f$PARAM)) %>% - count_abnormal( - "ANRIND", - abnormal = list(Low = c("LOW", "LOW LOW"), High = c("HIGH", "HIGH HIGH")), - exclude_base_abn = TRUE - ) %>% - append_varlabels(advs_f, "ANRIND", indent = 1L) - - result <- build_table(lyt = lyt, df = advs_f, alt_counts_df = adsl) - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -}) From e2f93e168b6ed5331f00d5213dcdf778c995f5d6 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 5 Mar 2026 10:40:47 +0000 Subject: [PATCH 5/5] [skip style] [skip vbump] Restyle files --- tests/testthat/source_code/tsidem01.R | 15 +++++++++------ tests/testthat/source_code/tsids01.R | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/testthat/source_code/tsidem01.R b/tests/testthat/source_code/tsidem01.R index bb9ce26b..b3fd519d 100644 --- a/tests/testthat/source_code/tsidem01.R +++ b/tests/testthat/source_code/tsidem01.R @@ -232,8 +232,9 @@ lyt <- basic_table( .stats = c("n", "mean_sd", "median", "range", "count_fraction"), .labels = c("n" = "N", "range" = "Min, max"), .formats = c(P1_precision, - n = jjcsformat_xx("xx"), - "count_fraction" = jjcsformat_count_fraction), + n = jjcsformat_xx("xx"), + "count_fraction" = jjcsformat_count_fraction + ), .indent_mods = c( "n" = 0L, "mean_sd" = 1L, @@ -265,8 +266,9 @@ lyt <- basic_table( .stats = c("n", "mean_sd", "median", "range", "count_fraction"), .labels = c("n" = "N", "range" = "Min, max"), .formats = c(P2a_precision, - n = jjcsformat_xx("xx"), - "count_fraction" = jjcsformat_count_fraction), + n = jjcsformat_xx("xx"), + "count_fraction" = jjcsformat_count_fraction + ), .indent_mods = c( "n" = 0L, "mean_sd" = 1L, @@ -285,8 +287,9 @@ lyt <- basic_table( .stats = c("n", "mean_sd", "median", "range", "count_fraction"), .labels = c("n" = "N", "range" = "Min, max"), .formats = c(P2b_precision, - n = jjcsformat_xx("xx"), - "count_fraction" = jjcsformat_count_fraction), + n = jjcsformat_xx("xx"), + "count_fraction" = jjcsformat_count_fraction + ), .indent_mods = c( "n" = 0L, "mean_sd" = 1L, diff --git a/tests/testthat/source_code/tsids01.R b/tests/testthat/source_code/tsids01.R index 8b649cbc..0a3f2cb0 100644 --- a/tests/testthat/source_code/tsids01.R +++ b/tests/testthat/source_code/tsids01.R @@ -24,7 +24,7 @@ ############################################################################### library(envsetup) -#library(tern) +# library(tern) library(dplyr) library(rtables) library(junco)