Skip to content

Commit

Permalink
Adding messaging for mixed-type tbl_ard_summary(by) variables (#2134)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddsjoberg authored Feb 3, 2025
1 parent d4beb68 commit 2221eb0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions R/tbl_ard_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ tbl_ard_summary <- function(cards,
call = get_cli_abort_call()
)
}
# check consistent types for the by variable
if (!is_empty(by)) {
# test if any of the levels have inconsistent classes. making this a message, because it won't always result in a bad table
if (some(compact(cards$group1_level), \(x) is_empty(intersect(class(x), class(compact(cards$group1_level)[[1]]))))) {
cli::cli_inform(
c("Levels of the {.code tbl_ard_summary(by)} variable do not have a consistent S3 class.",
"i" = "This may cause an unexpected or incorrect layout in the final table.")
)
}
}

# check the missing stats are available
if (missing != "no") {
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-tbl_ard_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,16 @@ test_that("tbl_ard_summary() non-standard ARDs (ie not 'continuous', 'categorica
as.data.frame()
)
})

# addressed Issue #2000
test_that("tbl_ard_summary(by) mixed-type messaging", {
expect_message(
cards::bind_ard(
cards::ard_continuous(trial, variables = age, by = trt),
cards::ard_continuous(trial |> dplyr::mutate(trt = factor(trt)), variables = marker, by = trt)
) |>
tbl_ard_summary(by = trt),
"Levels of the.*variable do not have a consistent S3 class."
)
})

0 comments on commit 2221eb0

Please sign in to comment.