Skip to content

Commit

Permalink
Fix pct bug in tabulate_rsp_subgroups when risk difference column…
Browse files Browse the repository at this point in the history
… is added (#1387)

Fixes #1386
  • Loading branch information
edelarua authored Jan 31, 2025
1 parent a11af4b commit 12ab34e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Bug Fixes
* Fixed bug in `a_count_patients_with_flags()` preventing select custom label and indentation specification formats from being applied.
* Fixed bug in `tabulate_rsp_subgroups` and `tabulate_survival_subgroups` preventing the `pct` option from having an effect when adding a risk difference column.

### Miscellaneous
* Removed internal function `ungroup_stats()` and replaced its usage with the `get_*_from_stats()` functions.
Expand Down
3 changes: 2 additions & 1 deletion R/response_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ tabulate_rsp_subgroups <- function(lyt,
x = as.list(.data[[arm_cols[1]]]),
y = as.list(.data[[arm_cols[2]]]),
N_x = .data[[arm_cols[3]]],
N_y = .data[[arm_cols[4]]]
N_y = .data[[arm_cols[4]]],
pct = riskdiff$pct
)
) %>%
dplyr::select(-dplyr::all_of(arm_cols))
Expand Down
3 changes: 2 additions & 1 deletion R/survival_duration_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ tabulate_survival_subgroups <- function(lyt,
x = as.list(.data[[arm_cols[1]]]),
y = as.list(.data[[arm_cols[2]]]),
N_x = .data[[arm_cols[3]]],
N_y = .data[[arm_cols[4]]]
N_y = .data[[arm_cols[4]]],
pct = riskdiff$pct
)
) %>%
dplyr::select(-dplyr::all_of(arm_cols))
Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test-response_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,23 @@ testthat::test_that("tabulate_rsp_subgroups riskdiff argument works as expected"

res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)

# pct works
result2 <- basic_table() %>%
tabulate_rsp_subgroups(
df = df,
vars = c("n", "prop", "n_tot", "or", "ci", "pval"),
riskdiff = control_riskdiff(
arm_x = levels(df$prop$arm)[1],
arm_y = levels(df$prop$arm)[2],
pct = FALSE
)
)

testthat::expect_equal(
cell_values(result2)[[1]][[9]],
cell_values(result)[[1]][[9]] / 100
)
})

testthat::test_that("tabulate_rsp_subgroups pval statistic warning works as expected", {
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-survival_duration_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,17 @@ testthat::test_that("tabulate_survival_subgroups riskdiff argument works as expe

res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)

# pct works
result2 <- basic_table() %>%
tabulate_survival_subgroups(
df,
time_unit = adtte$AVALU[1],
riskdiff = control_riskdiff(pct = FALSE)
)

testthat::expect_equal(
cell_values(result2)[[1]][[8]],
cell_values(result)[[1]][[8]] / 100
)
})

0 comments on commit 12ab34e

Please sign in to comment.