From 8c54703a25759bc46a882b8d46e03161ab671647 Mon Sep 17 00:00:00 2001 From: Alanah Jonas <156101954+alanahjonas95@users.noreply.github.com> Date: Fri, 27 Feb 2026 12:09:02 +0000 Subject: [PATCH 1/3] add attributes to ard_strata --- R/ard_strata.R | 10 +++++++++- tests/testthat/test-ard_strata.R | 29 ++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/R/ard_strata.R b/R/ard_strata.R index a4686eed6..5f7ccaee7 100644 --- a/R/ard_strata.R +++ b/R/ard_strata.R @@ -109,8 +109,16 @@ ard_strata <- function(.data, .by = NULL, .strata = NULL, .f, ...) { } # unnest ard data frame and return final table ------------------------------- - df_nested_data |> + ard_full <- df_nested_data |> tidyr::unnest(cols = all_of("ard")) |> as_card() |> tidy_ard_column_order(group_order = "descending") + + # append attributes ---------------------------------------------------------- + attr(ard_full, "args") <- list( + by =.by, + strata = .strata + ) + + ard_full } diff --git a/tests/testthat/test-ard_strata.R b/tests/testthat/test-ard_strata.R index af6b62240..6cb121342 100644 --- a/tests/testthat/test-ard_strata.R +++ b/tests/testthat/test-ard_strata.R @@ -20,19 +20,22 @@ test_that("ard_strata() works", { tidy_ard_column_order() |> tidy_ard_row_order(), ard_summary(ADSL, by = c(SEX, AGEGR1, ARM), variables = AGE) |> - tidy_ard_row_order() + tidy_ard_row_order(), + ignore_attr = TRUE ) }) test_that("ard_strata(by,strata) when both empty", { expect_equal( ard_strata(ADSL, .f = ~ ard_summary(.x, variables = AGE)), - ard_summary(ADSL, variables = AGE) + ard_summary(ADSL, variables = AGE), + ignore_attr = TRUE ) expect_equal( ard_strata(ADSL, .f = ~ ard_summary(.x, by = ARM, variables = AGE)), - ard_summary(ADSL, by = ARM, variables = AGE) + ard_summary(ADSL, by = ARM, variables = AGE), + ignore_attr = TRUE ) }) @@ -74,3 +77,23 @@ test_that("ard_strata computes stats for parameter specific strata", { expect_snapshot(as.data.frame(tbl)) }) + + +test_that("ard_strata() attaches 'args' attribute", { + # Test with both .by and .strata + res <- ard_strata( + ADSL, + .by = ARM, + .strata = SEX, + .f = ~ ard_summary(.x, variables = AGE) + ) + + expect_equal(attr(res, "args")$by, "ARM") + expect_equal(attr(res, "args")$strata, "SEX") + + # Test with only .by + res_by <- ard_strata(ADSL, .by = ARM, .f = ~ ard_summary(.x, variables = AGE)) + expect_equal(attr(res_by, "args")$by, "ARM") + expect_equal(attr(res_by, "args")$strata, character(0)) + +}) From f61a3d244d5007cec93df24c9f58917c364ac20a Mon Sep 17 00:00:00 2001 From: Alanah Jonas <156101954+alanahjonas95@users.noreply.github.com> Date: Fri, 27 Feb 2026 12:24:45 +0000 Subject: [PATCH 2/3] add args to pairwise --- R/ard_pairwise.R | 6 ++++++ tests/testthat/test-ard_pairwise.R | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/R/ard_pairwise.R b/R/ard_pairwise.R index 28b4440e7..23ab5516f 100644 --- a/R/ard_pairwise.R +++ b/R/ard_pairwise.R @@ -90,6 +90,12 @@ ard_pairwise <- function(data, variable, .f, include = NULL) { } ) + # Assign attributes to the list of ARDs + attr(lst_ard, "args") <- list( + variable = variable, + include = include + ) + # return result -------------------------------------------------------------- lst_ard } diff --git a/tests/testthat/test-ard_pairwise.R b/tests/testthat/test-ard_pairwise.R index a70ec6431..7fac15b0b 100644 --- a/tests/testthat/test-ard_pairwise.R +++ b/tests/testthat/test-ard_pairwise.R @@ -116,3 +116,15 @@ test_that("ard_pairwise(include) messaging", { ) ) }) + +test_that("ard_pairwise() attaches 'args' attribute", { + res <- ard_pairwise( + data = mtcars, + variable = "am", + .f = \(x) ard_summary(x, variables = "mpg") + ) + + args <- attr(res, "args") + expect_equal(args$variable, "am") + expect_equal(args$include, c(0, 1)) +}) From 357faad8f2398acf370a06e62610755f772685d6 Mon Sep 17 00:00:00 2001 From: Alanah Jonas <156101954+alanahjonas95@users.noreply.github.com> Date: Tue, 3 Mar 2026 09:30:13 +0000 Subject: [PATCH 3/3] run styler --- R/ard_strata.R | 2 +- tests/testthat/test-ard_strata.R | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/R/ard_strata.R b/R/ard_strata.R index 5f7ccaee7..530f9e3e2 100644 --- a/R/ard_strata.R +++ b/R/ard_strata.R @@ -116,7 +116,7 @@ ard_strata <- function(.data, .by = NULL, .strata = NULL, .f, ...) { # append attributes ---------------------------------------------------------- attr(ard_full, "args") <- list( - by =.by, + by = .by, strata = .strata ) diff --git a/tests/testthat/test-ard_strata.R b/tests/testthat/test-ard_strata.R index 6cb121342..8f17fa767 100644 --- a/tests/testthat/test-ard_strata.R +++ b/tests/testthat/test-ard_strata.R @@ -95,5 +95,4 @@ test_that("ard_strata() attaches 'args' attribute", { res_by <- ard_strata(ADSL, .by = ARM, .f = ~ ard_summary(.x, variables = AGE)) expect_equal(attr(res_by, "args")$by, "ARM") expect_equal(attr(res_by, "args")$strata, character(0)) - })