Skip to content

Commit

Permalink
Merge branch 'main' into 2157_update_standalone@main
Browse files Browse the repository at this point in the history
  • Loading branch information
ayogasekaram authored Feb 27, 2025
2 parents c6ae400 + 83b15a1 commit b3de3a0
Show file tree
Hide file tree
Showing 30 changed files with 185 additions and 76 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: gtsummary
Title: Presentation-Ready Data Summary and Analytic Result Tables
Version: 2.1.0.9000
Version: 2.1.0.9003
Authors@R: c(
person("Daniel D.", "Sjoberg", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-0862-2018")),
Expand Down
10 changes: 9 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# gtsummary (development version)

* The `remove_*()` family of functions default argument values have been updated to remove _all_ footnotes, source notes, abbreviations, column merging, bold and italic styling by default, so the users are not longer required to remove, for example, one source note at a time. The one exception is `remove_spanning_headers()`, which will remove the first level spanning headers be default. (#2161)

* The `tbl_strata_nested_stack(quiet)` argument documentation was updated. (#2164)

* Corrected the class of objects returned from `tbl_strata_nested_stack()`.

* Corrected bug in `tbl_strata_nested_stack()` when the strata variable had a single level. Pervasively, the indentation of the single strata level was not correct.

# gtsummary 2.1.0

### New Features and Functions
Expand Down Expand Up @@ -752,7 +760,7 @@ Updates to address regressions in the v2.0.0 release:

* Added a standardized mean difference method for `tbl_svysummary()` tables.

* Added `tbl_strata(.stack_group_header=)` argument to include/exclude the headers when tables are combined with `tbl_stack()`
* Added `tbl_strata(.stack_group_header=)` argument to include/exclude the headers when tables are combined with `tbl_stack()`.

* Added `tbl_strata(.quiet=)` argument.

Expand Down
4 changes: 1 addition & 3 deletions R/deprecated.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
NULL

# "soft" deprecation for 6 months: (Sys.Date() - lubridate::dmonths(6)) |> as.Date()
# v2.1.0 2025-02-19
# v2.0.2 2024-09-05
# v2.0.1 2024-08-01
# v2.0.0 2024-07-23
Expand All @@ -23,9 +24,6 @@ NULL
# v1.6.2 2022-09-30
# v1.6.1 2022-06-22
# v1.6.0 2022-04-25
# v1.5.2 2022-01-29
# v1.5.1 2022-01-20
# v1.5.0 2021-10-16


# v1.6.1 ----------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion R/modify.R
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ modify_spanning_header <- function(x, ..., text_interpret = c("md", "html"),

#' @name modify
#' @export
remove_spanning_header <- function(x, columns, level = 1L) {
remove_spanning_header <- function(x, columns = everything(), level = 1L) {
set_cli_abort_call()
updated_call_list <- c(x$call_list, list(remove_spanning_header = match.call()))

Expand Down
15 changes: 12 additions & 3 deletions R/modify_abbreviation.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#'
#' @inheritParams modify_footnote2
#' @param abbreviation (`string`)\cr
#' a string
#' a string. In `remove_abbreviation()`, the default value is `NULL`, which
#' will remove all abbreviation source notes.
#'
#' @return Updated gtsummary object
#' @name modify_abbreviation
Expand Down Expand Up @@ -49,13 +50,21 @@ modify_abbreviation <- function(x, abbreviation, text_interpret = c("md", "html"

#' @export
#' @rdname modify_abbreviation
remove_abbreviation <- function(x, abbreviation) {
remove_abbreviation <- function(x, abbreviation = NULL) {
set_cli_abort_call()
updated_call_list <- c(x$call_list, list(modify_footnote_body = match.call()))

# check inputs ---------------------------------------------------------------
check_class(x, "gtsummary")
check_string(abbreviation)
check_string(abbreviation, allow_empty = TRUE)

# remove all abbreviations if abbreviation=NULL ------------------------------
if (is_empty(abbreviation)) {
x$table_styling$abbreviation <- x$table_styling$abbreviation[0,]
return(x)
}

# check passed abbreviations for validity
if (nrow(x$table_styling$abbreviation) == 0L) {
cli::cli_abort("There are no abbreviations to remove.", call = get_cli_abort_call())
}
Expand Down
5 changes: 3 additions & 2 deletions R/modify_bold_italic.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Modify Bold and Italic
#'
#' Add or remove bold and italic styling to a cell in a table.
#' By default, the remove functions will remove all bold/italic styling.
#'
#' @inheritParams modify_footnote2
#'
Expand Down Expand Up @@ -45,7 +46,7 @@ modify_bold <- function(x, columns, rows) {

#' @rdname modify_bold_italic
#' @export
remove_bold <- function(x, columns, rows) {
remove_bold <- function(x, columns = everything(), rows = TRUE) {
set_cli_abort_call()

# check inputs ---------------------------------------------------------------
Expand Down Expand Up @@ -89,7 +90,7 @@ modify_italic <- function(x, columns, rows) {

#' @rdname modify_bold_italic
#' @export
remove_italic <- function(x, columns, rows) {
remove_italic <- function(x, columns = everything(), rows = TRUE) {
set_cli_abort_call()

# check inputs ---------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion R/modify_column_merge.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ modify_column_merge <- function(x, pattern, rows = NULL) {

#' @export
#' @name modify_column_merge
remove_column_merge <- function(x, columns) {
remove_column_merge <- function(x, columns = everything()) {
set_cli_abort_call()
# check inputs ---------------------------------------------------------------
check_class(x, "gtsummary")
Expand Down
8 changes: 4 additions & 4 deletions R/modify_footnote.R
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ modify_footnote_spanning_header <- function(x, footnote, columns,

#' @export
#' @rdname modify_footnote2
remove_footnote_header <- function(x, columns) {
remove_footnote_header <- function(x, columns = everything()) {
set_cli_abort_call()
updated_call_list <- c(x$call_list, list(remove_footnote_header = match.call()))

Expand Down Expand Up @@ -197,7 +197,7 @@ remove_footnote_header <- function(x, columns) {

#' @export
#' @rdname modify_footnote2
remove_footnote_body <- function(x, columns, rows) {
remove_footnote_body <- function(x, columns = everything(), rows = TRUE) {
set_cli_abort_call()
updated_call_list <- c(x$call_list, list(remove_footnote_body = match.call()))

Expand Down Expand Up @@ -227,13 +227,13 @@ remove_footnote_body <- function(x, columns, rows) {

#' @export
#' @rdname modify_footnote2
remove_footnote_spanning_header <- function(x, columns, level) {
remove_footnote_spanning_header <- function(x, columns = everything(), level = 1L) {
set_cli_abort_call()
updated_call_list <- c(x$call_list, list(remove_footnote_body = match.call()))

# check inputs ---------------------------------------------------------------
check_class(x, "gtsummary")
check_scalar_integerish(level)
check_scalar_integerish(level, allow_empty = NULL)
if (level < 1) {
cli::cli_abort(
"The {.arg level} argument must be a positive integer.",
Expand Down
4 changes: 2 additions & 2 deletions R/modify_source_note.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#' @param source_note_id (`integers`)\cr
#' Integers specifying the ID of the source note to remove.
#' Source notes are indexed sequentially at the time of creation.
#' Default is `NULL`, which removes all source notes.
#' @inheritParams modify
#'
#' @details
Expand Down Expand Up @@ -62,13 +63,12 @@ modify_source_note <- function(x, source_note, text_interpret = c("md", "html"))

#' @export
#' @rdname modify_source_note
remove_source_note <- function(x, source_note_id) {
remove_source_note <- function(x, source_note_id = NULL) {
set_cli_abort_call()
updated_call_list <- c(x$call_list, list(remove_source_note = match.call()))

# check inputs ---------------------------------------------------------------
check_not_missing(x)
check_not_missing(source_note_id)
check_class(x, "gtsummary")
check_integerish(source_note_id, allow_empty = TRUE)

Expand Down
21 changes: 0 additions & 21 deletions R/tbl_strata.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#' - `N` Overall N
#'
#' The evaluated value of `.header` is also available within `tbl_strata2(.tbl_fun)`
#' @param .stack_group_header `r lifecycle::badge("deprecated")`
#' @param .quiet `r lifecycle::badge("deprecated")`
#'
#' @section Tips:
Expand Down Expand Up @@ -101,7 +100,6 @@ tbl_strata <- function(data,
.combine_args = NULL,
.header =
ifelse(.combine_with == "tbl_merge", "**{strata}**", "{strata}"),
.stack_group_header = NULL,
.quiet = NULL) {
set_cli_abort_call()

Expand All @@ -128,7 +126,6 @@ tbl_strata <- function(data,
.combine_with = .combine_with,
.combine_args = .combine_args,
.header = .header,
.stack_group_header = .stack_group_header,
.parent_fun = "tbl_strata"
)
}
Expand All @@ -144,7 +141,6 @@ tbl_strata2 <- function(data,
.combine_args = NULL,
.header =
ifelse(.combine_with == "tbl_merge", "**{strata}**", "{strata}"),
.stack_group_header = NULL,
.quiet = TRUE) {
set_cli_abort_call()

Expand All @@ -171,7 +167,6 @@ tbl_strata2 <- function(data,
.combine_with = .combine_with,
.combine_args = .combine_args,
.header = .header,
.stack_group_header = .stack_group_header,
.parent_fun = "tbl_strata2"
)
}
Expand All @@ -184,7 +179,6 @@ tbl_strata_internal <- function(data,
.combine_with = c("tbl_merge", "tbl_stack"),
.combine_args = NULL,
.header = NULL,
.stack_group_header = NULL,
.parent_fun) {
check_string(.header)

Expand Down Expand Up @@ -245,21 +239,6 @@ tbl_strata_internal <- function(data,
)
)

# deprecated argument --------------------------------------------------------
if (!is.null(.stack_group_header) && isTRUE(.combine_with == "tbl_stack")) {
lifecycle::deprecate_stop(
when = "1.5.1",
what = "gtsummary::tbl_strata(.stack_group_header)",
details =
switch(isFALSE(.stack_group_header),
glue(
"Use the following instead:\n",
"gtsummary::tbl_strata(.combine_args = list(group_header = NULL))"
)
)
)
}

# combining tbls -------------------------------------------------------------
.combine_args <-
# default arguments
Expand Down
9 changes: 7 additions & 2 deletions R/tbl_strata_nested_stack.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#' Stratified Nested Stacking
#'
#' @description
#' This function stratifies your data frame, builds gtsummary tables, and
#' stacks the resulting tables in a nested style. The underlying functionality
#' is similar to `tbl_strata()`, except the resulting tables are nested or indented
#' within each group.
#'
#' **NOTE**: The header from the first table is used for the final table. Oftentimes,
#' this header will include incorrect Ns and _must be updated._
#'
#' @inheritParams tbl_stack
#' @inheritParams tbl_strata
#' @param data (`data.frame`)\cr
#' a data frame
Expand Down Expand Up @@ -155,7 +160,7 @@ tbl_strata_nested_stack <- function(data, strata, .tbl_fun, ..., row_header = "{
tbl <- tbl_stack(tbls = tbls, quiet = quiet)

# cycle over the depth and indenting nesting headers
for (d in seq_len(nrow(df_headers) - 1L)) {
for (d in seq_along(strata)) {
tbl <- tbl |>
modify_column_indent(
columns = all_of(first_non_hidden_col),
Expand All @@ -169,7 +174,7 @@ tbl_strata_nested_stack <- function(data, strata, .tbl_fun, ..., row_header = "{
tbl$inputs = list(tbl_row_split = func_inputs)
tbl$tbls <- NULL
tbl |>
structure(class = c("tbl_row_split", "gtsummary"))
structure(class = c("tbl_strata_nested_stack", "tbl_stack", "gtsummary"))
}


Expand Down
2 changes: 1 addition & 1 deletion man/add_glance.Rd

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

2 changes: 1 addition & 1 deletion man/modify.Rd

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

5 changes: 3 additions & 2 deletions man/modify_abbreviation.Rd

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

5 changes: 3 additions & 2 deletions man/modify_bold_italic.Rd

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

2 changes: 1 addition & 1 deletion man/modify_column_merge.Rd

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

6 changes: 3 additions & 3 deletions man/modify_footnote2.Rd

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

5 changes: 3 additions & 2 deletions man/modify_source_note.Rd

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

Loading

0 comments on commit b3de3a0

Please sign in to comment.