Skip to content

Commit

Permalink
Merge branch 'main' into 903_check_tests@96_exporter_pagination_migra…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
shajoezhu authored May 17, 2023
2 parents a8c4566 + 13c2445 commit e23f37f
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 10 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

### Bug Fixes
* Fixed missing label for `TRTEDTM` in `tern` datasets.
* Fixed improper implementation of `na_level` argument in `summarize_vars` preventing it from having an effect.

### Enhancements
* Added `section_div` and `na_level` (`na_str`) to `summarize_vars`.
Expand All @@ -13,6 +14,7 @@
* Added new "Analyze Functions" and "Summarize Functions" overview pages.
* Moved all KM plot documentation to the `g_km` function.
* Added `a_count_patients_sum_exposure` for new analyze function `analyze_patients_exposure_in_cols` and `summarize_patients_exposure_in_cols`.
* Added more informative error when the user selects an invalid method for unstratified analyses in `s_proportion_diff`.

### Miscellaneous
* Implemented the `lubridate` package for date variables in `tern` datasets.
Expand Down
9 changes: 9 additions & 0 deletions R/prop_diff.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ NULL
#' @return
#' * `s_proportion_diff()` returns a named list of elements `diff` and `diff_ci`.
#'
#' @note When performing an unstratified analysis, methods `"cmh"`, `"strat_newcombe"`, and `"strat_newcombecc"` are
#' not permitted.
#'
#' @examples
#' # Summary
#'
Expand Down Expand Up @@ -65,6 +68,12 @@ s_proportion_diff <- function(df,
),
weights_method = "cmh") {
method <- match.arg(method)
if (is.null(variables$strata) && checkmate::test_subset(method, c("cmh", "strat_newcombe", "strat_newcombecc"))) {
stop(paste(
"When performing an unstratified analysis, methods 'cmh', 'strat_newcombe', and 'strat_newcombecc' are not",
"permitted. Please choose a different method."
))
}
y <- list(diff = "", diff_ci = "")

if (!.in_ref_col) {
Expand Down
5 changes: 2 additions & 3 deletions R/summarize_variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ s_summary.factor <- function(x,
#' @param verbose (`logical`)\cr Defaults to `TRUE`, which prints out warnings and messages. It is mainly used
#' to print out information about factor casting.
#'
#' @note Automatic conversion of character to factor does not guarantee that the table
#' @note
#' * Automatic conversion of character to factor does not guarantee that the table
#' can be generated correctly. In particular for sparse tables this very likely can fail.
#' It is therefore better to always pre-process the dataset such that factors are manually
#' created from character variables before passing the dataset to [rtables::build_table()].
Expand Down Expand Up @@ -722,7 +723,6 @@ create_afun_summary <- function(.stats, .formats, .labels, .indent_mods) {
summarize_vars <- function(lyt,
vars,
var_labels = vars,
na_level = NA_character_,
nested = TRUE,
...,
show_labels = "default",
Expand All @@ -739,7 +739,6 @@ summarize_vars <- function(lyt,
vars = vars,
var_labels = var_labels,
afun = afun,
na_str = na_level,
nested = nested,
extra_args = list(...),
inclNAs = TRUE,
Expand Down
4 changes: 4 additions & 0 deletions man/prop_diff.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/summarize_variables.Rd

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

10 changes: 5 additions & 5 deletions tests/testthat/_snaps/summarize_coxreg.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
row_name formatted_cell indent_mod row_label
1 Label 1 340 0 Label 1

# summarize_coxreg adds the univariable Cox regression layer to rtables
# summarize_coxreg adds the univariate Cox regression layer to rtables

Code
res
Expand Down Expand Up @@ -97,7 +97,7 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Sex (F/M) 340 0.62 (0.42, 0.92) 0.0182

# summarize_coxreg works with interactions in univariable case
# summarize_coxreg works with interactions in univariate case

Code
res
Expand All @@ -118,7 +118,7 @@
F 0.67 (0.36, 1.22)
M 0.60 (0.36, 0.99)

# summarize_coxreg 'at' argument works in univariable case
# summarize_coxreg 'at' argument works in univariate case

Code
res
Expand Down Expand Up @@ -155,7 +155,7 @@
F 0.67 (0.36, 1.22) ---
M 0.60 (0.36, 0.99) ---

# summarize_coxreg works without treatment arm in univariable case
# summarize_coxreg works without treatment arm in univariate case

Code
res
Expand All @@ -170,7 +170,7 @@
Sex (F/M) (reference = F)
M 1.33 (0.97, 1.82) 0.1414

# summarize_coxreg works with numeric covariate without treatment arm in univariable case
# summarize_coxreg works with numeric covariate without treatment arm in univariate case

Code
res
Expand Down
23 changes: 23 additions & 0 deletions tests/testthat/_snaps/summarize_variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -1128,3 +1128,26 @@
Median NA 3.5 5.5
Min - Max NA 3.0 - 4.0 5.0 - 6.0

# `summarize_vars` na_level argument works with non-default input

Code
res
Output
all obs
———————————
n 4
a 2 (50%)
b 2 (50%)

---

Code
res
Output
all obs
—————————————
n 6
a 2 (33.3%)
b 2 (33.3%)
c 2 (33.3%)

20 changes: 20 additions & 0 deletions tests/testthat/test-summarize_variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,23 @@ testthat::test_that("`summarize_vars` works with empty named numeric variables",
res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)
})

testthat::test_that("`summarize_vars` na_level argument works with non-default input", {
dta <- tibble::tibble(
foo = factor(c("a", "a", "b", "b", "c", "c"), levels = c("a", "b", "c"))
)

result <- basic_table() %>%
summarize_vars(vars = "foo", na_level = "c") %>%
build_table(dta)

res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)

result <- basic_table() %>%
summarize_vars(vars = "foo", na_level = "c", na.rm = FALSE) %>%
build_table(dta)

res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)
})

0 comments on commit e23f37f

Please sign in to comment.