diff --git a/R/add_p.R b/R/add_p.R index d403f660d..12a11fa05 100644 --- a/R/add_p.R +++ b/R/add_p.R @@ -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", diff --git a/R/add_p.tbl_continuous.R b/R/add_p.tbl_continuous.R index f3d2cb765..d7914c95a 100644 --- a/R/add_p.tbl_continuous.R +++ b/R/add_p.tbl_continuous.R @@ -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), diff --git a/R/tbl_ard_summary.R b/R/tbl_ard_summary.R index 73d54b7be..547018ac0 100644 --- a/R/tbl_ard_summary.R +++ b/R/tbl_ard_summary.R @@ -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 #' diff --git a/R/tbl_strata.R b/R/tbl_strata.R index 83341d23f..ddfe5df06 100644 --- a/R/tbl_strata.R +++ b/R/tbl_strata.R @@ -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 diff --git a/man/add_p.tbl_continuous.Rd b/man/add_p.tbl_continuous.Rd index 13fa7ef2a..33aedecdb 100644 --- a/man/add_p.tbl_continuous.Rd +++ b/man/add_p.tbl_continuous.Rd @@ -51,9 +51,15 @@ Default is \code{NULL}. See \link{tests} for methods that utilize the \code{grou Add p-values } \examples{ -\dontshow{if (gtsummary:::is_pkg_installed("cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if ((identical(Sys.getenv("NOT_CRAN"), "true") || identical(Sys.getenv("IN_PKGDOWN"), "true")) && gtsummary:::is_pkg_installed("cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +# 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") \dontshow{\}) # examplesIf} } diff --git a/man/tbl_ard_summary.Rd b/man/tbl_ard_summary.Rd index 8edbc1e29..cf6ffa7f8 100644 --- a/man/tbl_ard_summary.Rd +++ b/man/tbl_ard_summary.Rd @@ -70,6 +70,21 @@ The \code{tbl_ard_summary()} function tables descriptive statistics for continuous, categorical, and dichotomous variables. The functions accepts an ARD object. } +\details{ +There are three types of additional data that can be included in the ARD to +improve the default appearance of the table. +\enumerate{ +\item \strong{Attributes}: When attributes are included, the default labels will be +the variable labels, when available. Attributes can be included in an ARD +with \code{cards::ard_attributes()} or \code{ard_stack(.attributes = TRUE)}. +\item \strong{Missing}: When missing results are included, users can include +missing counts or rates for variables with \code{tbl_ard_summary(missing = c("ifany", "always"))}. +The missing statistics can be included in an ARD with +\code{cards::ard_missing()} or \code{ard_stack(.missing = TRUE)}. +\item \strong{Total N}: The total N is saved internally when available, and it can +be calculated with \code{cards::ard_total_n()} or \code{ard_stack(.total_n = TRUE)}. +} +} \examples{ library(cards) diff --git a/man/tbl_strata.Rd b/man/tbl_strata.Rd index 807b38950..b5df493bf 100644 --- a/man/tbl_strata.Rd +++ b/man/tbl_strata.Rd @@ -129,8 +129,7 @@ trial |> 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**") } diff --git a/tests/testthat/test-add_p.tbl_continuous.R b/tests/testthat/test-add_p.tbl_continuous.R index 0a5376fdf..91154dde3 100644 --- a/tests/testthat/test-add_p.tbl_continuous.R +++ b/tests/testthat/test-add_p.tbl_continuous.R @@ -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*" + ) +})