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

Fix documentation for the label_all argument of extract_* functions #1232

Merged
merged 4 commits into from
Apr 23, 2024
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
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# tern 0.9.4.9000

### Enhancements
* Added examples and tests for `label_all` parameter to `extract_survival_biomarkers` and `extract_survival_subgroups`.

### Miscellaneous
* Began deprecation of the unused `label_all` parameter to `tabulate_survival_biomarkers` and `tabulate_survival_subgroups`, with redirection to the same parameter in their associated `extract_*` functions.

# tern 0.9.4

### New Features
Expand Down
18 changes: 16 additions & 2 deletions R/survival_biomarkers_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#' covariates = "SEX",
#' subgroups = "BMRKR2"
#' ),
#' label_all = "Total Patients",
#' data = adtte_f
#' )
#' df
Expand Down Expand Up @@ -162,6 +163,9 @@ extract_survival_biomarkers <- function(variables,
#' @describeIn survival_biomarkers_subgroups Table-creating function which creates a table
#' summarizing biomarker effects on survival by subgroup.
#'
#' @param label_all `r lifecycle::badge("deprecated")`\cr please assign the `label_all` parameter within the
#' [extract_survival_biomarkers()] function when creating `df`.
#'
#' @return An `rtables` table summarizing biomarker effects on survival by subgroup.
#'
#' @note In contrast to [tabulate_survival_subgroups()] this tabulation function does
Expand Down Expand Up @@ -192,16 +196,26 @@ tabulate_survival_biomarkers <- function(df,
vars = c("n_tot", "n_tot_events", "median", "hr", "ci", "pval"),
groups_lists = list(),
control = control_coxreg(),
label_all = "All Patients",
label_all = lifecycle::deprecated(),
time_unit = NULL,
na_str = default_na_str(),
.indent_mods = 0L) {
if (lifecycle::is_present(label_all)) {
lifecycle::deprecate_warn(
"0.9.5", "tabulate_survival_biomarkers(label_all)",
details = paste(
"Please assign the `label_all` parameter within the",
"`extract_survival_biomarkers()` function when creating `df`."
)
)
}

checkmate::assert_data_frame(df)
checkmate::assert_character(df$biomarker)
checkmate::assert_character(df$biomarker_label)
checkmate::assert_subset(vars, get_stats("tabulate_survival_biomarkers"))

extra_args <- list(groups_lists = groups_lists, control = control, label_all = label_all)
extra_args <- list(groups_lists = groups_lists, control = control)

df_subs <- split(df, f = df$biomarker)
tabs <- lapply(df_subs, FUN = function(df_sub) {
Expand Down
20 changes: 16 additions & 4 deletions R/survival_duration_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#'
#' @examples
#' library(dplyr)
#' library(forcats)
#'
#' adtte <- tern_ex_adtte
#'
Expand All @@ -43,7 +42,7 @@
#' ) %>%
#' mutate(
#' # Reorder levels of ARM to display reference arm before treatment arm.
#' ARM = droplevels(fct_relevel(ARM, "B: Placebo")),
#' ARM = droplevels(forcats::fct_relevel(ARM, "B: Placebo")),
#' SEX = droplevels(SEX),
#' AVALU = as.character(AVALU),
#' is_event = CNSR == 0
Expand All @@ -62,6 +61,7 @@
#' is_event = "is_event",
#' arm = "ARM", subgroups = c("SEX", "BMRKR2")
#' ),
#' label_all = "Total Patients",
#' data = adtte_f
#' )
#' df
Expand Down Expand Up @@ -199,6 +199,10 @@ a_survival_subgroups <- function(.formats = list( # nolint start
#' summarizing survival by subgroup. This function is a wrapper for [rtables::analyze_colvars()]
#' and [rtables::summarize_row_groups()].
#'
#' @param label_all `r lifecycle::badge("deprecated")`\cr please assign the `label_all` parameter within the
#' [extract_survival_subgroups()] function when creating `df`.
#'
#'
#' @return An `rtables` table summarizing survival by subgroup.
#'
#' @examples
Expand All @@ -220,13 +224,21 @@ tabulate_survival_subgroups <- function(lyt,
df,
vars = c("n_tot_events", "n_events", "median", "hr", "ci"),
groups_lists = list(),
label_all = "All Patients",
label_all = lifecycle::deprecated(),
time_unit = NULL,
na_str = default_na_str()) {
if (lifecycle::is_present(label_all)) {
lifecycle::deprecate_warn(
"0.9.5", "tabulate_survival_subgroups(label_all)",
details =
"Please assign the `label_all` parameter within the `extract_survival_subgroups()` function when creating `df`."
)
}

conf_level <- df$hr$conf_level[1]
method <- df$hr$pval_label[1]

extra_args <- list(groups_lists = groups_lists, conf_level = conf_level, method = method, label_all = label_all)
extra_args <- list(groups_lists = groups_lists, conf_level = conf_level, method = method)

afun_lst <- a_survival_subgroups(na_str = na_str)
colvars <- d_survival_subgroups_colvars(
Expand Down
6 changes: 4 additions & 2 deletions man/survival_biomarkers_subgroups.Rd

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

9 changes: 5 additions & 4 deletions man/survival_duration_subgroups.Rd

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

26 changes: 26 additions & 0 deletions tests/testthat/_snaps/survival_biomarkers_subgroups.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,29 @@
MEDIUM 68 42 859.0 0.97 (0.89, 1.06) 0.5218
HIGH 62 47 727.8 1.06 (0.96, 1.17) 0.2239

# label_all argument to extract_survival_subgroups works as expected

Code
res
Output
Total n Total Events Median (DAYS) Hazard Ratio 95% Wald CI p-value (Wald)
——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
Age
Full Analysis Set 200 141 753.5 1.01 (0.99, 1.04) 0.3432
Sex
F 110 79 685.2 1.00 (0.96, 1.03) 0.8808
M 90 62 888.5 1.02 (0.99, 1.05) 0.1974
Continuous Level Biomarker 2
LOW 70 52 735.5 1.01 (0.97, 1.06) 0.5584
MEDIUM 68 42 859.0 1.03 (0.98, 1.09) 0.2532
HIGH 62 47 727.8 1.00 (0.96, 1.03) 0.8292
Continuous Level Biomarker 1
Full Analysis Set 200 141 753.5 1.00 (0.95, 1.05) 0.9590
Sex
F 110 79 685.2 1.01 (0.96, 1.07) 0.6215
M 90 62 888.5 0.98 (0.90, 1.07) 0.6939
Continuous Level Biomarker 2
LOW 70 52 735.5 1.00 (0.92, 1.08) 0.9833
MEDIUM 68 42 859.0 0.97 (0.89, 1.06) 0.5218
HIGH 62 47 727.8 1.06 (0.96, 1.17) 0.2239

17 changes: 17 additions & 0 deletions tests/testthat/_snaps/survival_duration_subgroups.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,20 @@
MEDIUM 31 14 731.8 17 964.2 <No data> (0.36, 1.61)
HIGH 34 22 654.8 12 1016.3 0.67 (0.33, 1.36)

# label_all argument to extract_survival_subgroups works as expected

Code
res
Output
B: Placebo A: Drug X
Baseline Risk Factors Total Events Events Median (DAYS) Events Median (DAYS) Hazard Ratio 95% Wald CI
———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
Full Analysis Set 101 57 727.8 44 974.6 0.71 (0.48, 1.06)
Sex
F 55 31 599.2 24 1016.3 0.56 (0.32, 0.96)
M 46 26 888.5 20 974.6 0.91 (0.50, 1.65)
Continuous Level Biomarker 2
LOW 36 21 735.5 15 974.6 0.76 (0.39, 1.51)
MEDIUM 31 14 731.8 17 964.2 0.77 (0.36, 1.61)
HIGH 34 22 654.8 12 1016.3 0.67 (0.33, 1.36)

25 changes: 25 additions & 0 deletions tests/testthat/test-survival_biomarkers_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,28 @@ testthat::test_that("tabulate_survival_biomarkers na_str argument works as expec
res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)
})

testthat::test_that("label_all argument to extract_survival_subgroups works as expected", {
adtte_f <- adtte_local

df <- extract_survival_biomarkers(
variables = list(
tte = "AVAL",
is_event = "is_event",
biomarkers = c("AGE", "BMRKR1"),
subgroups = c("SEX", "BMRKR2")
),
data = adtte_f,
label_all = "Full Analysis Set"
)

lifecycle::expect_deprecated(
result <- tabulate_survival_biomarkers(
df,
time_unit = as.character(adtte_f$AVALU[1]), label_all = "Full Analysis Set"
)
)

res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)
})
18 changes: 18 additions & 0 deletions tests/testthat/test-survival_duration_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,21 @@ testthat::test_that("tabulate_survival_subgroups na_str argument works as expect
res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)
})

testthat::test_that("label_all argument to extract_survival_subgroups works as expected", {
adtte <- adtte_local

df <- extract_survival_subgroups(
variables = list(tte = "AVAL", is_event = "is_event", arm = "ARM", subgroups = c("SEX", "BMRKR2")),
data = adtte,
label_all = "Full Analysis Set"
)

lifecycle::expect_deprecated(
result <- basic_table() %>%
tabulate_survival_subgroups(df, time_unit = adtte$AVALU[1], label_all = "Full Analysis Set")
)

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