Skip to content

Commit

Permalink
Updating deprecation message for modify_*() functions (#1802)
Browse files Browse the repository at this point in the history
* progress

* updates

* Update test-modify_header.R
  • Loading branch information
ddsjoberg committed Jul 6, 2024
1 parent e9af78a commit 990a396
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 6 deletions.
2 changes: 1 addition & 1 deletion R/add_difference.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ add_difference <- function(x, ...) {
#' Default is
#' `list(c(all_continuous(), all_categorical(FALSE)) ~ label_style_sigfig(), all_categorical() ~ \(x) paste0(style_sigfig(x, scale = 100), "%"))`
#' @param conf.level (`numeric`)\cr
#' a scalar in `⁠(0, 1`)⁠ indicating the confidence level. Default is 0.95
#' a scalar in the interval `(0, 1)` indicating the confidence level. Default is 0.95
#' @inheritParams add_p.tbl_summary
#'
#' @export
Expand Down
2 changes: 1 addition & 1 deletion R/add_difference.tbl_svysummary.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#' Default is
#' `list(c(all_continuous(), all_categorical(FALSE)) ~ label_style_sigfig(), all_categorical() ~ \(x) paste0(style_sigfig(x, scale = 100), "%"))`
#' @param conf.level (`numeric`)\cr
#' a scalar in `⁠(0, 1`)⁠ indicating the confidence level. Default is 0.95
#' a scalar in the interval `(0, 1)` indicating the confidence level. Default is 0.95
#' @inheritParams add_p.tbl_summary
#'
#' @export
Expand Down
8 changes: 6 additions & 2 deletions R/modify.R
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,19 @@ show_header_names <- function(x = NULL, include_example = TRUE, quiet = NULL) {

.deprecate_modify_update_and_quiet_args <- function(dots, update, quiet, calling_fun) {
# deprecated arguments
if (!missing(update)) {
if (!missing(update) || (!is_empty(dots) && is.list(dots[[1]]))) {
lifecycle::deprecate_warn(
"2.0.0", glue("gtsummary::{calling_fun}(update=)"),
details =
glue("Use `{calling_fun}(...)` input instead.
Dynamic dots allow for syntax like `{calling_fun}(!!!list(...))`."),
env = get_cli_abort_call()
)
dots <- c(dots, update)

if (!is_empty(dots) && is.list(dots[[1]])) dots <- c(dots[-1], dots[[1]]) # styler: off
if (!missing(update)) dots <- c(dots, update) # styler: off

dots
}
if (!missing(quiet)) {
lifecycle::deprecate_warn(
Expand Down
2 changes: 1 addition & 1 deletion man/add_difference.tbl_summary.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/add_difference.tbl_svysummary.Rd

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

33 changes: 33 additions & 0 deletions tests/testthat/test-modify_header.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,49 @@

# first, testing deprecation
test_that("modify_header(update,quiet) are deprecated", {
lifecycle::expect_deprecated(
tbl_summary(trial, include = marker) |>
modify_header(list(label = "Variable"))
)

# THIS ONE FAILS LOCALLY UNLESS I RUN ALL THE TESTS WITH THE 'Test' BUTTON
lifecycle::expect_deprecated(
tbl_summary(trial, include = marker) |>
modify_header(update = list(label = "Variable"))
)

lifecycle::expect_deprecated(
tbl_summary(trial, include = marker) |>
modify_header(quiet = FALSE)
)
})


test_that("modify_header(update) are deprecated and still work", {
withr::local_options(lifecycle_verbosity = "quiet")
expect_equal(
tbl_summary(trial, include = marker) |>
modify_header(list(label = "Variable")) |>
getElement("table_styling") |>
getElement("header"),
tbl_summary(trial, include = marker) |>
modify_header(label = "Variable") |>
getElement("table_styling") |>
getElement("header")
)

expect_equal(
tbl_summary(trial, include = marker) |>
modify_header(update = list(label = "Variable")) |>
getElement("table_styling") |>
getElement("header"),
tbl_summary(trial, include = marker) |>
modify_header(label = "Variable") |>
getElement("table_styling") |>
getElement("header")
)
})

test_that("modify_header(update) deprecated argument still works", {
withr::local_options(lifecycle_verbosity = "quiet")
expect_equal(
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-show_header_names.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_on_os("windows")

test_that("show_header_names() works", {
expect_snapshot(
tbl_summary(trial, include = age, by = trt, missing = "no") |>
Expand Down

0 comments on commit 990a396

Please sign in to comment.