Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecate_warn instead of stop for create_afun* #1034

Merged
merged 8 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# tern 0.8.5.9013

### Miscellaneous
* Fix swapped descriptions for the `.N_row` and `.N_col` parameters.
* Fix bug in `analyze_vars_in_cols` when categorical data was used.
* Removal of internal calls to `df_explicit_na`. Changes in `NA` values should happen externally to `tern` functions, depending on users' needs.

### Enhancements
* Refactored `a_summary` to no longer use helper function `create_afun_summary`.
* Refactored `summarize_vars` and `compare_vars` to use refactored `a_summary`.
* Created new internal helper functions `ungroup_stats` to ungroup statistics calculated for factor variables, and `a_summary_internal` to perform calculations for `a_summary`.

### Miscellaneous
* Fix swapped descriptions for the `.N_row` and `.N_col` parameters.
* Fix bug in `analyze_vars_in_cols` when categorical data was used.
* Removal of internal calls to `df_explicit_na`. Changes in `NA` values should happen externally to `tern` functions, depending on users' needs.
* Reinstated correct soft deprecation for `create_afun_summary` and `create_afun_compare`.

# tern 0.8.5

### Enhancements
Expand Down
19 changes: 17 additions & 2 deletions R/analyze_variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -612,11 +612,26 @@ a_summary.numeric <- function(x,
#'
#' @export
create_afun_summary <- function(.stats, .formats, .labels, .indent_mods) {
lifecycle::deprecate_stop(
"0.8.3",
lifecycle::deprecate_warn(
"0.8.5.9010",
"create_afun_summary()",
details = "Please use a_summary() directly instead."
)
function(x,
.ref_group,
.in_ref_col,
...,
.var) {
a_summary(x,
.stats = .stats,
.formats = .formats,
.labels = .labels,
.indent_mods = .indent_mods,
.ref_group = .ref_group,
.in_ref_col = .in_ref_col,
.var = .var, ...
)
}
}

#' @describeIn analyze_variables Layout-creating function which can take statistics function arguments
Expand Down
20 changes: 18 additions & 2 deletions R/compare_variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,27 @@ create_afun_compare <- function(.stats = NULL,
.formats = NULL,
.labels = NULL,
.indent_mods = NULL) {
lifecycle::deprecate_stop(
"0.8.3",
lifecycle::deprecate_warn(
"0.8.5.9010",
"create_afun_compare()",
details = "Please use a_summary(compare = TRUE) directly instead."
)
function(x,
.ref_group,
.in_ref_col,
...,
.var) {
a_summary(x,
compare = TRUE,
.stats = .stats,
.formats = .formats,
.labels = .labels,
.indent_mods = .indent_mods,
.ref_group = .ref_group,
.in_ref_col = .in_ref_col,
.var = .var, ...
)
}
}

#' @describeIn compare_variables Layout-creating function which can take statistics function arguments
Expand Down
25 changes: 23 additions & 2 deletions tests/testthat/test-analyze_variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,27 @@ testthat::test_that("analyze_vars 'na_level' argument works as expected", {

# Deprecated functions

testthat::test_that("create_afun_summary returns error message", {
testthat::expect_error(create_afun_summary())
testthat::test_that("create_afun_summary creates an `afun` that works and throws a warning", {
testthat::expect_warning(afun <- create_afun_summary(
.stats = c("n", "count_fraction", "median", "range", "mean_ci"),
.formats = c(median = "xx."),
.labels = c(median = "My median"),
.indent_mods = c(median = 1L)
))
dta_test <- data.frame(
USUBJID = rep(1:6, each = 3),
PARAMCD = rep("lab", 6 * 3),
AVISIT = rep(paste0("V", 1:3), 6),
ARM = rep(LETTERS[1:3], rep(6, 3)),
AVAL = c(9:1, rep(NA, 9)),
stringsAsFactors = TRUE
)

l <- basic_table() %>%
split_cols_by(var = "ARM") %>%
split_rows_by(var = "AVISIT") %>%
analyze(vars = c("AVAL", "ARM"), afun = afun)

# From visual inspection it works as before, same output
testthat::expect_silent(result <- build_table(l, df = dta_test))
})
2 changes: 1 addition & 1 deletion tests/testthat/test-compare_variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ testthat::test_that("compare_vars 'na_level' argument works as expected", {
# Deprecated functions

testthat::test_that("create_afun_compare returns error message", {
testthat::expect_error(create_afun_compare())
testthat::expect_warning(create_afun_compare()) # before It was not covered directly
})

testthat::test_that("a_compare returns correct output and warning message", {
Expand Down