Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create test snapshots & upgrade to testthat 3rd edition #801

Merged
merged 13 commits into from
Jan 19, 2023
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Suggests:
scda (>= 0.1.5),
scda.2022 (>= 0.1.3),
stringr,
testthat (>= 2.0)
testthat (>= 3.0)
VignetteBuilder:
knitr
RdMacros:
Expand All @@ -65,6 +65,7 @@ Remotes:
insightsengineering/scda.2022@*release,
insightsengineering/scda@*release
Config/Needs/website: insightsengineering/nesttemplate
Config/testthat/edition: 3
Encoding: UTF-8
Language: en-US
Roxygen: list(markdown = TRUE)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
repeat when paginating.
* Added `h_row_first_values` function as a more general helper function to retrieve
first values from specific rows.
* Replaced table template tests with snapshot testing.

### Bug Fixes
* Fixed bug causing incorrect ordering of numeric grade levels when missing
Expand All @@ -38,6 +39,7 @@
* Renamed `summarize_vars_in_cols` into `analyze_vars_in_cols` to reflect the
appropriate `analyze` logic.
* Exported function `format_xx`.
* Updated tests to use `testthat` 3rd edition.

# tern 0.7.10

Expand Down
4 changes: 2 additions & 2 deletions R/g_step.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ g_step <- function(df,
name = "", values = c("CI 95%" = ci_ribbon$fill)
)
}
p <- p +
suppressMessages(p <- p +
ggplot2::geom_line(
ggplot2::aes(y = .data[["y"]], color = legend_names[1]),
linetype = est$lty
) +
scale_colour_manual(
name = "", values = c("Estimate" = "blue")
)
))

p <- p + ggplot2::labs(x = attrs$biomarker, y = attrs$estimate)
if (use_percentile) {
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/.gitignore

This file was deleted.

30 changes: 30 additions & 0 deletions tests/testthat/_snaps/table_adat03.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# ADAT03 is produced correctly

Code
res
Output
Treatment Group
Visit Total Number Samples with
of Measurable Concentration
Samples {1} Mean SD Median Minimum Maximum CV (%) Geometric Mean ≤ 15μg/mL {2}
—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
A: Drug X (N=1206)
Day 1
938 8.227e+00 7.351e+00 1.131e+01 0.000e+00 1.986e+01 89.4 NA 738 (78.7%)
Day 2
268 1.344e+01 1.351e+00 1.330e+01 1.075e+01 1.646e+01 10.0 1.338e+01 228 (85.1%)
C: Combination (N=2112)
Day 1
1584 1.469e+01 1.237e+01 1.451e+01 0.000e+00 3.947e+01 84.3 NA 836 (52.8%)
Day 2
528 2.018e+01 7.129e+00 1.888e+01 1.073e+01 3.259e+01 35.3 1.891e+01 210 (39.8%)
Overall 3318 1.363e+01 1.059e+01 1.377e+01 0.000e+00 3.947e+01 77.7 NA 2012 (60.6%)
—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
{1} - footnote1
{2} - footnote2
—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

107 changes: 107 additions & 0 deletions tests/testthat/_snaps/table_aet01.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Safety Summary Variant 1 works as expected

Code
res
Output
A: Drug X B: Placebo C: Combination
(N=134) (N=134) (N=132)
———————————————————————————————————————————————————————————————————————————————————————————————————————
Total number of patients with at least one adverse event 122 (91.0%) 123 (91.8%) 120 (90.9%)
Total AEs 609 622 703
Total number of deaths 25 (18.66%) 23 (17.16%) 22 (16.67%)
Total number of patients withdrawn from study due to an AE 3 (2.24%) 6 (4.48%) 5 (3.79%)
Total number of patients with at least one
AE with fatal outcome 76 (56.7%) 70 (52.2%) 75 (56.8%)
Serious AE 104 (77.6%) 101 (75.4%) 99 (75.0%)
Serious AE leading to withdrawal from treatment 9 (6.7%) 6 (4.5%) 11 (8.3%)
Serious AE leading to dose modification/interruption 22 (16.4%) 26 (19.4%) 29 (22.0%)
Related Serious AE 76 (56.7%) 70 (52.2%) 75 (56.8%)
AE leading to withdrawal from treatment 27 (20.1%) 26 (19.4%) 30 (22.7%)
AE leading to dose modification/interruption 66 (49.3%) 76 (56.7%) 74 (56.1%)
Related AE 105 (78.4%) 108 (80.6%) 109 (82.6%)
Related AE leading to withdrawal from treatment 6 (4.5%) 12 (9.0%) 8 (6.1%)
Related AE leading to dose modification/interruption 29 (21.6%) 38 (28.4%) 38 (28.8%)
Grade 3-5 AE 109 (81.3%) 104 (77.6%) 109 (82.6%)

# Safety Summary Variant 2 (with Medical Concepts Section) works as expected

Code
res
Output
A: Drug X B: Placebo C: Combination
(N=134) (N=134) (N=132)
———————————————————————————————————————————————————————————————————————————————————————————————————————
Total number of patients with at least one adverse event 122 (91.0%) 123 (91.8%) 120 (90.9%)
Total AEs 609 622 703
Total number of deaths 25 (18.66%) 23 (17.16%) 22 (16.67%)
Total number of patients withdrawn from study due to an AE 3 (2.24%) 6 (4.48%) 5 (3.79%)
Total number of patients with at least one
AE with fatal outcome 76 (56.7%) 70 (52.2%) 75 (56.8%)
Serious AE 104 (77.6%) 101 (75.4%) 99 (75.0%)
Serious AE leading to withdrawal from treatment 9 (6.7%) 6 (4.5%) 11 (8.3%)
Serious AE leading to dose modification/interruption 22 (16.4%) 26 (19.4%) 29 (22.0%)
Related Serious AE 76 (56.7%) 70 (52.2%) 75 (56.8%)
AE leading to withdrawal from treatment 27 (20.1%) 26 (19.4%) 30 (22.7%)
AE leading to dose modification/interruption 66 (49.3%) 76 (56.7%) 74 (56.1%)
Related AE 105 (78.4%) 108 (80.6%) 109 (82.6%)
Related AE leading to withdrawal from treatment 6 (4.5%) 12 (9.0%) 8 (6.1%)
Related AE leading to dose modification/interruption 29 (21.6%) 38 (28.4%) 38 (28.8%)
Grade 3-5 AE 109 (81.3%) 104 (77.6%) 109 (82.6%)
Total number of patients with at least one
C.1.1.1.3/B.2.2.3.1 AESI (BROAD) 72 (53.7%) 79 (59.0%) 75 (56.8%)
SMQ 02 Reference Name 0 0 0
D.2.1.5.3/A.1.1.1.1 AESI 74 (55.2%) 80 (59.7%) 87 (65.9%)

# Safety Summary Variant 3 (with Modified Rows) works as expected

Code
res
Output
A: Drug X B: Placebo C: Combination
(N=134) (N=134) (N=132)
———————————————————————————————————————————————————————————————————————————————————————————————————————
Total number of patients with at least one adverse event 122 (91.0%) 123 (91.8%) 120 (90.9%)
Total AEs 609 622 703
Total number of deaths 25 (18.66%) 23 (17.16%) 22 (16.67%)
Total number of patients withdrawn from study due to an AE 3 (2.24%) 6 (4.48%) 5 (3.79%)
Total number of patients withdrawn informed consent 1 (0.75%) 1 (0.75%) 1 (0.76%)
Total number of patients with at least one
AE with fatal outcome 76 (56.7%) 70 (52.2%) 75 (56.8%)
Serious AE 104 (77.6%) 101 (75.4%) 99 (75.0%)
AE leading to withdrawal from treatment 27 (20.1%) 26 (19.4%) 30 (22.7%)
Related AE 105 (78.4%) 108 (80.6%) 109 (82.6%)
Grade 3-5 AE 109 (81.3%) 104 (77.6%) 109 (82.6%)
Grade 4/5 AE 91 (67.9%) 90 (67.2%) 93 (70.5%)

# Safety Summary Variant 4 (with Rows Counting Events and Additional Sections) works as expected

Code
res
Output
A: Drug X B: Placebo C: Combination
(N=134) (N=134) (N=132)
———————————————————————————————————————————————————————————————————————————————————————————————————————
Total number of patients with at least one adverse event 122 (91.0%) 123 (91.8%) 120 (90.9%)
Total AEs 609 622 703
Total number of deaths 25 (18.66%) 23 (17.16%) 22 (16.67%)
Total number of patients withdrawn from study due to an AE 3 (2.24%) 6 (4.48%) 5 (3.79%)
Total number of patients with at least one
AE with fatal outcome 76 (56.7%) 70 (52.2%) 75 (56.8%)
Serious AE 104 (77.6%) 101 (75.4%) 99 (75.0%)
AE leading to withdrawal from treatment 27 (20.1%) 26 (19.4%) 30 (22.7%)
AE leading to dose modification/interruption 66 (49.3%) 76 (56.7%) 74 (56.1%)
Related AE 105 (78.4%) 108 (80.6%) 109 (82.6%)
Grade 3-5 AE 109 (81.3%) 104 (77.6%) 109 (82.6%)
Total number of unique preferred terms which are
Serious AE 4 4 4
AE leading to dose modification/interruption 8 8 8
Related AE 5 5 5
Grade 3-5 AE 5 5 5
Grade 4/5 3 3 3
Total number of adverse events which are
Serious AE 249 255 282
AE leading to dose modification/interruption 116 122 137
Related AE 282 299 336
Grade 3-5 AE 303 291 327
Grade 4/5 172 174 197

Loading