Skip to content

Commit

Permalink
Merge branch 'main' into 2062-flextable-multi-row-col-footnote
Browse files Browse the repository at this point in the history
  • Loading branch information
Melkiades authored Nov 21, 2024
2 parents 4a34d9e + 25c739d commit 5e7cd55
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 9 deletions.
2 changes: 1 addition & 1 deletion R/add_p.R
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ calculate_and_add_test_results <- function(x, include, group = NULL, test.args,
if (!is.null(lst_captured_results[["result"]])) return(lst_captured_results[["result"]]) # styler: off
# otherwise, construct a {cards}-like object with error
dplyr::tibble(
group1 = x$inputs$by,
group1 = switch(!is_empty(x$inputs$by), x$inputs$by),
variable = variable,
stat_name = switch(calling_fun,
"add_p" = "p.value",
Expand Down
10 changes: 8 additions & 2 deletions R/add_p.tbl_continuous.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@
#' @export
#' @return 'tbl_continuous' object
#'
#' @examplesIf gtsummary:::is_pkg_installed("cardx")
#' @examplesIf (identical(Sys.getenv("NOT_CRAN"), "true") || identical(Sys.getenv("IN_PKGDOWN"), "true")) && gtsummary:::is_pkg_installed("cardx")
#' # Example 1 ----------------------------------
#' trial |>
#' tbl_continuous(variable = age, by = trt, include = grade) |>
#' add_p()
#' add_p(pvalue_fun = label_style_pvalue(digits = 2))
#'
#' # Example 2 ----------------------------------
#' trial |>
#' tbl_continuous(variable = age, include = grade) |>
#' add_p(test = everything() ~ "kruskal.test")
add_p.tbl_continuous <- function(x,
test = NULL,
pvalue_fun = label_style_pvalue(digits = 1),
Expand Down
16 changes: 16 additions & 0 deletions R/tbl_ard_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@
#' Default is `FALSE`.
#' @inheritParams tbl_summary
#'
#' @details
#' There are three types of additional data that can be included in the ARD to
#' improve the default appearance of the table.
#'
#' 1. **Attributes**: When attributes are included, the default labels will be
#' the variable labels, when available. Attributes can be included in an ARD
#' with `cards::ard_attributes()` or `ard_stack(.attributes = TRUE)`.
#'
#' 2. **Missing**: When missing results are included, users can include
#' missing counts or rates for variables with `tbl_ard_summary(missing = c("ifany", "always"))`.
#' The missing statistics can be included in an ARD with
#' `cards::ard_missing()` or `ard_stack(.missing = TRUE)`.
#'
#' 3. **Total N**: The total N is saved internally when available, and it can
#' be calculated with `cards::ard_total_n()` or `ard_stack(.total_n = TRUE)`.
#'
#' @return a gtsummary table of class `"tbl_ard_summary"`
#' @export
#'
Expand Down
3 changes: 1 addition & 2 deletions R/tbl_strata.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@
#' modify_header(stat_0 = "**Rate (95% CI)**") |>
#' modify_footnote(stat_0 = NA),
#' .combine_with = "tbl_stack",
#' .combine_args = list(group_header = NULL),
#' .quiet = TRUE
#' .combine_args = list(group_header = NULL)
#' ) |>
#' modify_caption("**Response Rate by Grade**")
NULL
Expand Down
10 changes: 8 additions & 2 deletions man/add_p.tbl_continuous.Rd

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

15 changes: 15 additions & 0 deletions man/tbl_ard_summary.Rd

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

3 changes: 1 addition & 2 deletions man/tbl_strata.Rd

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

8 changes: 8 additions & 0 deletions tests/testthat/test-add_p.tbl_continuous.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,11 @@ test_that("add_p.tbl_continuous(group) works", {
unlist(compare)
)
})

test_that("add_p.tbl_continuous() messaging", {
expect_message(
tbl_continuous(trial, variable = age, include = grade) |>
add_p(test = ~"lme4"),
"*argument cannot be missing*"
)
})

0 comments on commit 5e7cd55

Please sign in to comment.