Skip to content

Commit

Permalink
Merge branch 'main' into 1077_update_g_lineplot@main
Browse files Browse the repository at this point in the history
  • Loading branch information
shajoezhu authored Oct 18, 2023
2 parents 704f69a + 98cb04c commit fa85d58
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 22 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: tern
Title: Create Common TLGs Used in Clinical Trials
Version: 0.9.1.9006
Date: 2023-10-16
Version: 0.9.1.9009
Date: 2023-10-18
Authors@R: c(
person("Joe", "Zhu", , "joe.zhu@roche.com", role = c("aut", "cre")),
person("Daniel", "Sabanés Bové", , "daniel.sabanes_bove@roche.com", role = "aut"),
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# tern 0.9.1.9006
# tern 0.9.1.9009

### New Features
* Added the `na_str` argument to `analyze` & `summarize_row_groups` wrapper functions `count_abnormal`, `count_abnormal_by_baseline`, `count_abnormal_by_marked`, `count_abnormal_by_worst_grade`, `count_abnormal_lab_worsen_by_baseline`, `count_cumulative`, `count_missed_doses`, `count_occurrences`, `count_occurrences_by_grade`, `summarize_occurrences_by_grade`, `summarize_patients_events_in_cols`, `count_patients_with_event`, `count_patients_with_flags`, `count_values`, `estimate_multinomial_response`, `estimate_proportion`, `h_tab_one_biomarker`, `estimate_incidence_rate`, `logistic_summary_by_flag`, `estimate_odds_ratio`, `estimate_proportion_diff`, `test_proportion_diff`, `summarize_ancova`, `summarize_change`, `summarize_glm_count`, `summarize_num_patients`, `analyze_num_patients`, `summarize_patients_exposure_in_cols`, `coxph_pairwise`, `tabulate_survival_subgroups`, `surv_time`, and `surv_timepoint`.

### Enhancements
* Added formatting function `format_count_fraction_lt10` for formatting `count_fraction` with special consideration when count is less than 10.
* Updated `s_summary.logical` output for `count_fraction` when denominator is zero to display as `NA` instead of `0` in tables.
* Updated `analyze_vars_in_cols` to allow character input to indicate whether nominal time point is post-dose or pre-dose when applying the 1/3 imputation rule.

### Bug Fixes
* Fixed bug in `g_km` causing an error when converting certain annotation width units.
Expand Down
10 changes: 8 additions & 2 deletions R/analyze_vars_in_cols.R
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,12 @@ analyze_vars_in_cols <- function(lyt,
if (is.null(imp_rule) || !stat %in% c("mean", "sd", "cv", "geom_mean", "geom_cv", "median", "min", "max")) {
res <- x_stats[[stat]]
} else {
timept <- as.numeric(gsub(".*?([0-9\\.]+).*", "\\1", tail(.spl_context$value, 1)))
res_imp <- imputation_rule(
.df_row, x_stats, stat,
imp_rule = imp_rule, post = as.numeric(tail(.spl_context$value, 1)) > 0, avalcat_var = avalcat_var
imp_rule = imp_rule,
post = grepl("Predose", tail(.spl_context$value, 1)) || timept > 0,
avalcat_var = avalcat_var
)
res <- res_imp[["val"]]
na_str <- res_imp[["na_str"]]
Expand Down Expand Up @@ -313,9 +316,12 @@ analyze_vars_in_cols <- function(lyt,
if (is.null(imp_rule) || !stat %in% c("mean", "sd", "cv", "geom_mean", "geom_cv", "median", "min", "max")) {
res <- x_stats[[stat]]
} else {
timept <- as.numeric(gsub(".*?([0-9\\.]+).*", "\\1", tail(.spl_context$value, 1)))
res_imp <- imputation_rule(
.df_row, x_stats, stat,
imp_rule = imp_rule, post = as.numeric(tail(.spl_context$value, 1)) > 0, avalcat_var = avalcat_var
imp_rule = imp_rule,
post = grepl("Predose", tail(.spl_context$value, 1)) || timept > 0,
avalcat_var = avalcat_var
)
res <- res_imp[["val"]]
na_str <- res_imp[["na_str"]]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# tern <a href='https://github.com/insightsengineering/tern'><img src="man/figures/tern.png" align="right" height="139" style="max-width: 100%;"/></a>
# tern <a href='https://github.com/insightsengineering/tern'><img src="man/figures/tern.png" align="right" height="200" width="200"/></a>

<!-- start badges -->
[![Check 🛠](https://github.com/insightsengineering/tern/actions/workflows/check.yaml/badge.svg)](https://insightsengineering.github.io/tern/main/unit-test-report/)
Expand Down
Binary file modified man/figures/tern.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 24 additions & 16 deletions tests/testthat/test-analyze_vars_in_cols.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@ testthat::test_that("analyze_vars_in_cols works correctly", {
testthat::expect_snapshot(res)

# It fails if called multiple times with identical col split
testthat::expect_error(basic_table() %>%
split_rows_by(var = "ARM", label_pos = "topleft") %>%
split_rows_by(var = "SEX", label_pos = "topleft") %>%
analyze_vars_in_cols(vars = "AGE", .stats = c("n", "mean", "se")) %>%
analyze_vars_in_cols(vars = "AGE", .stats = c("n", "mean", "se")))
testthat::expect_error(
basic_table() %>%
split_rows_by(var = "ARM", label_pos = "topleft") %>%
split_rows_by(var = "SEX", label_pos = "topleft") %>%
analyze_vars_in_cols(vars = "AGE", .stats = c("n", "mean", "se")) %>%
analyze_vars_in_cols(vars = "AGE", .stats = c("n", "mean", "se"))
)

# It fails if called multiple times with identical col split on different lines
testthat::expect_error(basic_table() %>%
split_rows_by(var = "ARM", label_pos = "topleft") %>%
analyze_vars_in_cols(vars = "AGE", .stats = c("n", "mean", "se")) %>%
split_rows_by(var = "SEX", label_pos = "topleft") %>%
analyze_vars_in_cols(vars = "AGE", .stats = c("n", "mean", "se")))
testthat::expect_error(
basic_table() %>%
split_rows_by(var = "ARM", label_pos = "topleft") %>%
analyze_vars_in_cols(vars = "AGE", .stats = c("n", "mean", "se")) %>%
split_rows_by(var = "SEX", label_pos = "topleft") %>%
analyze_vars_in_cols(vars = "AGE", .stats = c("n", "mean", "se"))
)
})

testthat::test_that("analyze_vars_in_cols throws error when vars and .stats lengths differ in len", {
Expand Down Expand Up @@ -263,12 +267,14 @@ testthat::test_that("analyze_vars_in_cols works well with categorical data", {
in_rows(.list = ret_list, .formats = aform)
}

testthat::expect_snapshot(basic_table(show_colcounts = TRUE) %>%
split_rows_by(var = "STRATA1", label_pos = "topleft") %>%
split_cols_by("ARM") %>%
analyze(vars = "SEX", afun = count_fraction) %>%
append_topleft(" SEX") %>%
build_table(adpp))
testthat::expect_snapshot(
basic_table(show_colcounts = TRUE) %>%
split_rows_by(var = "STRATA1", label_pos = "topleft") %>%
split_cols_by("ARM") %>%
analyze(vars = "SEX", afun = count_fraction) %>%
append_topleft(" SEX") %>%
build_table(adpp)
)
})

testthat::test_that("analyze_vars_in_cols works with imputation rule", {
Expand Down Expand Up @@ -312,6 +318,8 @@ testthat::test_that("analyze_vars_in_cols works with imputation rule", {
res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)

df$NFRLT <- as.character(df$NFRLT)

# 1/3 imputation rule, custom avalcat_var
lyt <- basic_table() %>%
split_rows_by(
Expand Down

0 comments on commit fa85d58

Please sign in to comment.