Skip to content

Commit

Permalink
added argument to ard_stack for total n
Browse files Browse the repository at this point in the history
  • Loading branch information
ddsjoberg committed Jun 13, 2024
1 parent d98a935 commit 2b805a2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
14 changes: 13 additions & 1 deletion R/ard_stack.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
#' @param .shuffle (`logical`)\cr
#' logical indicating whether to perform `shuffle_ard()` on the final result.
#' Default is `FALSE`.
#' @param .total_n (`logical`)\cr
#' logical indicating whether to include of `ard_total_n()` in the returned ARD.
#'
#' @return a transformed ARD data frame (of class 'card' if `.shuffle = FALSE`)
#'
#' @export
#'
#' @examples
#' ard_stack(
#' data = ADSL,
Expand All @@ -55,6 +57,7 @@ ard_stack <- function(data,
.overall = FALSE,
.missing = FALSE,
.attributes = FALSE,
.total_n = FALSE,
.shuffle = FALSE) {
set_cli_abort_call()

Expand All @@ -69,6 +72,7 @@ ard_stack <- function(data,
check_scalar_logical(.missing)
check_scalar_logical(.attributes)
check_scalar_logical(.shuffle)
check_scalar_logical(.total_n)

if (is_empty(.by) && isTRUE(.overall)) {
cli::cli_inform(
Expand Down Expand Up @@ -128,6 +132,14 @@ ard_stack <- function(data,
)
}

# total n
if (isTRUE(.total_n)) {
ard_full <- bind_ard(
ard_full,
ard_total_n(data)
)
}

# order
ard_full <- tidy_ard_row_order(ard_full)

Expand Down
4 changes: 4 additions & 0 deletions man/ard_stack.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions tests/testthat/test-ard_stack.R
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,19 @@ test_that("ard_stack() .shuffle argument", {
)
})

test_that("ard_stack() adding total N", {
expect_equal(
ard_stack(
mtcars,
.by = am,
ard_continuous(variables = mpg),
.total_n = TRUE
) |>
tail(n = 1) |>
dplyr::select(-all_ard_groups(), -all_ard_variables("levels")),
ard_total_n(mtcars)
)
})

test_that("ard_stack() works with namespaced functions", {
expect_equal(
Expand Down

0 comments on commit 2b805a2

Please sign in to comment.