Skip to content

Commit

Permalink
Add general default for na_str (#1145)
Browse files Browse the repository at this point in the history
Fixes #1113
  • Loading branch information
Melkiades authored Dec 6, 2023
1 parent f281007 commit a0c8ee9
Show file tree
Hide file tree
Showing 94 changed files with 377 additions and 156 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export(d_test_proportion_diff)
export(day2month)
export(decorate_grob)
export(decorate_grob_set)
export(default_na_str)
export(df_explicit_na)
export(draw_grob)
export(estimate_incidence_rate)
Expand Down Expand Up @@ -261,6 +262,7 @@ export(score_occurrences)
export(score_occurrences_cols)
export(score_occurrences_cont_cols)
export(score_occurrences_subtable)
export(set_default_na_str)
export(split_cols_by_groups)
export(stack_grobs)
export(stat_mean_ci)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Added referential footnotes to `surv_time` for censored range observations, controlled via the `ref_fn_censor` parameter.
* Added helper function `h_adlb_abnormal_by_worst_grade` to prepare `ADLB` data to use as input in `count_abnormal_by_worst_grade`.
* Added function `rtable2gg` that converts `rtable` objects to `ggplot` objects.
* Added helper function to set default `na_str` globally with `set_default_na_str()` and added `default_na_str()` for all interested functions.

### Enhancements
* Added `ref_group_coxph` parameter to `g_km` to specify the reference group used for pairwise Cox-PH calculations when `annot_coxph = TRUE`.
Expand All @@ -29,6 +30,7 @@

### Miscellaneous
* Specified minimal version of package dependencies.
* Upgraded `to_string_matrix` to take into account `widths` and other printing parameters.

# tern 0.9.2

Expand Down
2 changes: 1 addition & 1 deletion R/abnormal.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ count_abnormal <- function(lyt,
abnormal = list(Low = "LOW", High = "HIGH"),
variables = list(id = "USUBJID", baseline = "BNRIND"),
exclude_base_abn = FALSE,
na_str = NA_character_,
na_str = default_na_str(),
nested = TRUE,
...,
table_names = var,
Expand Down
2 changes: 1 addition & 1 deletion R/abnormal_by_marked.R
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ count_abnormal_by_marked <- function(lyt,
var,
category = list(single = "SINGLE", last_replicated = c("LAST", "REPLICATED")),
variables = list(id = "USUBJID", param = "PARAM", direction = "abn_dir"),
na_str = NA_character_,
na_str = default_na_str(),
nested = TRUE,
...,
.stats = NULL,
Expand Down
2 changes: 1 addition & 1 deletion R/abnormal_by_worst_grade.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ count_abnormal_by_worst_grade <- function(lyt,
param = "PARAM",
grade_dir = "GRADE_DIR"
),
na_str = NA_character_,
na_str = default_na_str(),
nested = TRUE,
...,
.stats = NULL,
Expand Down
2 changes: 1 addition & 1 deletion R/abnormal_by_worst_grade_worsen.R
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ count_abnormal_lab_worsen_by_baseline <- function(lyt, # nolint
baseline_var = "BTOXGR",
direction_var = "GRADDR"
),
na_str = NA_character_,
na_str = default_na_str(),
nested = TRUE,
...,
table_names = NULL,
Expand Down
4 changes: 2 additions & 2 deletions R/analyze_variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ a_summary <- function(x,
.indent_mods = NULL,
na.rm = TRUE, # nolint
na_level = lifecycle::deprecated(),
na_str = NA_character_,
na_str = default_na_str(),
...) {
extra_args <- list(...)
if (lifecycle::is_present(na_level)) {
Expand Down Expand Up @@ -671,7 +671,7 @@ analyze_vars <- function(lyt,
vars,
var_labels = vars,
na_level = lifecycle::deprecated(),
na_str = NA_character_,
na_str = default_na_str(),
nested = TRUE,
...,
na.rm = TRUE, # nolint
Expand Down
2 changes: 1 addition & 1 deletion R/analyze_vars_in_cols.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ analyze_vars_in_cols <- function(lyt,
cache = FALSE,
.indent_mods = NULL,
na_level = lifecycle::deprecated(),
na_str = NA_character_,
na_str = default_na_str(),
nested = TRUE,
.formats = NULL,
.aligns = NULL) {
Expand Down
2 changes: 1 addition & 1 deletion R/compare_variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ compare_vars <- function(lyt,
vars,
var_labels = vars,
na_level = lifecycle::deprecated(),
na_str = NA_character_,
na_str = default_na_str(),
nested = TRUE,
...,
na.rm = TRUE, # nolint
Expand Down
2 changes: 1 addition & 1 deletion R/count_cumulative.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ count_cumulative <- function(lyt,
include_eq = TRUE,
var_labels = vars,
show_labels = "visible",
na_str = NA_character_,
na_str = default_na_str(),
nested = TRUE,
...,
table_names = vars,
Expand Down
2 changes: 1 addition & 1 deletion R/count_missed_doses.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ count_missed_doses <- function(lyt,
thresholds,
var_labels = vars,
show_labels = "visible",
na_str = NA_character_,
na_str = default_na_str(),
nested = TRUE,
...,
table_names = vars,
Expand Down
6 changes: 3 additions & 3 deletions R/count_occurrences.R
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ a_count_occurrences <- function(df,
.formats = NULL,
.labels = NULL,
.indent_mods = NULL,
na_str = NA_character_) {
na_str = default_na_str()) {
denom <- match.arg(denom)
x_stats <- s_count_occurrences(
df = df, denom = denom, .N_col = .N_col, .df_row = .df_row, drop = drop, .var = .var, id = id
Expand Down Expand Up @@ -216,7 +216,7 @@ count_occurrences <- function(lyt,
var_labels = vars,
show_labels = "hidden",
riskdiff = FALSE,
na_str = NA_character_,
na_str = default_na_str(),
nested = TRUE,
...,
table_names = vars,
Expand Down Expand Up @@ -282,7 +282,7 @@ summarize_occurrences <- function(lyt,
id = "USUBJID",
drop = TRUE,
riskdiff = FALSE,
na_str = NA_character_,
na_str = default_na_str(),
...,
.stats = "count_fraction_fixed_dp",
.formats = NULL,
Expand Down
4 changes: 2 additions & 2 deletions R/count_occurrences_by_grade.R
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ count_occurrences_by_grade <- function(lyt,
var_labels = var,
show_labels = "default",
riskdiff = FALSE,
na_str = NA_character_,
na_str = default_na_str(),
nested = TRUE,
...,
table_names = var,
Expand Down Expand Up @@ -355,7 +355,7 @@ summarize_occurrences_by_grade <- function(lyt,
id = "USUBJID",
grade_groups = list(),
remove_single = TRUE,
na_str = NA_character_,
na_str = default_na_str(),
...,
.stats = NULL,
.formats = NULL,
Expand Down
2 changes: 1 addition & 1 deletion R/count_patients_events_in_cols.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ summarize_patients_events_in_cols <- function(lyt, # nolint
id = "USUBJID",
filters_list = list(),
empty_stats = character(),
na_str = NA_character_,
na_str = default_na_str(),
...,
.stats = c(
"unique",
Expand Down
2 changes: 1 addition & 1 deletion R/count_patients_with_event.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ count_patients_with_event <- function(lyt,
vars,
filters,
riskdiff = FALSE,
na_str = NA_character_,
na_str = default_na_str(),
nested = TRUE,
...,
table_names = vars,
Expand Down
2 changes: 1 addition & 1 deletion R/count_patients_with_flags.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ count_patients_with_flags <- function(lyt,
var_labels = var,
show_labels = "hidden",
riskdiff = FALSE,
na_str = NA_character_,
na_str = default_na_str(),
nested = TRUE,
...,
table_names = paste0("tbl_flags_", var),
Expand Down
2 changes: 1 addition & 1 deletion R/count_values.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ a_count_values <- make_afun(
count_values <- function(lyt,
vars,
values,
na_str = NA_character_,
na_str = default_na_str(),
nested = TRUE,
...,
table_names = vars,
Expand Down
2 changes: 1 addition & 1 deletion R/estimate_multinomial_rsp.R
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ a_length_proportion <- make_afun(
#' @order 2
estimate_multinomial_response <- function(lyt,
var,
na_str = NA_character_,
na_str = default_na_str(),
nested = TRUE,
...,
show_labels = "hidden",
Expand Down
2 changes: 1 addition & 1 deletion R/estimate_proportion.R
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ estimate_proportion <- function(lyt,
max_iterations = 50,
variables = list(strata = NULL),
long = FALSE,
na_str = NA_character_,
na_str = default_na_str(),
nested = TRUE,
...,
show_labels = "hidden",
Expand Down
2 changes: 1 addition & 1 deletion R/h_biomarkers_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
h_tab_one_biomarker <- function(df,
afuns,
colvars,
na_str = NA_character_,
na_str = default_na_str(),
.indent_mods = 0L,
...) {
extra_args <- list(...)
Expand Down
2 changes: 1 addition & 1 deletion R/h_response_biomarkers_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ h_logistic_mult_cont_df <- function(variables,
#' @export
h_tab_rsp_one_biomarker <- function(df,
vars,
na_str = NA_character_,
na_str = default_na_str(),
.indent_mods = 0L) {
afuns <- a_response_subgroups(na_str = na_str)[vars]
colvars <- d_rsp_subgroups_colvars(
Expand Down
2 changes: 1 addition & 1 deletion R/h_survival_biomarkers_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ h_coxreg_mult_cont_df <- function(variables,
h_tab_surv_one_biomarker <- function(df,
vars,
time_unit,
na_str = NA_character_,
na_str = default_na_str(),
.indent_mods = 0L,
...) {
afuns <- a_survival_subgroups(na_str = na_str)[vars]
Expand Down
2 changes: 1 addition & 1 deletion R/incidence_rate.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ estimate_incidence_rate <- function(lyt,
vars,
n_events,
control = control_incidence_rate(),
na_str = NA_character_,
na_str = default_na_str(),
nested = TRUE,
...,
show_labels = "hidden",
Expand Down
2 changes: 1 addition & 1 deletion R/logistic_regression.R
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ logistic_regression_cols <- function(lyt,
#' @return A content function.
#'
#' @export
logistic_summary_by_flag <- function(flag_var, na_str = NA_character_, .indent_mods = NULL) {
logistic_summary_by_flag <- function(flag_var, na_str = default_na_str(), .indent_mods = NULL) {
checkmate::assert_string(flag_var)
function(lyt) {
cfun_list <- list(
Expand Down
2 changes: 1 addition & 1 deletion R/odds_ratio.R
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ estimate_odds_ratio <- function(lyt,
variables = list(arm = NULL, strata = NULL),
conf_level = 0.95,
groups_list = NULL,
na_str = NA_character_,
na_str = default_na_str(),
nested = TRUE,
...,
show_labels = "hidden",
Expand Down
2 changes: 1 addition & 1 deletion R/prop_diff.R
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ estimate_proportion_diff <- function(lyt,
"strat_newcombe", "strat_newcombecc"
),
weights_method = "cmh",
na_str = NA_character_,
na_str = default_na_str(),
nested = TRUE,
...,
var_labels = vars,
Expand Down
2 changes: 1 addition & 1 deletion R/prop_diff_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ test_proportion_diff <- function(lyt,
vars,
variables = list(strata = NULL),
method = c("chisq", "schouten", "fisher", "cmh"),
na_str = NA_character_,
na_str = default_na_str(),
nested = TRUE,
...,
var_labels = vars,
Expand Down
2 changes: 1 addition & 1 deletion R/response_biomarkers_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
#' @name response_biomarkers_subgroups
tabulate_rsp_biomarkers <- function(df,
vars = c("n_tot", "n_rsp", "prop", "or", "ci", "pval"),
na_str = NA_character_,
na_str = default_na_str(),
.indent_mods = 0L) {
checkmate::assert_data_frame(df)
checkmate::assert_character(df$biomarker)
Expand Down
4 changes: 2 additions & 2 deletions R/response_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ a_response_subgroups <- function(.formats = list(
ci = list(format_extreme_values_ci(2L)),
pval = "x.xxxx | (<0.0001)" # nolint end
),
na_str = NA_character_) {
na_str = default_na_str()) {
checkmate::assert_list(.formats)
checkmate::assert_subset(
names(.formats),
Expand Down Expand Up @@ -198,7 +198,7 @@ tabulate_rsp_subgroups <- function(lyt,
vars = c("n_tot", "n", "prop", "or", "ci"),
groups_lists = list(),
label_all = "All Patients",
na_str = NA_character_) {
na_str = default_na_str()) {
conf_level <- df$or$conf_level[1]
method <- if ("pval_label" %in% names(df$or)) {
df$or$pval_label[1]
Expand Down
2 changes: 1 addition & 1 deletion R/riskdiff.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ afun_riskdiff <- function(df,
.formats = NULL,
.labels = NULL,
.indent_mods = NULL,
na_str = NA_character_,
na_str = default_na_str(),
afun,
s_args = list()) {
if (!any(grepl("riskdiff", names(.spl_context)))) {
Expand Down
2 changes: 1 addition & 1 deletion R/summarize_ancova.R
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ summarize_ancova <- function(lyt,
interaction_y = FALSE,
interaction_item = NULL,
var_labels,
na_str = NA_character_,
na_str = default_na_str(),
nested = TRUE,
...,
show_labels = "visible",
Expand Down
2 changes: 1 addition & 1 deletion R/summarize_change.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ a_change_from_baseline <- make_afun(
summarize_change <- function(lyt,
vars,
variables,
na_str = NA_character_,
na_str = default_na_str(),
nested = TRUE,
...,
table_names = vars,
Expand Down
2 changes: 1 addition & 1 deletion R/summarize_colvars.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
summarize_colvars <- function(lyt,
...,
na_level = lifecycle::deprecated(),
na_str = NA_character_,
na_str = default_na_str(),
.stats = c("n", "mean_sd", "median", "range", "count_fraction"),
.formats = NULL,
.labels = NULL,
Expand Down
2 changes: 1 addition & 1 deletion R/summarize_glm_count.R
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ summarize_glm_count <- function(lyt,
weights = stats::weights,
scale = 1,
var_labels,
na_str = NA_character_,
na_str = default_na_str(),
nested = TRUE,
...,
show_labels = "visible",
Expand Down
4 changes: 2 additions & 2 deletions R/summarize_num_patients.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ summarize_num_patients <- function(lyt,
required = NULL,
count_by = NULL,
unique_count_suffix = TRUE,
na_str = NA_character_,
na_str = default_na_str(),
.stats = NULL,
.formats = NULL,
.labels = c(
Expand Down Expand Up @@ -233,7 +233,7 @@ analyze_num_patients <- function(lyt,
required = NULL,
count_by = NULL,
unique_count_suffix = TRUE,
na_str = NA_character_,
na_str = default_na_str(),
nested = TRUE,
.stats = NULL,
.formats = NULL,
Expand Down
Loading

0 comments on commit a0c8ee9

Please sign in to comment.