From 830a8b4b9f4a9240f59012f5f9819cc05575159a Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Mon, 17 Jul 2023 22:49:12 -0400 Subject: [PATCH 1/2] Fix tests using ADPC after refactor --- tests/testthat/_snaps/listing_adal02.md | 98 ++++++++++++++----------- tests/testthat/_snaps/table_adat03.md | 28 +++---- tests/testthat/test-listing_adal02.R | 41 +++++++---- tests/testthat/test-listing_pkcl01.R | 6 +- tests/testthat/test-table_adat03.R | 6 +- tests/testthat/test-table_pkct01.R | 14 ++-- 6 files changed, 107 insertions(+), 86 deletions(-) diff --git a/tests/testthat/_snaps/listing_adal02.md b/tests/testthat/_snaps/listing_adal02.md index 377c59ee..c7de9b3f 100644 --- a/tests/testthat/_snaps/listing_adal02.md +++ b/tests/testthat/_snaps/listing_adal02.md @@ -8,49 +8,61 @@ Treatment Group: A: Drug X - —————————————————————————————————————————————————————— - Day 2 Patient Treatment - Subject ID (Day 1) Emergent ADA Status - —————————————————————————————————————————————————————— - AB12345-BRA-1-id-93 <1.10* Induced (Persistent) - AB12345-CHN-1-id-123 1.28* Induced (Persistent) - AB12345-CHN-1-id-329 1.43* Induced (Persistent) - AB12345-CHN-1-id-53 <1.10* Induced (Persistent) - AB12345-CHN-1-id-71 1.28* Induced (Persistent) - AB12345-CHN-11-id-116 1.36* Induced (Persistent) - AB12345-CHN-11-id-124 <1.10* Induced (Persistent) - AB12345-CHN-11-id-167 1.26* Induced (Persistent) - AB12345-CHN-11-id-256 1.35* Induced (Persistent) - AB12345-CHN-11-id-377 1.17* Induced (Persistent) - AB12345-CHN-12-id-258 1.40* Induced (Persistent) - AB12345-CHN-12-id-266 <1.10* Induced (Persistent) - AB12345-CHN-12-id-57 1.24* Induced (Persistent) - AB12345-CHN-14-id-161 <1.10* Induced (Persistent) - AB12345-CHN-15-id-399 <1.10* Induced (Persistent) - AB12345-CHN-18-id-170 <1.10* Induced (Persistent) - AB12345-CHN-2-id-22 <1.10* Induced (Persistent) - AB12345-CHN-2-id-272 1.20* Induced (Persistent) - AB12345-CHN-2-id-398 1.14* Induced (Persistent) - AB12345-CHN-3-id-128 1.21* Induced (Persistent) - AB12345-CHN-3-id-361 1.32* Induced (Persistent) - AB12345-CHN-5-id-108 <1.10* Induced (Persistent) - AB12345-CHN-8-id-205 1.14* Induced (Persistent) - AB12345-GBR-13-id-80 <1.10* Induced (Persistent) - AB12345-GBR-15-id-293 1.14* Induced (Persistent) - AB12345-JPN-1-id-218 <1.10* Induced (Persistent) - AB12345-NGA-1-id-388 <1.10* Induced (Persistent) - AB12345-NGA-2-id-353 <1.10* Induced (Persistent) - AB12345-PAK-1-id-79 1.26* Induced (Persistent) - AB12345-PAK-11-id-187 1.16* Induced (Persistent) - AB12345-PAK-13-id-251 1.14* Induced (Persistent) - AB12345-PAK-15-id-314 <1.10* Induced (Persistent) - AB12345-RUS-1-id-52 1.22* Induced (Persistent) - AB12345-RUS-6-id-77 1.16* Induced (Persistent) - AB12345-USA-11-id-238 1.31* Induced (Persistent) - AB12345-USA-11-id-339 1.24* Induced (Persistent) - AB12345-USA-17-id-142 1.35* Induced (Persistent) - AB12345-USA-3-id-282 <1.10* Induced (Persistent) - —————————————————————————————————————————————————————— + ————————————————————————————————————————————————————— + Day 2 Patient Treatment + Subject ID (Day 1) Emergent ADA Status + ————————————————————————————————————————————————————— + AB12345-BRA-1-id-105 --- Enhanced + AB12345-BRA-1-id-134 --- Enhanced + AB12345-BRA-1-id-42 --- Enhanced + AB12345-BRA-1-id-93 --- Enhanced + AB12345-BRA-11-id-217 --- Enhanced + AB12345-BRA-11-id-345 --- Enhanced + AB12345-BRA-11-id-397 --- Enhanced + AB12345-BRA-11-id-50 --- Enhanced + AB12345-BRA-13-id-177 --- Enhanced + AB12345-BRA-14-id-23 --- Enhanced + AB12345-BRA-15-id-36 --- Enhanced + AB12345-BRA-2-id-296 --- Enhanced + AB12345-BRA-6-id-369 --- Enhanced + AB12345-CAN-1-id-18 --- Enhanced + AB12345-CAN-11-id-139 --- Enhanced + AB12345-CAN-14-id-104 --- Enhanced + AB12345-CHN-1-id-119 --- Enhanced + AB12345-CHN-1-id-123 --- Enhanced + AB12345-CHN-1-id-133 --- Enhanced + AB12345-CHN-1-id-199 --- Enhanced + AB12345-CHN-1-id-216 --- Enhanced + AB12345-CHN-1-id-235 --- Enhanced + AB12345-CHN-1-id-25 --- Enhanced + AB12345-CHN-1-id-26 --- Enhanced + AB12345-CHN-1-id-275 --- Enhanced + AB12345-CHN-1-id-277 --- Enhanced + AB12345-CHN-1-id-287 --- Enhanced + AB12345-CHN-1-id-315 --- Enhanced + AB12345-CHN-1-id-316 --- Enhanced + AB12345-CHN-1-id-329 --- Enhanced + AB12345-CHN-1-id-360 --- Enhanced + AB12345-CHN-1-id-371 --- Enhanced + AB12345-CHN-1-id-47 --- Enhanced + AB12345-CHN-1-id-53 --- Enhanced + AB12345-CHN-1-id-62 --- Enhanced + AB12345-CHN-1-id-69 --- Enhanced + AB12345-CHN-1-id-71 --- Enhanced + AB12345-CHN-11-id-116 --- Enhanced + AB12345-CHN-11-id-124 --- Enhanced + AB12345-CHN-11-id-132 --- Enhanced + AB12345-CHN-11-id-153 --- Enhanced + AB12345-CHN-11-id-167 --- Enhanced + AB12345-CHN-11-id-256 --- Enhanced + AB12345-CHN-11-id-354 --- Enhanced + AB12345-CHN-11-id-356 --- Enhanced + AB12345-CHN-11-id-377 --- Enhanced + AB12345-CHN-11-id-379 --- Enhanced + AB12345-CHN-11-id-392 --- Enhanced + AB12345-CHN-11-id-88 --- Enhanced + AB12345-CHN-12-id-258 --- Enhanced + ————————————————————————————————————————————————————— Minimum reportable titer = 1.10 (example only) --- = No sample evaluated diff --git a/tests/testthat/_snaps/table_adat03.md b/tests/testthat/_snaps/table_adat03.md index b1d50588..a607effc 100644 --- a/tests/testthat/_snaps/table_adat03.md +++ b/tests/testthat/_snaps/table_adat03.md @@ -3,24 +3,24 @@ 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=670) - Day 1 536 3.152e+00 5.516e+00 0.000e+00 0.000e+00 1.557e+01 175.0 NA 531 (99.1%) - Day 2 134 1.618e+01 1.626e+00 1.619e+01 1.260e+01 1.986e+01 10.0 1.610e+01 39 (29.1%) + 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=536) + Day 1 402 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 NA NA 402 (100%) + Day 2 134 1.618e+01 1.626e+00 1.619e+01 1.260e+01 1.986e+01 10.0 1.610e+01 39 (29.1%) - C: Combination (N=1056) - Day 1 792 6.459e+00 9.961e+00 0.000e+00 0.000e+00 3.100e+01 154.2 NA 654 (82.6%) - Day 2 264 2.468e+01 8.645e+00 2.251e+01 1.264e+01 3.947e+01 35.0 2.315e+01 28 (10.6%) + C: Combination (N=792) + Day 1 528 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 NA NA 528 (100%) + Day 2 264 2.468e+01 8.645e+00 2.251e+01 1.264e+01 3.947e+01 35.0 2.315e+01 28 (10.6%) - Overall 1726 8.975e+00 1.104e+01 0.000e+00 0.000e+00 3.947e+01 123.0 NA 1252 (72.5%) - ————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————— + Overall 1328 6.540e+00 1.095e+01 0.000e+00 0.000e+00 3.947e+01 167.5 NA 997 (75.1%) + ———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————— {1} - footnote1 {2} - footnote2 - ————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————— + ———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————— diff --git a/tests/testthat/test-listing_adal02.R b/tests/testthat/test-listing_adal02.R index 15bfba7d..b24ca5f7 100644 --- a/tests/testthat/test-listing_adal02.R +++ b/tests/testthat/test-listing_adal02.R @@ -1,6 +1,6 @@ testthat::test_that("ADAL02 listing is produced correctly", { adab <- adab_raw %>% - filter(NRELTM1 %% 1 == 0 & NRELTM1 > 0) + filter(NFRLT %% 1 == 0 & NFRLT > 0) trt <- "A: Drug X" drug_a <- "A: Drug X Antibody" @@ -11,29 +11,30 @@ testthat::test_that("ADAL02 listing is produced correctly", { filter( ARM == trt, PARCAT1 == drug_a, - ADAPBLFL == "Y" + ADPBLPFL == "Y" ) %>% - select(-PARAMCD, -AVALC, -AVALU, -ARELTM2, -NRELTM2) %>% + select(-PARAMCD, -AVALC, -AVALU, -ARRLT, -NRRLT) %>% unique() %>% tidyr::pivot_wider( names_from = PARAM, values_from = AVAL ) %>% - filter(`Treatment Emergent - Positive` == 1) %>% + filter(if_any(matches("Treatment Emergent - Positive"), ~ .x == 1)) %>% + # filter(`Treatment Emergent - Positive` == 1) %>% mutate( VISN = factor(paste0( VISIT, "\n(Day ", ifelse( - NRELTM1 %% 1 == 0, - NRELTM1, - as.character(format(round(NRELTM1, 2), nsmall = 2)) + NFRLT %% 1 == 0, + NFRLT, + as.character(format(round(NFRLT, 2), nsmall = 2)) ), ")" )), PTES = ifelse( - `Treatment induced ADA` == 1, + ifelse("Treatment induced ADA" %in% names(.), `Treatment induced ADA` == 1, F), ifelse( - `Transient ADA` == 1, + "Transient ADA" %in% names(.) & `Transient ADA` == 1, "Induced (Transient)", "Induced (Persistent)" ), @@ -42,16 +43,24 @@ testthat::test_that("ADAL02 listing is produced correctly", { ) %>% mutate( AVAL = paste0( - ifelse(`ADA interpreted per sample result` == 0, + ifelse( + ifelse("ADA interpreted per sample result" %in% names(.), `ADA interpreted per sample result` == 0, F), "NEGATIVE", - ifelse(is.na(`Antibody titer units`), - "---", - ifelse(`Antibody titer units` < min_titer, + ifelse( + ifelse("Antibody titer units" %in% names(.), !is.na(`Antibody titer units`), F), + ifelse( + `Antibody titer units` < min_titer, paste0("<", format(min_titer, nsmall = 2)), as.character(format(round(`Antibody titer units`, 2), nsmall = 2)) - ) + ), + "---" ) - ), ifelse(`NAB interpreted per sample result` == 1, "*", "") + ), + ifelse( + ifelse("NAB interpreted per sample result" %in% names(.), `NAB interpreted per sample result` == 1, F), + "*", + "" + ) ) ) @@ -61,7 +70,7 @@ testthat::test_that("ADAL02 listing is produced correctly", { names_from = VISN, values_from = AVAL ) %>% - select(USUBJID, unique(adab_x$VISN[order(adab_x$NRELTM1)]), PTES) + select(USUBJID, unique(adab_x$VISN[order(adab_x$NFRLT)]), PTES) formatters::var_labels(out) <- names(out) diff --git a/tests/testthat/test-listing_pkcl01.R b/tests/testthat/test-listing_pkcl01.R index 64669306..bba6f4fd 100644 --- a/tests/testthat/test-listing_pkcl01.R +++ b/tests/testthat/test-listing_pkcl01.R @@ -3,14 +3,14 @@ testthat::test_that("PKCL01 listing is produced correctly", { analyte <- "Plasma Drug X" out <- adpc %>% filter(PARAM == analyte) %>% - select(ARM, USUBJID, VISIT, NRELTM1, ARELTM1, AVAL) + select(ARM, USUBJID, VISIT, NFRLT, AFRLT, AVAL) formatters::var_labels(out) <- c( ARM = "Treatment Group", USUBJID = "Subject ID", VISIT = "Visit", - NRELTM1 = paste0("Nominal Sampling\nTime (", adpc$RELTMU[1], ")"), - ARELTM1 = paste0("Actual Time\nFrom First\nDose (", adpc$RELTMU[1], ")"), + NFRLT = paste0("Nominal Sampling\nTime (", adpc$RELTMU[1], ")"), + AFRLT = paste0("Actual Time\nFrom First\nDose (", adpc$RELTMU[1], ")"), AVAL = paste0("Concentration\n(", adpc$AVALU[1], ")") ) diff --git a/tests/testthat/test-table_adat03.R b/tests/testthat/test-table_adat03.R index 9b3f183a..e6e00cdf 100644 --- a/tests/testthat/test-table_adat03.R +++ b/tests/testthat/test-table_adat03.R @@ -1,9 +1,9 @@ -adpc <- adpc_raw %>% select(USUBJID, NRELTM1, AVAL, AVALU, AVALC) +adpc <- adpc_raw %>% select(USUBJID, NFRLT, AVAL, AVALU) anl <- adab_raw %>% filter(., PARAM == "ADA interpreted per sample result") %>% - select(-AVAL, AVALC, AVALU) + select(-AVAL, AVALU) -anl <- merge(anl, adpc, by = c("USUBJID", "NRELTM1")) %>% +anl <- merge(anl, adpc, by = c("USUBJID", "NFRLT")) %>% mutate(AVAL_LT = ifelse(AVAL <= 15, TRUE, FALSE)) # parameters in columns diff --git a/tests/testthat/test-table_pkct01.R b/tests/testthat/test-table_pkct01.R index 099d67d3..8e3ac832 100644 --- a/tests/testthat/test-table_pkct01.R +++ b/tests/testthat/test-table_pkct01.R @@ -24,11 +24,11 @@ testthat::test_that("PKCT01 is produced correctly", { ) %>% split_rows_by(var = "PARAM", child_labels = "hidden") %>% analyze_vars_in_cols( - vars = "AVALC", var_type = "character", .stats = c("n_blq"), + vars = "AVALCAT1", var_type = "character", .stats = c("n_blq"), .labels = c(n_blq = "n_blq") ) - adpc <- adpc %>% mutate(AVALC = as.factor(AVALC)) + adpc <- adpc %>% mutate(AVALCAT1 = as.factor(AVALCAT1)) result <- build_table(l2, df = adpc) res <- testthat::expect_silent(result) @@ -44,12 +44,12 @@ testthat::test_that("Specific PKCT01 features are present", { # Setting up the data adpc_1 <- adpc %>% mutate( - NRELTM1 = as.factor(NRELTM1), - AVALC = as.factor(AVALC) + NFRLT = as.factor(NFRLT), + AVALCAT1 = as.factor(AVALCAT1) ) %>% filter(ACTARM %in% c("A: Drug X")) %>% mutate(ACTARM = factor(ACTARM, levels = c("A: Drug X"))) %>% - select(NRELTM1, ACTARM, VISIT, AVAL, PARAM, AVALC) + select(NFRLT, ACTARM, VISIT, AVAL, PARAM, AVALCAT1) # Row structure l_rows <- basic_table() %>% @@ -64,7 +64,7 @@ testthat::test_that("Specific PKCT01 features are present", { label_pos = "topleft" ) %>% split_rows_by( - var = "NRELTM1", + var = "NFRLT", split_label = "Norminal Time from First Dose", label_pos = "topleft", child_labels = "hidden" @@ -73,7 +73,7 @@ testthat::test_that("Specific PKCT01 features are present", { # Column results for numeric values lyt <- l_rows %>% analyze_vars_in_cols( - vars = c("AVAL", "AVALC", rep("AVAL", 8)), + vars = c("AVAL", "AVALCAT1", rep("AVAL", 8)), .stats = c( "n", "n_blq", "mean", "sd", "cv", "geom_mean", "geom_cv", # "geom_mean_ci", From a76215d83813f6707c679e14ef0a6bd64dedb3f4 Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Mon, 17 Jul 2023 22:57:02 -0400 Subject: [PATCH 2/2] Fix lint --- tests/testthat/test-listing_adal02.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-listing_adal02.R b/tests/testthat/test-listing_adal02.R index b24ca5f7..58fe3558 100644 --- a/tests/testthat/test-listing_adal02.R +++ b/tests/testthat/test-listing_adal02.R @@ -32,7 +32,7 @@ testthat::test_that("ADAL02 listing is produced correctly", { ")" )), PTES = ifelse( - ifelse("Treatment induced ADA" %in% names(.), `Treatment induced ADA` == 1, F), + ifelse("Treatment induced ADA" %in% names(.), `Treatment induced ADA` == 1, FALSE), ifelse( "Transient ADA" %in% names(.) & `Transient ADA` == 1, "Induced (Transient)", @@ -44,10 +44,10 @@ testthat::test_that("ADAL02 listing is produced correctly", { mutate( AVAL = paste0( ifelse( - ifelse("ADA interpreted per sample result" %in% names(.), `ADA interpreted per sample result` == 0, F), + ifelse("ADA interpreted per sample result" %in% names(.), `ADA interpreted per sample result` == 0, FALSE), "NEGATIVE", ifelse( - ifelse("Antibody titer units" %in% names(.), !is.na(`Antibody titer units`), F), + ifelse("Antibody titer units" %in% names(.), !is.na(`Antibody titer units`), FALSE), ifelse( `Antibody titer units` < min_titer, paste0("<", format(min_titer, nsmall = 2)), @@ -57,7 +57,7 @@ testthat::test_that("ADAL02 listing is produced correctly", { ) ), ifelse( - ifelse("NAB interpreted per sample result" %in% names(.), `NAB interpreted per sample result` == 1, F), + ifelse("NAB interpreted per sample result" %in% names(.), `NAB interpreted per sample result` == 1, FALSE), "*", "" )