Skip to content

Commit

Permalink
adding tests (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
shajoezhu authored Dec 1, 2024
1 parent 1606c2e commit 6cab16a
Show file tree
Hide file tree
Showing 9 changed files with 353 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ ae_summary.pptx
dd.pptx
dm.pptx
dor.pptx
‘output.pptx’
‘output.pptx’
tests/testthat/srep.pptx
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
.Ruserdata
tests/testthat/Rplots.pdf
tests/testthat/t_dm_output.rds
tests/testthat/srep.pptx
38 changes: 38 additions & 0 deletions tests/testthat/_snaps/t_ae_slide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Test adverse event table creation of t_ae_slide (Adverse Events for Patient)

Code
t_ae_slide(adsl, adae, "TRT01A")
Output
AE event table
———————————————————————————————————————————————————————————————————————
MedDRA System Organ Class
MedDRA Preferred Term N (%) A: Drug X B: Placebo All Patients
———————————————————————————————————————————————————————————————————————
cl A.1 78 (58.2%) 75 (56.0%) 242 (60.5%)
dcd A.1.1.1.1 50 (37.3%) 45 (33.6%) 158 (39.5%)
dcd A.1.1.1.2 48 (35.8%) 48 (35.8%) 146 (36.5%)
cl B.2 79 (59.0%) 74 (55.2%) 238 (59.5%)
dcd B.2.2.3.1 48 (35.8%) 54 (40.3%) 153 (38.2%)
dcd B.2.1.2.1 49 (36.6%) 44 (32.8%) 145 (36.2%)
cl D.1 79 (59.0%) 67 (50.0%) 226 (56.5%)
dcd D.1.1.1.1 50 (37.3%) 42 (31.3%) 143 (35.8%)
dcd D.1.1.4.2 48 (35.8%) 42 (31.3%) 140 (35.0%)
cl D.2 47 (35.1%) 58 (43.3%) 162 (40.5%)
dcd D.2.1.5.3 47 (35.1%) 58 (43.3%) 162 (40.5%)
cl B.1 47 (35.1%) 49 (36.6%) 139 (34.8%)
dcd B.1.1.1.1 47 (35.1%) 49 (36.6%) 139 (34.8%)
cl C.1 43 (32.1%) 46 (34.3%) 132 (33.0%)
dcd C.1.1.1.3 43 (32.1%) 46 (34.3%) 132 (33.0%)
cl C.2 35 (26.1%) 48 (35.8%) 138 (34.5%)
dcd C.2.1.2.1 35 (26.1%) 48 (35.8%) 138 (34.5%)

# Test adverse event table creation of t_ae_slide with null_report

Code
t_ae_slide(adsl, adae, "TRT01A")
Output
————————————————————————————————————————————————————————————————————————————————————————
Null Report: No observations met the reporting criteria for inclusion in this output.

80 changes: 80 additions & 0 deletions tests/testthat/_snaps/t_ae_summary_slide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Test table creation of t_ae_summ_slide (safety summary table)

Code
t_ae_summ_slide(testdata$adsl, testdata$adae, arm = "TRT01A",
dose_adjust_flags = c("dis_flags", "dis_flags", "dis_flags"),
dose_adjust_labels = c("DRUG WITHDRAWN", "DOSE REDUCED", "DRUG INTERRUPTED"),
gr34_highest_grade_only = TRUE)
Condition
Warning:
Non-unique sibling analysis table names. Using Labels instead. Use the table_names argument to analyze to avoid this when analyzing the same variable multiple times.
occured at (row) path: root
Output
AE summary table
———————————————————————————————————————————————————————————————————————————————————
A: Drug X B: Placebo C: Combination All Patients
(N=134) (N=134) (N=132) (N=400)
———————————————————————————————————————————————————————————————————————————————————
All grade AEs, any cause 100 (74.6%) 98 (73.1%) 103 (78.0%) 301 (75.2%)
Related 86 (64.2%) 85 (63.4%) 92 (69.7%) 263 (65.8%)
Grade 3-4 AEs 26 (19.4%) 31 (23.1%) 29 (22.0%) 86 (21.5%)
Related 13 (9.7%) 18 (13.4%) 15 (11.4%) 46 (11.5%)
Grade 5 AE 64 (47.8%) 52 (38.8%) 64 (48.5%) 180 (45.0%)
Related 64 (47.8%) 52 (38.8%) 64 (48.5%) 180 (45.0%)
SAEs 85 (63.4%) 80 (59.7%) 87 (65.9%) 252 (63.0%)
Related 64 (47.8%) 52 (38.8%) 64 (48.5%) 180 (45.0%)
DRUG WITHDRAWN 22 (16.4%) 21 (15.7%) 28 (21.2%) 71 (17.8%)
DOSE REDUCED 22 (16.4%) 21 (15.7%) 28 (21.2%) 71 (17.8%)
DRUG INTERRUPTED 22 (16.4%) 21 (15.7%) 28 (21.2%) 71 (17.8%)

---

Code
t_ae_summ_slide(testdata$adsl, testdata$adae, arm = "TRT01A",
dose_adjust_flags = c("dis_flags", "dis_flags", "dis_flags"),
dose_adjust_labels = c("DRUG WITHDRAWN", "DOSE REDUCED", "DRUG INTERRUPTED"),
gr34_highest_grade_only = FALSE)
Condition
Warning:
Non-unique sibling analysis table names. Using Labels instead. Use the table_names argument to analyze to avoid this when analyzing the same variable multiple times.
occured at (row) path: root
Output
AE summary table
———————————————————————————————————————————————————————————————————————————————————
A: Drug X B: Placebo C: Combination All Patients
(N=134) (N=134) (N=132) (N=400)
———————————————————————————————————————————————————————————————————————————————————
All grade AEs, any cause 100 (74.6%) 98 (73.1%) 103 (78.0%) 301 (75.2%)
Related 86 (64.2%) 85 (63.4%) 92 (69.7%) 263 (65.8%)
Grade 3-4 AEs 72 (53.7%) 70 (52.2%) 77 (58.3%) 219 (54.8%)
Related 36 (26.9%) 34 (25.4%) 36 (27.3%) 106 (26.5%)
Grade 5 AE 64 (47.8%) 52 (38.8%) 64 (48.5%) 180 (45.0%)
Related 64 (47.8%) 52 (38.8%) 64 (48.5%) 180 (45.0%)
SAEs 85 (63.4%) 80 (59.7%) 87 (65.9%) 252 (63.0%)
Related 64 (47.8%) 52 (38.8%) 64 (48.5%) 180 (45.0%)
DRUG WITHDRAWN 22 (16.4%) 21 (15.7%) 28 (21.2%) 71 (17.8%)
DOSE REDUCED 22 (16.4%) 21 (15.7%) 28 (21.2%) 71 (17.8%)
DRUG INTERRUPTED 22 (16.4%) 21 (15.7%) 28 (21.2%) 71 (17.8%)

# Test t_ae_summ_slide with expected Error

Code
t_ae_summ_slide(testdata$adsl, testdata$adae, arm = "TRT01A",
dose_adjust_flags = c("dis_flags", "dis_flags", "dis_flags"),
dose_adjust_labels = c("DRUG WITHDRAWN", "DOSE REDUCED", "DRUG INTERRUPTED"),
gr34_highest_grade_only = "FALSE")
Condition
Error:
! gr34_highest_grade_only is not a flag (a length one logical vector).

# Test t_ae_summ_slide with null_report

Code
t_ae_summ_slide(testdata$adsl[1, ], testdata$adae[1, ])
Output
————————————————————————————————————————————————————————————————————————————————————————
Null Report: No observations met the reporting criteria for inclusion in this output.

69 changes: 69 additions & 0 deletions tests/testthat/_snaps/t_aesi_slide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Test table creation of t_aesi_slide (AESI summary table) with AETOXGR grading

Code
t_aesi_slide(testdata$adsl, testdata$adae, aesi = "CQ01NAM", arm = "ACTARM")
Output
A: Drug X B: Placebo C: Combination
(N=134) (N=134) (N=132)
————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
Total number of patients with at least one AESI 97 (72.4%) 93 (69.4%) 99 (75.0%)
Total number of AESIs 396 380 465
Total number of patients with at least one AESI by worst grade
Grade 1 4 (3.0%) 3 (2.2%) 0
Grade 2 6 (4.5%) 10 (7.5%) 7 (5.3%)
Grade 3 18 (13.4%) 14 (10.4%) 16 (12.1%)
Grade 4 15 (11.2%) 20 (14.9%) 18 (13.6%)
Grade 5 (fatal outcome) 76 (56.7%) 70 (52.2%) 75 (56.8%)
Total number of patients with study drug withdrawn due to AESI 21 (15.7%) 15 (11.2%) 26 (19.7%)
Total number of patients with dose modified/interrupted due to AESI 56 (41.8%) 63 (47.0%) 64 (48.5%)
Total number of patients with treatment received for AESI 91 (67.9%) 93 (69.4%) 95 (72.0%)
Total number of patients with all non-fatal AESIs resolved 23 (17.2%) 17 (12.7%) 19 (14.4%)
Total number of patients with at least one unresolved or ongoing non-fatal AESI 96 (71.6%) 100 (74.6%) 97 (73.5%)
Total number of patients with at least one serious AESI 104 (77.6%) 101 (75.4%) 99 (75.0%)
Total number of patients with at least one related AESI 99 (73.9%) 98 (73.1%) 102 (77.3%)

# Test table creation of t_aesi_slide (AESI summary table) with AESEV grading

Code
t_aesi_slide(testdata$adsl, testdata$adae_aesev, aesi = "CQ01NAM", arm = "ACTARM",
grad_var = "AESEV")
Output
A: Drug X B: Placebo C: Combination
(N=134) (N=134) (N=132)
————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
Total number of patients with at least one AESI 97 (72.4%) 93 (69.4%) 99 (75.0%)
Total number of AESIs 396 380 465
Total number of patients with at least one AESI by worst grade
Mild 10 (7.5%) 13 (9.7%) 7 (5.3%)
Moderate 18 (13.4%) 14 (10.4%) 16 (12.1%)
Severe 91 (67.9%) 90 (67.2%) 93 (70.5%)
Total number of patients with study drug withdrawn due to AESI 21 (15.7%) 15 (11.2%) 26 (19.7%)
Total number of patients with dose modified/interrupted due to AESI 56 (41.8%) 63 (47.0%) 64 (48.5%)
Total number of patients with treatment received for AESI 91 (67.9%) 93 (69.4%) 95 (72.0%)
Total number of patients with all non-fatal AESIs resolved 23 (17.2%) 17 (12.7%) 19 (14.4%)
Total number of patients with at least one unresolved or ongoing non-fatal AESI 96 (71.6%) 100 (74.6%) 97 (73.5%)
Total number of patients with at least one serious AESI 104 (77.6%) 101 (75.4%) 99 (75.0%)
Total number of patients with at least one related AESI 99 (73.9%) 98 (73.1%) 102 (77.3%)

# Test table creation of t_aesi_slide (AESI summary table) with custom AEGRP grouping

Code
t_aesi_slide(testdata$adsl, testdata$adae_custom, aesi = "CQ01NAM", arm = "ARM",
grad_var = "AEGRP")
Output
A: Drug X B: Placebo C: Combination
(N=134) (N=134) (N=132)
————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
Total number of patients with at least one AESI 97 (72.4%) 93 (69.4%) 99 (75.0%)
Total number of AESIs 396 380 465
Total number of patients with at least one AESI by worst grade
Grade 1-2 10 (7.5%) 13 (9.7%) 7 (5.3%)
Grade 3-5 109 (81.3%) 104 (77.6%) 109 (82.6%)
Total number of patients with study drug withdrawn due to AESI 21 (15.7%) 15 (11.2%) 26 (19.7%)
Total number of patients with dose modified/interrupted due to AESI 56 (41.8%) 63 (47.0%) 64 (48.5%)
Total number of patients with treatment received for AESI 91 (67.9%) 93 (69.4%) 95 (72.0%)
Total number of patients with all non-fatal AESIs resolved 23 (17.2%) 17 (12.7%) 19 (14.4%)
Total number of patients with at least one unresolved or ongoing non-fatal AESI 96 (71.6%) 100 (74.6%) 97 (73.5%)
Total number of patients with at least one serious AESI 104 (77.6%) 101 (75.4%) 99 (75.0%)
Total number of patients with at least one related AESI 99 (73.9%) 98 (73.1%) 102 (77.3%)

53 changes: 53 additions & 0 deletions tests/testthat/test-srep_outputs.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
library(filters)

test_that("Listing print correctly", {
# skip_if_too_deep(1)
load_filters(file.path(system.file(package = "autoslider.core"), "filters.yml"), overwrite = TRUE)

spec_file <- file.path(system.file(package = "autoslider.core"), "spec.yml")

full_spec <- spec_file %>%
read_spec()

outputs <- full_spec %>%
filter_spec(., program %in% c(
"t_ds_slide",
"t_ds_trt_slide",
"t_dd_slide",
"t_ae_slide",
"t_ae_sae_slide",
# "g_km_slide",
# "g_km_annotation_surv",
# "g_km_annotation_coxph",
"t_ae_pt_slide",
"t_ae_pt_soc_slide",
"t_ae_pt_diff_slide",
"t_ae_pt_diff_soc_slide",
"t_pop_slide",
"t_dor_slide",
"t_orr_dor_slide",
"t_tte_slide",
"t_orr_slide",
# "l_dsl01_slide",
# "t_dm_slide",
"t_vs_slide",
"t_ae_summ_slide",
"t_ex_slide"
)) %>%
generate_outputs(datasets = testdata) %>%
decorate_outputs(
version_label = NULL,
for_test = TRUE
)

output_dir <- tempdir()
testthat::expect_output({
outputs %>%
generate_slides(outfile = paste0(output_dir, "/srep.pptx"), t_cpp = 250, t_lpp = 50)
})

testthat::expect_no_error({
outputs %>%
save_outputs(outfolder = output_dir)
})
})
25 changes: 25 additions & 0 deletions tests/testthat/test-t_ae_slide.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
test_that("Test adverse event table creation of t_ae_slide (Adverse Events for Patient)", {
adsl <- eg_adsl %>%
dplyr::mutate(TRT01A = factor(TRT01A, levels = c("A: Drug X", "B: Placebo")))
adae <- eg_adae %>%
dplyr::mutate(
TRT01A = factor(TRT01A, levels = c("A: Drug X", "B: Placebo")),
ATOXGR = AETOXGR
)

expect_snapshot(t_ae_slide(adsl, adae, "TRT01A"))
})

test_that("Test adverse event table creation of t_ae_slide with null_report", {
adsl <- eg_adsl %>%
dplyr::mutate(TRT01A = factor(TRT01A, levels = c("A: Drug X", "B: Placebo")))
adae <- eg_adae %>%
dplyr::mutate(
TRT01A = factor(TRT01A, levels = c("A: Drug X", "B: Placebo")),
ATOXGR = AETOXGR
)
adae <- adae[1, ]
adsl <- adsl[1, ]

expect_snapshot(t_ae_slide(adsl, adae, "TRT01A"))
})
36 changes: 36 additions & 0 deletions tests/testthat/test-t_ae_summary_slide.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
test_that("Test table creation of t_ae_summ_slide (safety summary table)", {
expect_snapshot(t_ae_summ_slide(testdata$adsl, testdata$adae,
arm = "TRT01A",
dose_adjust_flags = c("dis_flags", "dis_flags", "dis_flags"),
dose_adjust_labels = c(
"DRUG WITHDRAWN", "DOSE REDUCED",
"DRUG INTERRUPTED"
),
gr34_highest_grade_only = TRUE
))
expect_snapshot(t_ae_summ_slide(testdata$adsl, testdata$adae,
arm = "TRT01A",
dose_adjust_flags = c("dis_flags", "dis_flags", "dis_flags"),
dose_adjust_labels = c(
"DRUG WITHDRAWN", "DOSE REDUCED",
"DRUG INTERRUPTED"
),
gr34_highest_grade_only = FALSE
))
})

test_that("Test t_ae_summ_slide with expected Error", {
expect_snapshot(error = TRUE, t_ae_summ_slide(testdata$adsl, testdata$adae,
arm = "TRT01A",
dose_adjust_flags = c("dis_flags", "dis_flags", "dis_flags"),
dose_adjust_labels = c(
"DRUG WITHDRAWN", "DOSE REDUCED",
"DRUG INTERRUPTED"
),
gr34_highest_grade_only = "FALSE"
))
})

test_that("Test t_ae_summ_slide with null_report", {
expect_snapshot(t_ae_summ_slide(testdata$adsl[1, ], testdata$adae[1, ]))
})
Loading

0 comments on commit 6cab16a

Please sign in to comment.