From 79ebc56b6001bb8be8d0165e3ab85db6f0969e3b Mon Sep 17 00:00:00 2001 From: m7pr Date: Wed, 7 Feb 2024 12:37:49 +0100 Subject: [PATCH 01/31] substitute assertthat with checkmate in a couple of functions --- R/tm_g_ipp.R | 26 ++++++------- R/tm_t_abnormality.R | 33 ++++++++-------- R/tm_t_abnormality_by_worst_grade.R | 27 +++++++------ R/tm_t_events_by_grade.R | 59 ++++++++++++++--------------- R/tm_t_shift_by_arm.R | 28 +++++++------- R/tm_t_shift_by_arm_by_worst.R | 28 +++++++------- 6 files changed, 96 insertions(+), 105 deletions(-) diff --git a/R/tm_g_ipp.R b/R/tm_g_ipp.R index ff7083e7f1..663be0a63c 100644 --- a/R/tm_g_ipp.R +++ b/R/tm_g_ipp.R @@ -51,20 +51,18 @@ template_g_ipp <- function(dataname = "ANL", ) } - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(paramcd), - assertthat::is.string(arm_var), - assertthat::is.string(aval_var), - assertthat::is.string(avalu_var), - assertthat::is.string(id_var), - assertthat::is.string(visit_var), - assertthat::is.string(baseline_var), - assertthat::is.flag(add_baseline_hline), - assertthat::is.flag(separate_by_obs), - assertthat::is.flag(suppress_legend), - assertthat::is.flag(add_avalu) - ) + checkmate::assert_string(dataname) + checkmate::assert_string(paramcd) + checkmate::assert_string(arm_var) + checkmate::assert_string(aval_var) + checkmate::assert_string(avalu_var) + checkmate::assert_string(id_var) + checkmate::assert_string(visit_var) + checkmate::assert_string(baseline_var) + checkmate::assert_flag(add_baseline_hline) + checkmate::assert_flag(separate_by_obs) + checkmate::assert_flag(suppress_legend) + checkmate::assert_flag(add_avalu) y <- list() # Data preprocessing diff --git a/R/tm_t_abnormality.R b/R/tm_t_abnormality.R index f06c0fd285..ef404fd0ef 100644 --- a/R/tm_t_abnormality.R +++ b/R/tm_t_abnormality.R @@ -34,23 +34,22 @@ template_abnormality <- function(parentname, na_level = default_na_str(), basic_table_args = teal.widgets::basic_table_args(), tbl_title) { - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(id_var), - assertthat::is.string(parentname), - assertthat::is.string(arm_var), - is.character(by_vars), - is.list(abnormal), - assertthat::is.string(grade), - assertthat::is.string(baseline_var), - assertthat::is.string(treatment_flag_var), - assertthat::is.string(treatment_flag), - assertthat::is.flag(add_total), - assertthat::is.string(total_label), - assertthat::is.flag(exclude_base_abn), - assertthat::is.flag(drop_arm_levels), - assertthat::is.string(tbl_title) - ) + + checkmate::assert_string(dataname) + checkmate::assert_string(id_var) + checkmate::assert_string(parentname) + checkmate::assert_string(arm_var) + checkmate::check_character(by_vars) + checkmate::check_list(abnormal) + checkmate::assert_string(grade) + checkmate::assert_string(baseline_var) + checkmate::assert_string(treatment_flag_var) + checkmate::assert_string(treatment_flag) + checkmate::assert_flag(add_total) + checkmate::assert_string(total_label) + checkmate::assert_flag(exclude_base_abn) + checkmate::assert_flag(drop_arm_levels) + checkmate::assert_string(tbl_title) y <- list() diff --git a/R/tm_t_abnormality_by_worst_grade.R b/R/tm_t_abnormality_by_worst_grade.R index 33e2116319..4a30f667c8 100644 --- a/R/tm_t_abnormality_by_worst_grade.R +++ b/R/tm_t_abnormality_by_worst_grade.R @@ -28,20 +28,19 @@ template_abnormality_by_worst_grade <- function(parentname, # nolint total_label = default_total_label(), drop_arm_levels = TRUE, basic_table_args = teal.widgets::basic_table_args()) { - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(parentname), - assertthat::is.string(arm_var), - assertthat::is.string(id_var), - assertthat::is.string(paramcd), - assertthat::is.string(atoxgr_var), - assertthat::is.string(worst_high_flag_var), - assertthat::is.string(worst_low_flag_var), - assertthat::is.string(worst_flag_indicator), - assertthat::is.flag(add_total), - assertthat::is.string(total_label), - assertthat::is.flag(drop_arm_levels) - ) + + checkmate::assert_string(dataname) + checkmate::assert_string(parentname) + checkmate::assert_string(arm_var) + checkmate::assert_string(id_var) + checkmate::assert_string(paramcd) + checkmate::assert_string(atoxgr_var) + checkmate::assert_string(worst_high_flag_var) + checkmate::assert_string(worst_low_flag_var) + checkmate::assert_string(worst_flag_indicator) + checkmate::assert_flag(add_total) + checkmate::assert_string(total_label) + checkmate::assert_flag(drop_arm_levels) y <- list() diff --git a/R/tm_t_events_by_grade.R b/R/tm_t_events_by_grade.R index 2a3470d71e..294d06539f 100644 --- a/R/tm_t_events_by_grade.R +++ b/R/tm_t_events_by_grade.R @@ -30,22 +30,21 @@ template_events_by_grade <- function(dataname, na_level = default_na_str(), drop_arm_levels = TRUE, basic_table_args = teal.widgets::basic_table_args()) { - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(parentname), - assertthat::is.string(arm_var), - assertthat::is.string(hlt) || is.null(hlt), - assertthat::is.string(llt) || is.null(llt), - !is.null(hlt) || !is.null(llt), - assertthat::is.string(label_hlt) || is.null(label_hlt), - assertthat::is.string(label_llt) || is.null(label_llt), - assertthat::is.string(grade), - assertthat::is.string(label_grade) || is.null(label_grade), - assertthat::is.flag(add_total), - assertthat::is.string(total_label), - assertthat::is.string(na_level), - assertthat::is.flag(drop_arm_levels) - ) + + checkmate::assert_string(dataname) + checkmate::assert_string(parentname) + checkmate::assert_string(arm_var) + checkmate::assert_string(hlt, null.ok = TRUE) + checkmate::assert_string(llt, null.ok = TRUE) + stopifnot(!is.null(hlt) || !is.null(llt)) + checkmate::assert_string(label_hlt, null.ok = TRUE) + checkmate::assert_string(label_llt, null.ok = TRUE) + checkmate::assert_string(grade) + checkmate::assert_string(label_grade, null.ok = TRUE) + checkmate::assert_flag(add_total) + checkmate::assert_string(total_label) + checkmate::assert_string(na_level) + checkmate::assert_flag(drop_arm_levels) checkmate::assert_scalar(prune_freq) checkmate::assert_scalar(prune_diff) @@ -410,21 +409,21 @@ template_events_col_by_grade <- function(dataname, drop_arm_levels = TRUE, basic_table_args = teal.widgets::basic_table_args()) { assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(parentname), - assertthat::is.string(arm_var), + checkmate::assert_string(dataname), + checkmate::assert_string(parentname), + checkmate::assert_string(arm_var), is.list(grading_groups), - assertthat::is.flag(add_total), - assertthat::is.string(total_label), - assertthat::is.string(id), - assertthat::is.string(hlt) || is.null(hlt), - assertthat::is.string(llt), - assertthat::is.string(grade), - assertthat::is.string(label_hlt) || is.null(label_hlt), - assertthat::is.string(label_llt) || is.null(label_llt), - assertthat::is.string(label_grade) || is.null(label_grade), - assertthat::is.string(na_level), - assertthat::is.flag(drop_arm_levels) + checkmate::assert_flag(add_total), + checkmate::assert_string(total_label), + checkmate::assert_string(id), + checkmate::assert_string(hlt) || is.null(hlt), + checkmate::assert_string(llt), + checkmate::assert_string(grade), + checkmate::assert_string(label_hlt) || is.null(label_hlt), + checkmate::assert_string(label_llt) || is.null(label_llt), + checkmate::assert_string(label_grade) || is.null(label_grade), + checkmate::assert_string(na_level), + checkmate::assert_flag(drop_arm_levels) ) checkmate::assert_scalar(prune_freq) checkmate::assert_scalar(prune_diff) diff --git a/R/tm_t_shift_by_arm.R b/R/tm_t_shift_by_arm.R index 674039ab3e..df985069cf 100644 --- a/R/tm_t_shift_by_arm.R +++ b/R/tm_t_shift_by_arm.R @@ -36,21 +36,19 @@ template_shift_by_arm <- function(dataname, ) } - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(parentname), - assertthat::is.string(arm_var), - assertthat::is.string(visit_var), - assertthat::is.string(paramcd), - assertthat::is.string(aval_var), - assertthat::is.string(baseline_var), - assertthat::is.flag(na.rm), - assertthat::is.string(na_level), - assertthat::is.string(treatment_flag_var), - assertthat::is.string(treatment_flag), - assertthat::is.flag(add_total), - assertthat::is.string(total_label) - ) + checkmate::assert_string(dataname) + checkmate::assert_string(parentname) + checkmate::assert_string(arm_var) + checkmate::assert_string(visit_var) + checkmate::assert_string(paramcd) + checkmate::assert_string(aval_var) + checkmate::assert_string(baseline_var) + checkmate::assert_flag(na.rm) + checkmate::assert_string(na_level) + checkmate::assert_string(treatment_flag_var) + checkmate::assert_string(treatment_flag) + checkmate::assert_flag(add_total) + checkmate::assert_string(total_label) y <- list() diff --git a/R/tm_t_shift_by_arm_by_worst.R b/R/tm_t_shift_by_arm_by_worst.R index d9175cf072..b46d71b70d 100644 --- a/R/tm_t_shift_by_arm_by_worst.R +++ b/R/tm_t_shift_by_arm_by_worst.R @@ -37,21 +37,19 @@ template_shift_by_arm_by_worst <- function(dataname, ) } - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(parentname), - assertthat::is.string(arm_var), - is.null(worst_flag_var) || is.character(worst_flag_var), - assertthat::is.string(paramcd), - assertthat::is.string(aval_var), - assertthat::is.string(baseline_var), - assertthat::is.flag(na.rm), - assertthat::is.string(na_level), - assertthat::is.string(treatment_flag_var), - assertthat::is.string(treatment_flag), - assertthat::is.flag(add_total), - assertthat::is.string(total_label) - ) + checkmate::assert_string(dataname) + checkmate::assert_string(parentname) + checkmate::assert_string(arm_var) + checkmate::assert_character(worst_flag_var, null.ok = TRUE) + checkmate::assert_string(paramcd) + checkmate::assert_string(aval_var) + checkmate::assert_string(baseline_var) + checkmate::assert_flag(na.rm) + checkmate::assert_string(na_level) + checkmate::assert_string(treatment_flag_var) + checkmate::assert_string(treatment_flag) + checkmate::assert_flag(add_total) + checkmate::assert_string(total_label) y <- list() From a28a7f8f9aa0f38d4e002f8ead1e74612506bfb2 Mon Sep 17 00:00:00 2001 From: m7pr Date: Wed, 7 Feb 2024 12:50:02 +0100 Subject: [PATCH 02/31] substitute assertthat with checkmate in few more files --- R/tm_g_lineplot.R | 20 ++++++++++---------- R/tm_g_pp_therapy.R | 29 ++++++++++++++--------------- R/tm_t_ancova.R | 22 ++++++++++------------ R/tm_t_events_summary.R | 33 ++++++++++++++++----------------- R/tm_t_mult_events.R | 26 ++++++++++++-------------- R/tm_t_pp_medical_history.R | 10 ++++------ R/tm_t_summary_by.R | 34 +++++++++++++++++----------------- 7 files changed, 83 insertions(+), 91 deletions(-) diff --git a/R/tm_g_lineplot.R b/R/tm_g_lineplot.R index 6c6ca9ccad..b372f52bd1 100644 --- a/R/tm_g_lineplot.R +++ b/R/tm_g_lineplot.R @@ -39,16 +39,16 @@ template_g_lineplot <- function(dataname = "ANL", title = "Line Plot", y_lab = "", ggplot2_args = teal.widgets::ggplot2_args()) { - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(strata), - assertthat::is.string(x), - assertthat::is.string(y), - assertthat::is.string(y_unit), - assertthat::is.string(paramcd), - assertthat::is.string(title), - assertthat::is.string(y_lab) - ) + + checkmate::assert_string(dataname) + checkmate::assert_string(strata) + checkmate::assert_string(x) + checkmate::assert_string(y) + checkmate::assert_string(y_unit) + checkmate::assert_string(paramcd) + checkmate::assert_string(title) + checkmate::assert_string(y_lab) + z <- list() data_list <- list() diff --git a/R/tm_g_pp_therapy.R b/R/tm_g_pp_therapy.R index 0fcf150a7b..8146341e9b 100644 --- a/R/tm_g_pp_therapy.R +++ b/R/tm_g_pp_therapy.R @@ -30,21 +30,20 @@ template_therapy <- function(dataname = "ANL", patient_id, font_size = 12L, ggplot2_args = teal.widgets::ggplot2_args()) { - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(atirel), - assertthat::is.string(cmdecod), - assertthat::is.string(cmindc), - assertthat::is.string(cmdose), - assertthat::is.string(cmtrt), - assertthat::is.string(cmdosu), - assertthat::is.string(cmroute), - assertthat::is.string(cmdosfrq), - assertthat::is.string(cmstdy), - assertthat::is.string(cmendy), - assertthat::is.string(patient_id), - is.numeric(font_size) - ) + + checkmate::assert_string(dataname) + checkmate::assert_string(atirel) + checkmate::assert_string(cmdecod) + checkmate::assert_string(cmindc) + checkmate::assert_string(cmdose) + checkmate::assert_string(cmtrt) + checkmate::assert_string(cmdosu) + checkmate::assert_string(cmroute) + checkmate::assert_string(cmdosfrq) + checkmate::assert_string(cmstdy) + checkmate::assert_string(cmendy) + checkmate::assert_string(patient_id) + is.numeric(font_size) y <- list() y$table_list <- list() diff --git a/R/tm_t_ancova.R b/R/tm_t_ancova.R index d7d31550a7..ba268f5f9a 100644 --- a/R/tm_t_ancova.R +++ b/R/tm_t_ancova.R @@ -42,18 +42,16 @@ template_ancova <- function(dataname = "ANL", visit_var = "AVISIT", conf_level = 0.95, basic_table_args = teal.widgets::basic_table_args()) { - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(parentname), - assertthat::is.string(arm_var), - assertthat::is.string(label_aval) || is.null(label_aval), - assertthat::is.flag(combine_comp_arms), - assertthat::is.string(aval_var), - is.character(cov_var), - assertthat::is.flag(include_interact), - all(sapply(interact_y, assertthat::is.string)) || isFALSE(interact_y), - assertthat::is.string(interact_var) || is.null(interact_var) - ) + checkmate::assert_string(dataname) + checkmate::assert_string(parentname) + checkmate::assert_string(arm_var) + checkmate::assert_string(label_aval, null.ok = TRUE) + checkmate::assert_flag(combine_comp_arms) + checkmate::assert_string(aval_var) + checkmate::assert_character(cov_var) + checkmate::assert_flag(include_interact) + stopifnot(all(sapply(interact_y, checkmate::assert_string)) || isFALSE(interact_y)) + checkmate::assert_string(interact_var, null.ok = TRUE) y <- list() diff --git a/R/tm_t_events_summary.R b/R/tm_t_events_summary.R index 1753bc3fae..994a319b13 100644 --- a/R/tm_t_events_summary.R +++ b/R/tm_t_events_summary.R @@ -42,23 +42,22 @@ template_events_summary <- function(anl_name, count_subj = TRUE, count_pt = TRUE, count_events = TRUE) { - assertthat::assert_that( - assertthat::is.string(anl_name), - assertthat::is.string(parentname), - is.character(arm_var) && length(arm_var) %in% c(1, 2), - assertthat::is.string(dthfl_var), - assertthat::is.string(dcsreas_var), - assertthat::is.flag(add_total), - assertthat::is.string(total_label), - assertthat::is.string(na_level), - is.character(flag_var_anl) || is.null(NULL), - is.character(flag_var_aesi) || is.null(NULL), - assertthat::is.string(aeseq_var), - assertthat::is.string(llt), - assertthat::is.flag(count_subj), - assertthat::is.flag(count_pt), - assertthat::is.flag(count_events) - ) + + checkmate::assert_string(anl_name) + checkmate::assert_string(parentname) + checkmate::assert_character(arm_var, min.len = 1, max.len = 2) + checkmate::assert_string(dthfl_var) + checkmate::assert_string(dcsreas_var) + checkmate::assert_flag(add_total) + checkmate::assert_string(total_label) + checkmate::assert_string(na_level) + checkmate::assert_character(flag_var_anl, null.ok = TRUE) + checkmate::assert_character(flag_var_aesi, null.ok = TRUE) + checkmate::assert_string(aeseq_var) + checkmate::assert_string(llt) + checkmate::assert_flag(count_subj) + checkmate::assert_flag(count_pt) + checkmate::assert_flag(count_events) y <- list() diff --git a/R/tm_t_mult_events.R b/R/tm_t_mult_events.R index 14573f9eb3..6ccffdb6ae 100644 --- a/R/tm_t_mult_events.R +++ b/R/tm_t_mult_events.R @@ -23,20 +23,18 @@ template_mult_events <- function(dataname, event_type = "event", drop_arm_levels = TRUE, basic_table_args = teal.widgets::basic_table_args()) { - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(parentname), - assertthat::is.string(arm_var), - assertthat::is.string(seq_var), - !is.null(llt), - is.null(hlt) || is.character(hlt), - assertthat::is.string(llt), - assertthat::is.flag(add_total), - assertthat::is.string(total_label), - assertthat::is.string(na_level), - assertthat::is.string(event_type), - assertthat::is.flag(drop_arm_levels) - ) + + checkmate::assert_string(dataname) + checkmate::assert_string(parentname) + checkmate::assert_string(arm_var) + checkmate::assert_string(seq_var) + checkmate::assert_character(hlt, null.ok = TRUE) + checkmate::assert_string(llt, null.ok = FALSE) + checkmate::assert_flag(add_total) + checkmate::assert_string(total_label) + checkmate::assert_string(na_level) + checkmate::assert_string(event_type) + checkmate::assert_flag(drop_arm_levels) y <- list() diff --git a/R/tm_t_pp_medical_history.R b/R/tm_t_pp_medical_history.R index 9ec5309fbb..7213c2c0e8 100644 --- a/R/tm_t_pp_medical_history.R +++ b/R/tm_t_pp_medical_history.R @@ -17,12 +17,10 @@ template_medical_history <- function(dataname = "ANL", mhbodsys = "MHBODSYS", mhdistat = "MHDISTAT", patient_id = NULL) { - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(mhterm), - assertthat::is.string(mhbodsys), - assertthat::is.string(mhdistat) - ) + checkmate::assert_string(dataname) + checkmate::assert_string(mhterm) + checkmate::assert_string(mhbodsys) + checkmate::assert_string(mhdistat) y <- list() y$table <- list() diff --git a/R/tm_t_summary_by.R b/R/tm_t_summary_by.R index 84e0fceda9..aa9d6333dd 100644 --- a/R/tm_t_summary_by.R +++ b/R/tm_t_summary_by.R @@ -33,24 +33,24 @@ template_summary_by <- function(parentname, drop_arm_levels = TRUE, drop_zero_levels = TRUE, basic_table_args = teal.widgets::basic_table_args()) { - assertthat::assert_that( - assertthat::is.string(parentname), - assertthat::is.string(dataname), - assertthat::is.string(id_var), - is.character(sum_vars), - is.character(by_vars), - is.character(var_labels), - assertthat::is.flag(add_total), - assertthat::is.string(total_label), - assertthat::is.flag(parallel_vars), - assertthat::is.flag(row_groups), - assertthat::is.flag(na.rm), - assertthat::is.string(na_level), - assertthat::is.flag(drop_arm_levels), - is.character(numeric_stats), - assertthat::is.flag(drop_zero_levels) - ) + + checkmate::assert_string(parentname) + checkmate::assert_string(dataname) + checkmate::assert_string(id_var) + checkmate::assert_character(sum_vars) + checkmate::assert_character(by_vars) + checkmate::assert_character(var_labels) + checkmate::assert_flag(add_total) + checkmate::assert_string(total_label) + checkmate::assert_flag(parallel_vars) + checkmate::assert_flag(row_groups) + checkmate::assert_flag(na.rm) + checkmate::assert_string(na_level) + checkmate::assert_flag(drop_arm_levels) + checkmate::assert_character(numeric_stats) + checkmate::assert_flag(drop_zero_levels) checkmate::assert_character(arm_var, min.len = 1, max.len = 2) + denominator <- match.arg(denominator) y <- list() From 4d05e360487f219ac177346c93d440559b0c0278 Mon Sep 17 00:00:00 2001 From: m7pr Date: Wed, 7 Feb 2024 13:26:20 +0100 Subject: [PATCH 03/31] substitute assertthat with checkmate in few more files --- R/tm_g_pp_adverse_events.R | 23 +++++++++++------------ R/tm_t_events.R | 29 ++++++++++++++--------------- R/tm_t_exposure.R | 31 +++++++++++++++---------------- R/tm_t_logistic.R | 16 +++++++--------- R/tm_t_pp_prior_medication.R | 13 ++++++------- R/tm_t_summary.R | 22 +++++++++++----------- R/tm_t_tte.R | 25 ++++++++++++------------- 7 files changed, 76 insertions(+), 83 deletions(-) diff --git a/R/tm_g_pp_adverse_events.R b/R/tm_g_pp_adverse_events.R index 728435b402..392ef05fb7 100644 --- a/R/tm_g_pp_adverse_events.R +++ b/R/tm_g_pp_adverse_events.R @@ -27,18 +27,17 @@ template_adverse_events <- function(dataname = "ANL", patient_id, font_size = 12L, ggplot2_args = teal.widgets::ggplot2_args()) { - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(aeterm), - assertthat::is.string(tox_grade), - assertthat::is.string(causality), - assertthat::is.string(outcome), - assertthat::is.string(action), - assertthat::is.string(time) || is.null(time), - assertthat::is.string(decod) || is.null(decod), - assertthat::is.string(patient_id), - is.numeric(font_size) - ) + + checkmate::assert_string(dataname) + checkmate::assert_string(aeterm) + checkmate::assert_string(tox_grade) + checkmate::assert_string(causality) + checkmate::assert_string(outcome) + checkmate::assert_string(action) + checkmate::assert_string(time, null.ok = TRUE) + checkmate::assert_string(decod, null.ok = TRUE) + checkmate::assert_string(patient_id) + checkmate::assert_numeric(font_size) y <- list() diff --git a/R/tm_t_events.R b/R/tm_t_events.R index bf82ddda98..ee0f9d50db 100644 --- a/R/tm_t_events.R +++ b/R/tm_t_events.R @@ -30,21 +30,20 @@ template_events <- function(dataname, drop_arm_levels = TRUE, incl_overall_sum = TRUE, basic_table_args = teal.widgets::basic_table_args()) { - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(parentname), - is.character(arm_var) && length(arm_var) %in% c(1, 2), - assertthat::is.string(hlt) || is.null(hlt), - assertthat::is.string(llt) || is.null(llt), - assertthat::is.string(label_hlt) || is.null(label_hlt), - assertthat::is.string(label_llt) || is.null(label_llt), - is.character(c(llt, hlt)), - assertthat::is.flag(add_total), - assertthat::is.string(total_label), - assertthat::is.string(na_level), - assertthat::is.string(event_type), - assertthat::is.flag(drop_arm_levels) - ) + + checkmate::assert_string(dataname) + checkmate::assert_string(parentname) + checkmate::assert_character(arm_var, min.len = 1, max.len = 2) + checkmate::assert_string(hlt, null.ok = TRUE) + checkmate::assert_string(llt, null.ok = TRUE) + checkmate::assert_string(label_hlt, null.ok = TRUE) + checkmate::assert_string(label_llt, null.ok = TRUE) + checkmate::assert_character(c(llt, hlt)) + checkmate::assert_flag(add_total) + checkmate::assert_string(total_label) + checkmate::assert_string(na_level) + checkmate::assert_string(event_type) + checkmate::assert_flag(drop_arm_levels) checkmate::assert_scalar(prune_freq) checkmate::assert_scalar(prune_diff) diff --git a/R/tm_t_exposure.R b/R/tm_t_exposure.R index 88f48f694a..e042dbdcb2 100644 --- a/R/tm_t_exposure.R +++ b/R/tm_t_exposure.R @@ -34,22 +34,21 @@ template_exposure <- function(parentname, aval_var, avalu_var, basic_table_args = teal.widgets::basic_table_args()) { - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(parentname), - assertthat::is.string(row_by_var), - assertthat::is.string(col_by_var) || length(col_by_var) == 0, - assertthat::is.string(paramcd), - assertthat::is.string(id_var), - assertthat::is.flag(add_total), - assertthat::is.string(total_label), - assertthat::is.flag(add_total_row), - assertthat::is.string(total_row_label), - assertthat::is.string(na_level), - assertthat::is.string(aval_var), - assertthat::is.string(avalu_var) || length(avalu_var) == 0, - assertthat::is.flag(drop_levels) - ) + + checkmate::assert_string(dataname) + checkmate::assert_string(parentname) + checkmate::assert_string(row_by_var) + checkmate::assert_string(col_by_var, null.ok = TRUE) + checkmate::assert_string(paramcd) + checkmate::assert_string(id_var) + checkmate::assert_flag(add_total) + checkmate::assert_string(total_label) + checkmate::assert_flag(add_total_row) + checkmate::assert_string(total_row_label) + checkmate::assert_string(na_level) + checkmate::assert_string(aval_var) + checkmate::assert_string(avalu_var, null.ok = TRUE) + checkmate::assert_flag(drop_levels) y <- list() data_list <- list() diff --git a/R/tm_t_logistic.R b/R/tm_t_logistic.R index ffdbc0790b..c350b72ed7 100644 --- a/R/tm_t_logistic.R +++ b/R/tm_t_logistic.R @@ -37,14 +37,12 @@ template_logistic <- function(dataname, } # Common assertion no matter if arm_var is NULL or not. - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(aval_var), - assertthat::is.string(label_paramcd) || is.null(label_paramcd), - assertthat::is.string(topleft) || is.null(topleft), - is.character(cov_var) || is.null(cov_var), - assertthat::is.string(interaction_var) || is.null(interaction_var) - ) + checkmate::assert_string(dataname) + checkmate::assert_string(aval_var) + checkmate::assert_string(label_paramcd, null.ok = TRUE) + checkmate::assert_string(topleft, null.ok = TRUE) + checkmate::assert_character(cov_var, null.ok = TRUE) + checkmate::assert_string(interaction_var, null.ok = TRUE) y <- list() @@ -54,7 +52,7 @@ template_logistic <- function(dataname, # Conditional assertion depends on if arm_var isn't NULL. if (!is.null(arm_var)) { assertthat::assert_that( - assertthat::is.string(arm_var), + checkmate::assert_string(arm_var), assertthat::is.flag(combine_comp_arms) ) diff --git a/R/tm_t_pp_prior_medication.R b/R/tm_t_pp_prior_medication.R index afcd36ced9..0ffaffa35e 100644 --- a/R/tm_t_pp_prior_medication.R +++ b/R/tm_t_pp_prior_medication.R @@ -14,13 +14,12 @@ template_prior_medication <- function(dataname = "ANL", cmdecod = "CMDECOD", cmindc = "CMINDC", cmstdy = "CMSTDY") { - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(atirel), - assertthat::is.string(cmdecod), - assertthat::is.string(cmindc), - assertthat::is.string(cmstdy) - ) + + checkmate::assert_string(dataname) + checkmate::assert_string(atirel) + checkmate::assert_string(cmdecod) + checkmate::assert_string(cmindc) + checkmate::assert_string(cmstdy) y <- list() y$table <- list() diff --git a/R/tm_t_summary.R b/R/tm_t_summary.R index 4998fb0815..86148e6242 100644 --- a/R/tm_t_summary.R +++ b/R/tm_t_summary.R @@ -27,23 +27,23 @@ template_summary <- function(dataname, denominator = c("N", "n", "omit"), drop_arm_levels = TRUE, basic_table_args = teal.widgets::basic_table_args()) { - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(parentname), - is.character(sum_vars), - assertthat::is.flag(add_total), - assertthat::is.string(total_label), - is.character(var_labels), - assertthat::is.flag(na.rm), - assertthat::is.string(na_level), - assertthat::is.flag(drop_arm_levels) - ) + + checkmate::assert_string(dataname) + checkmate::assert_string(parentname) + checkmate::assert_character(sum_vars) + checkmate::assert_flag(add_total) + checkmate::assert_string(total_label) + checkmate::assert_character(var_labels) + checkmate::assert_flag(na.rm) + checkmate::assert_string(na_level) + checkmate::assert_flag(drop_arm_levels) checkmate::assert_character(arm_var, min.len = 1, max.len = 2) checkmate::assert_character(numeric_stats, min.len = 1) checkmate::assert_subset( numeric_stats, c("n", "mean_sd", "mean_ci", "median", "median_ci", "quantiles", "range", "geom_mean") ) + denominator <- match.arg(denominator) show_labels <- match.arg(show_labels) diff --git a/R/tm_t_tte.R b/R/tm_t_tte.R index 86275e2e42..e1d118ef00 100644 --- a/R/tm_t_tte.R +++ b/R/tm_t_tte.R @@ -65,19 +65,18 @@ template_tte <- function(dataname = "ANL", total_label = default_total_label(), na_level = default_na_str(), basic_table_args = teal.widgets::basic_table_args()) { - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(parentname), - assertthat::is.string(arm_var), - assertthat::is.string(aval_var), - assertthat::is.string(cnsr_var), - assertthat::is.string(time_unit_var), - assertthat::is.string(event_desc_var), - assertthat::is.flag(compare_arm), - assertthat::is.flag(combine_comp_arms), - assertthat::is.string(total_label), - assertthat::is.string(na_level) - ) + + checkmate::assert_string(dataname) + checkmate::assert_string(parentname) + checkmate::assert_string(arm_var) + checkmate::assert_string(aval_var) + checkmate::assert_string(cnsr_var) + checkmate::assert_string(time_unit_var) + checkmate::assert_string(event_desc_var) + checkmate::assert_flag(compare_arm) + checkmate::assert_flag(combine_comp_arms) + checkmate::assert_string(total_label) + checkmate::assert_string(na_level) ref_arm_val <- paste(ref_arm, collapse = "/") y <- list() From 2ca71ce9a40fc969235dd59e034a31046b87f171 Mon Sep 17 00:00:00 2001 From: m7pr Date: Wed, 7 Feb 2024 13:32:07 +0100 Subject: [PATCH 04/31] substitute asserthtat with checkmate in few more files --- R/tm_g_forest_rsp.R | 15 +++++++-------- R/tm_g_forest_tte.R | 11 +++++------ R/tm_g_km.R | 21 ++++++++++----------- R/tm_g_pp_patient_timeline.R | 27 +++++++++++++-------------- R/tm_g_pp_vitals.R | 14 ++++++-------- 5 files changed, 41 insertions(+), 47 deletions(-) diff --git a/R/tm_g_forest_rsp.R b/R/tm_g_forest_rsp.R index 22fb258b89..2963017e58 100644 --- a/R/tm_g_forest_rsp.R +++ b/R/tm_g_forest_rsp.R @@ -34,14 +34,13 @@ template_forest_rsp <- function(dataname = "ANL", conf_level = 0.95, col_symbol_size = NULL, ggplot2_args = teal.widgets::ggplot2_args()) { - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(parentname), - assertthat::is.string(arm_var), - assertthat::is.string(aval_var), - assertthat::is.string(obj_var_name), - is.null(subgroup_var) || is.character(subgroup_var) - ) + + checkmate::assert_string(dataname) + checkmate::assert_string(parentname) + checkmate::assert_string(arm_var) + checkmate::assert_string(aval_var) + checkmate::assert_string(obj_var_name) + checkmate::assert_character(subgroup_var, null.ok = TRUE) y <- list() ref_arm_val <- paste(ref_arm, collapse = "/") diff --git a/R/tm_g_forest_tte.R b/R/tm_g_forest_tte.R index f3105204f4..53a66ac7e2 100644 --- a/R/tm_g_forest_tte.R +++ b/R/tm_g_forest_tte.R @@ -24,12 +24,11 @@ template_forest_tte <- function(dataname = "ANL", col_symbol_size = NULL, time_unit_var = "AVALU", ggplot2_args = teal.widgets::ggplot2_args()) { - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(arm_var), - assertthat::is.string(obj_var_name), - is.character(subgroup_var) || is.null(subgroup_var) - ) + + checkmate::assert_string(dataname) + checkmate::assert_string(arm_var) + checkmate::assert_string(obj_var_name) + checkmate::assert_character(subgroup_va, null.ok = TRUE) y <- list() ref_arm_val <- paste(ref_arm, collapse = "/") diff --git a/R/tm_g_km.R b/R/tm_g_km.R index a0773aa28b..66e9acab5b 100644 --- a/R/tm_g_km.R +++ b/R/tm_g_km.R @@ -37,17 +37,16 @@ template_g_km <- function(dataname = "ANL", width_annots = list(surv_med = grid::unit(0.45, "npc"), coxph = grid::unit(0.6, "npc")), ci_ribbon = FALSE, title = "KM Plot") { - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(arm_var), - assertthat::is.string(aval_var), - assertthat::is.string(cnsr_var), - assertthat::is.string(time_unit_var), - assertthat::is.flag(compare_arm), - assertthat::is.flag(combine_comp_arms), - is.null(xticks) | is.numeric(xticks), - assertthat::is.string(title) - ) + + checkmate::assert_string(dataname) + checkmate::assert_string(arm_var) + checkmate::assert_string(aval_var) + checkmate::assert_string(cnsr_var) + checkmate::assert_string(time_unit_var) + checkmate::assert_flag(compare_arm) + checkmate::assert_flag(combine_comp_arms) + checkmate::assert_numeric(xticks, null.ok = TRUE) + checkmate::assert_string(title) ref_arm_val <- paste(ref_arm, collapse = "/") y <- list() diff --git a/R/tm_g_pp_patient_timeline.R b/R/tm_g_pp_patient_timeline.R index 7103eac218..12762bf919 100644 --- a/R/tm_g_pp_patient_timeline.R +++ b/R/tm_g_pp_patient_timeline.R @@ -36,20 +36,19 @@ template_patient_timeline <- function(dataname = "ANL", ggplot2_args = teal.widgets::ggplot2_args()) { # Note: The variables used for aetime_start, aetime_end, dstime_start and dstime_end are to be # updated after random.cdisc.data updates. - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(aeterm) || is.null(aeterm), - assertthat::is.string(aetime_start) || is.null(aetime_start), - assertthat::is.string(aetime_end) || is.null(aetime_end), - assertthat::is.string(dstime_start) || is.null(dstime_start), - assertthat::is.string(dstime_end) || is.null(dstime_end), - assertthat::is.string(cmdecod) || is.null(cmdecod), - assertthat::is.string(aerelday_start) || is.null(aerelday_start), - assertthat::is.string(dsrelday_start) || is.null(dsrelday_start), - is.numeric(font_size), - is.logical(relative_day), - assertthat::is.string(patient_id) - ) + + checkmate::assert_string(dataname) + checkmate::assert_string(aeterm, null.ok = TRUE) + checkmate::assert_string(aetime_start, null.ok = TRUE) + checkmate::assert_string(aetime_end, null.ok = TRUE) + checkmate::assert_string(dstime_start, null.ok = TRUE) + checkmate::assert_string(dstime_end, null.ok = TRUE) + checkmate::assert_string(cmdecod, null.ok = TRUE) + checkmate::assert_string(aerelday_start, null.ok = TRUE) + checkmate::assert_string(dsrelday_start, null.ok = TRUE) + checkmate::assert_numeric(font_size) + checkmate::assert_logical(relative_day) + checkmate::assert_string(patient_id) chart_list <- list() if (!relative_day) { diff --git a/R/tm_g_pp_vitals.R b/R/tm_g_pp_vitals.R index 16311f304b..789d32219c 100644 --- a/R/tm_g_pp_vitals.R +++ b/R/tm_g_pp_vitals.R @@ -29,14 +29,12 @@ template_vitals <- function(dataname = "ANL", ) } - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(paramcd), - assertthat::is.string(xaxis), - assertthat::is.string(aval_var), - assertthat::is.string(patient_id), - is.numeric(font_size) - ) + checkmate::assert_string(dataname) + checkmate::assert_string(paramcd) + checkmate::assert_string(xaxis) + checkmate::assert_string(aval_var) + checkmate::assert_string(patient_id) + checkmate::assert_numeric(font_size) # Note: VSDY (study day of vital signs) was replaced with ADY (analysis day) y <- list() From 53b320a04d7ac9d40c950b4a6265f09b26637047 Mon Sep 17 00:00:00 2001 From: m7pr Date: Wed, 7 Feb 2024 13:39:16 +0100 Subject: [PATCH 05/31] remove asserthat from few more files --- R/tm_t_binary_outcome.R | 23 +++++++++++------------ R/tm_t_pp_laboratory.R | 18 ++++++++---------- R/tm_t_shift_by_grade.R | 31 +++++++++++++++---------------- R/tm_t_smq.R | 25 ++++++++++++------------- R/utils.R | 35 ++++++++++++++++------------------- 5 files changed, 62 insertions(+), 70 deletions(-) diff --git a/R/tm_t_binary_outcome.R b/R/tm_t_binary_outcome.R index 7266dcf56e..92b57e5367 100644 --- a/R/tm_t_binary_outcome.R +++ b/R/tm_t_binary_outcome.R @@ -36,18 +36,17 @@ template_binary_outcome <- function(dataname, total_label = default_total_label(), na_level = default_na_str(), basic_table_args = teal.widgets::basic_table_args()) { - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(parentname), - assertthat::is.string(arm_var), - assertthat::is.string(aval_var), - assertthat::is.flag(compare_arm), - assertthat::is.flag(combine_comp_arms), - assertthat::is.flag(show_rsp_cat), - assertthat::is.flag(add_total), - assertthat::is.string(na_level), - assertthat::is.string(total_label) - ) + + checkmate::assert_string(dataname) + checkmate::assert_string(parentname) + checkmate::assert_string(arm_var) + checkmate::assert_string(aval_var) + checkmate::assert_flag(compare_arm) + checkmate::assert_flag(combine_comp_arms) + checkmate::assert_flag(show_rsp_cat) + checkmate::assert_flag(add_total) + checkmate::assert_string(na_level) + checkmate::assert_string(total_label) ref_arm_val <- paste(ref_arm, collapse = "/") y <- list() diff --git a/R/tm_t_pp_laboratory.R b/R/tm_t_pp_laboratory.R index 55be709978..694c516d4f 100644 --- a/R/tm_t_pp_laboratory.R +++ b/R/tm_t_pp_laboratory.R @@ -43,16 +43,14 @@ template_laboratory <- function(dataname = "ANL", ) } - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(paramcd), - assertthat::is.string(param), - assertthat::is.string(anrind), - assertthat::is.string(timepoints), - assertthat::is.string(aval_var), - assertthat::is.string(avalu_var), - is.integer(round_value) && round_value >= 0 - ) + checkmate::assert_string(dataname) + checkmate::assert_string(paramcd) + checkmate::assert_string(param) + checkmate::assert_string(anrind) + checkmate::assert_string(timepoints) + checkmate::assert_string(aval_var) + checkmate::assert_string(avalu_var) + checkmate::assert_integer(round_value, lower = 0) y <- list() y$table <- list() diff --git a/R/tm_t_shift_by_grade.R b/R/tm_t_shift_by_grade.R index ffceeec190..54f072140e 100644 --- a/R/tm_t_shift_by_grade.R +++ b/R/tm_t_shift_by_grade.R @@ -28,22 +28,21 @@ template_shift_by_grade <- function(parentname, na_level = default_na_str(), code_missing_baseline = FALSE, basic_table_args = teal.widgets::basic_table_args()) { - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(parentname), - assertthat::is.string(arm_var), - assertthat::is.string(id_var), - assertthat::is.string(visit_var), - assertthat::is.string(worst_flag_indicator), - is.character(worst_flag_var), - assertthat::is.string(anl_toxgrade_var), - assertthat::is.string(base_toxgrade_var), - assertthat::is.string(paramcd), - assertthat::is.flag(drop_arm_levels), - assertthat::is.flag(add_total), - assertthat::is.string(total_label), - assertthat::is.string(na_level) - ) + + checkmate::assert_string(dataname) + checkmate::assert_string(parentname) + checkmate::assert_string(arm_var) + checkmate::assert_string(id_var) + checkmate::assert_string(visit_var) + checkmate::assert_string(worst_flag_indicator) + checkmate::assert_character(worst_flag_var) + checkmate::assert_string(anl_toxgrade_var) + checkmate::assert_string(base_toxgrade_var) + checkmate::assert_string(paramcd) + checkmate::assert_flag(drop_arm_levels) + checkmate::assert_flag(add_total) + checkmate::assert_string(total_label) + checkmate::assert_string(na_level) worst_flag_var <- match.arg(worst_flag_var) diff --git a/R/tm_t_smq.R b/R/tm_t_smq.R index 98bdf7f132..2ccf919d90 100644 --- a/R/tm_t_smq.R +++ b/R/tm_t_smq.R @@ -24,19 +24,18 @@ template_smq <- function(dataname, baskets = c("SMQ01NAM", "SMQ02NAM", "CQ01NAM"), id_var = "USUBJID", basic_table_args = teal.widgets::basic_table_args()) { - assertthat::assert_that( - assertthat::is.string(parentname), - assertthat::is.string(dataname), - is.character(arm_var) && length(arm_var) %in% c(1, 2), - assertthat::is.string(id_var), - assertthat::is.string(llt), - assertthat::is.flag(add_total), - assertthat::is.string(total_label), - assertthat::is.flag(drop_arm_levels), - assertthat::is.string(na_level), - assertthat::is.string(smq_varlabel), - is.character(baskets) - ) + + checkmate::assert_string(parentname) + checkmate::assert_string(dataname) + checkmate::assert_character(arm_var, min.len = 1, max.len = 2) + checkmate::assert_string(id_var) + checkmate::assert_string(llt) + checkmate::assert_flag(add_total) + checkmate::assert_string(total_label) + checkmate::assert_flag(drop_arm_levels) + checkmate::assert_string(na_level) + checkmate::assert_string(smq_varlabel) + checkmate::assert_character(baskets) sort_criteria <- match.arg(sort_criteria) diff --git a/R/utils.R b/R/utils.R index c49a7c5d38..bb1e8cbf23 100644 --- a/R/utils.R +++ b/R/utils.R @@ -138,7 +138,6 @@ pipe_expr <- function(exprs, pipe_str = "%>%") { #' list. The list of expressions can be later used to generate a pipeline, #' for instance with `pipe_expr`. #' -#' @import assertthat #' @export #' #' @examples @@ -159,9 +158,9 @@ pipe_expr <- function(exprs, pipe_str = "%>%") { #' lyt <- teal.modules.clinical:::add_expr(lyt, quote(rtables::build_table(df = dta))) #' teal.modules.clinical:::pipe_expr(lyt) add_expr <- function(expr_ls, new_expr) { - assertthat::assert_that( - is.list(expr_ls), - is.call(new_expr) || is.name(new_expr) + stopifnot( + is.list(expr_ls) && + (is.call(new_expr) || is.name(new_expr)) ) # support nested expressions such as expr({a <- 1; b <- 2}) @@ -528,15 +527,14 @@ prepare_arm <- function(dataname, compare_arm = !is.null(ref_arm), ref_arm_val = paste(ref_arm, collapse = "/"), drop = TRUE) { - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(arm_var), - is.null(ref_arm) || is.character(ref_arm), - is.character(comp_arm) || is.null(comp_arm), - assertthat::is.flag(compare_arm), - assertthat::is.string(ref_arm_val), - assertthat::is.flag(drop) - ) + + checkmate::assert_string(dataname) + checkmate::assert_string(arm_var) + checkmate::assert_character(ref_arm, null.ok = TRUE) + checkmate::assert_character(comp_arm, null.ok = TRUE) + checkmate::assert_flag(compare_arm) + checkmate::assert_string(ref_arm_val) + checkmate::assert_flag(drop) data_list <- list() @@ -629,12 +627,11 @@ prepare_arm_levels <- function(dataname, parentname, arm_var, drop_arm_levels = TRUE) { - assertthat::assert_that( - assertthat::is.string(dataname), - assertthat::is.string(parentname), - assertthat::is.string(arm_var), - assertthat::is.flag(drop_arm_levels) - ) + + checkmate::assert_string(dataname) + checkmate::assert_string(parentname) + checkmate::assert_string(arm_var) + checkmate::assert_flag(drop_arm_levels) data_list <- list() From 3eaef34b45ee4ecde95ec7fde5c39aa8a04aa994 Mon Sep 17 00:00:00 2001 From: m7pr Date: Wed, 7 Feb 2024 13:50:16 +0100 Subject: [PATCH 06/31] remove assertthat complitely --- .pre-commit-config.yaml | 1 - DESCRIPTION | 3 +-- NAMESPACE | 1 - R/dynamic_assertions.R | 5 ++--- R/tm_g_forest_rsp.R | 5 +---- R/tm_g_pp_patient_timeline.R | 10 +++++----- R/tm_t_events_by_grade.R | 36 +++++++++++++++++------------------- R/tm_t_logistic.R | 6 ++---- man/dyn_assertion.Rd | 5 ++--- man/teal.modules.clinical.Rd | 1 - 10 files changed, 30 insertions(+), 43 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 35c7cbd95d..710d0e6c68 100755 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,6 @@ repos: - insightsengineering/teal - insightsengineering/teal.transform - tern - - assertthat - broom - checkmate - dplyr diff --git a/DESCRIPTION b/DESCRIPTION index b010099771..6a825fb644 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -30,7 +30,6 @@ Depends: teal.transform (>= 0.4.0.9011), tern (>= 0.9.3) Imports: - assertthat, broom (>= 0.7.10), checkmate (>= 2.1.0), dplyr (>= 1.0.5), @@ -71,7 +70,7 @@ VignetteBuilder: knitr Config/Needs/verdepcheck: insightsengineering/teal, insightsengineering/teal.transform, insightsengineering/tern, - cran/assertthat, tidymodels/broom, mllg/checkmate, tidyverse/dplyr, + tidymodels/broom, mllg/checkmate, tidyverse/dplyr, rstudio/DT, insightsengineering/formatters, tidyverse/ggplot2, slowkow/ggrepel, r-lib/lifecycle, daroczig/logger, tidyverse/magrittr, r-lib/rlang, insightsengineering/rlistings, rstudio/rmarkdown, diff --git a/NAMESPACE b/NAMESPACE index 10e6611848..0876fae85d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -65,7 +65,6 @@ export(tm_t_smq) export(tm_t_summary) export(tm_t_summary_by) export(tm_t_tte) -import(assertthat) import(teal) import(teal.transform) import(tern) diff --git a/R/dynamic_assertions.R b/R/dynamic_assertions.R index fc922e96bc..73d04ced6d 100644 --- a/R/dynamic_assertions.R +++ b/R/dynamic_assertions.R @@ -15,9 +15,8 @@ NULL #' #' @examples #' -#' library(assertthat) #' library(testthat) -#' expect_error(assertthat::assert_that(teal_enough_rows(data = iris, min_nrow = 1500))) +#' expect_error(stopifnot(teal_enough_rows(data = iris, min_nrow = 1500))) teal_enough_rows <- function(data, min_nrow) nrow(data) >= min_nrow assertthat::on_failure(teal_enough_rows) <- function(call, env) { call[[1]] <- validate_enough_rows @@ -45,7 +44,7 @@ validate_enough_rows <- function(data, min_nrow) { #' @examples #' #' armcd <- NULL -#' expect_error(assertthat::assert_that(teal_has_element(str = armcd, "ARMCD"))) +#' expect_error(stopifnot(teal_has_element(str = armcd, "ARMCD"))) teal_has_element <- function(str, ...) length(str) > 0 assertthat::on_failure(teal_has_element) <- function(call, env) { call[[1]] <- validate_has_elements diff --git a/R/tm_g_forest_rsp.R b/R/tm_g_forest_rsp.R index 2963017e58..4a0efa6e0a 100644 --- a/R/tm_g_forest_rsp.R +++ b/R/tm_g_forest_rsp.R @@ -311,10 +311,7 @@ tm_g_forest_rsp <- function(label, checkmate::assert_string(parentname) checkmate::assert_flag(fixed_symbol_size) checkmate::assert_class(conf_level, "choices_selected") - assertthat::assert_that( - inherits(default_responses, c("list", "character", "numeric", "NULL")), - msg = "`default_responses` must be a named list or an array." - ) + checkmate::assert_multi_class(default_responses, c("list", "character", "numeric"), null.ok = TRUE) checkmate::assert_numeric(plot_height, len = 3, any.missing = FALSE, finite = TRUE) checkmate::assert_numeric(plot_height[1], lower = plot_height[2], upper = plot_height[3], .var.name = "plot_height") checkmate::assert_numeric(plot_width, len = 3, any.missing = FALSE, null.ok = TRUE, finite = TRUE) diff --git a/R/tm_g_pp_patient_timeline.R b/R/tm_g_pp_patient_timeline.R index 12762bf919..edb5fcba70 100644 --- a/R/tm_g_pp_patient_timeline.R +++ b/R/tm_g_pp_patient_timeline.R @@ -470,11 +470,11 @@ tm_g_pp_patient_timeline <- function(label, plot_width[1], lower = plot_width[2], upper = plot_width[3], null.ok = TRUE, .var.name = "plot_width" ) - assertthat::assert_that(!xor(is.null(aetime_start), is.null(aetime_end))) - assertthat::assert_that(!xor(is.null(dstime_start), is.null(dstime_end))) - assertthat::assert_that(!xor(is.null(aerelday_start), is.null(aerelday_end))) - assertthat::assert_that(!xor(is.null(dsrelday_start), is.null(dsrelday_end))) - assertthat::assert_that( + stopifnot(!xor(is.null(aetime_start), is.null(aetime_end))) + stopifnot(!xor(is.null(dstime_start), is.null(dstime_end))) + stopifnot(!xor(is.null(aerelday_start), is.null(aerelday_end))) + stopifnot(!xor(is.null(dsrelday_start), is.null(dsrelday_end))) + stopifnot( (!is.null(aeterm) && (!is.null(aetime_start) || !is.null(aerelday_start))) || (!is.null(cmdecod) && (!is.null(dstime_start) || !is.null(dsrelday_start))) ) diff --git a/R/tm_t_events_by_grade.R b/R/tm_t_events_by_grade.R index 294d06539f..e89b13ecc1 100644 --- a/R/tm_t_events_by_grade.R +++ b/R/tm_t_events_by_grade.R @@ -408,27 +408,25 @@ template_events_col_by_grade <- function(dataname, na_level = default_na_str(), drop_arm_levels = TRUE, basic_table_args = teal.widgets::basic_table_args()) { - assertthat::assert_that( - checkmate::assert_string(dataname), - checkmate::assert_string(parentname), - checkmate::assert_string(arm_var), - is.list(grading_groups), - checkmate::assert_flag(add_total), - checkmate::assert_string(total_label), - checkmate::assert_string(id), - checkmate::assert_string(hlt) || is.null(hlt), - checkmate::assert_string(llt), - checkmate::assert_string(grade), - checkmate::assert_string(label_hlt) || is.null(label_hlt), - checkmate::assert_string(label_llt) || is.null(label_llt), - checkmate::assert_string(label_grade) || is.null(label_grade), - checkmate::assert_string(na_level), - checkmate::assert_flag(drop_arm_levels) - ) + + checkmate::assert_string(dataname) + checkmate::assert_string(parentname) + checkmate::assert_string(arm_var) + checkmate::assert_list(grading_groups) + checkmate::assert_flag(add_total) + checkmate::assert_string(total_label) + checkmate::assert_string(id) + checkmate::assert_string(hlt, null.ok = TRUE) + checkmate::assert_string(llt) + checkmate::assert_string(grade) + checkmate::assert_string(label_hlt, null.ok = TRUE) + checkmate::assert_string(label_llt, null.ok = TRUE) + checkmate::assert_string(label_grade, null.ok = TRUE) + checkmate::assert_string(na_level) + checkmate::assert_flag(drop_arm_levels) checkmate::assert_scalar(prune_freq) checkmate::assert_scalar(prune_diff) - y <- list() # Start data steps. @@ -1095,7 +1093,7 @@ srv_t_events_by_grade <- function(id, anl_filtered <- merged$anl_q()[[dataname]] adsl_keys <- merged$adsl_input_r()$keys - assertthat::assert_that("USUBJID" %in% adsl_keys) + stopifnot("USUBJID" %in% adsl_keys) input_arm_var <- as.vector(merged$anl_input_r()$columns_source$arm_var) input_level_term <- c( diff --git a/R/tm_t_logistic.R b/R/tm_t_logistic.R index c350b72ed7..3bd1cc66d0 100644 --- a/R/tm_t_logistic.R +++ b/R/tm_t_logistic.R @@ -51,10 +51,8 @@ template_logistic <- function(dataname, # Conditional assertion depends on if arm_var isn't NULL. if (!is.null(arm_var)) { - assertthat::assert_that( - checkmate::assert_string(arm_var), - assertthat::is.flag(combine_comp_arms) - ) + checkmate::assert_string(arm_var) + checkmate::assert_flag(combine_comp_arms) ref_arm_val <- paste(ref_arm, collapse = "/") diff --git a/man/dyn_assertion.Rd b/man/dyn_assertion.Rd index 9b9881a0b6..ad95be1326 100644 --- a/man/dyn_assertion.Rd +++ b/man/dyn_assertion.Rd @@ -31,11 +31,10 @@ Verifies assertions for dynamic outputs. }} \examples{ -library(assertthat) library(testthat) -expect_error(assertthat::assert_that(teal_enough_rows(data = iris, min_nrow = 1500))) +expect_error(stopifnot(teal_enough_rows(data = iris, min_nrow = 1500))) armcd <- NULL -expect_error(assertthat::assert_that(teal_has_element(str = armcd, "ARMCD"))) +expect_error(stopifnot(teal_has_element(str = armcd, "ARMCD"))) } \keyword{internal} diff --git a/man/teal.modules.clinical.Rd b/man/teal.modules.clinical.Rd index 8f563d4bfb..bcce24abd2 100644 --- a/man/teal.modules.clinical.Rd +++ b/man/teal.modules.clinical.Rd @@ -2,7 +2,6 @@ % Please edit documentation in R/teal.modules.clinical.R \docType{package} \name{teal.modules.clinical} -\alias{teal.modules.clinical-package} \alias{teal.modules.clinical} \title{Teal Modules for Standard Clinical Outputs} \description{ From 24dabd310f128eff4d64518bc13ad85dae1b4e61 Mon Sep 17 00:00:00 2001 From: m7pr Date: Wed, 7 Feb 2024 13:55:02 +0100 Subject: [PATCH 07/31] change is.numeric to checkmate::assert_numeric in tm_g_pp_therapy --- R/tm_g_pp_therapy.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/tm_g_pp_therapy.R b/R/tm_g_pp_therapy.R index 8146341e9b..313d422db9 100644 --- a/R/tm_g_pp_therapy.R +++ b/R/tm_g_pp_therapy.R @@ -43,7 +43,7 @@ template_therapy <- function(dataname = "ANL", checkmate::assert_string(cmstdy) checkmate::assert_string(cmendy) checkmate::assert_string(patient_id) - is.numeric(font_size) + checkmate::assert_numeric(font_size) y <- list() y$table_list <- list() From 37ffe559787f9dd86f9ac732b45469d0478220f4 Mon Sep 17 00:00:00 2001 From: "27856297+dependabot-preview[bot]@users.noreply.github.com" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 7 Feb 2024 13:00:37 +0000 Subject: [PATCH 08/31] [skip actions] Roxygen Man Pages Auto Update --- man/teal.modules.clinical.Rd | 1 + 1 file changed, 1 insertion(+) diff --git a/man/teal.modules.clinical.Rd b/man/teal.modules.clinical.Rd index bcce24abd2..8f563d4bfb 100644 --- a/man/teal.modules.clinical.Rd +++ b/man/teal.modules.clinical.Rd @@ -2,6 +2,7 @@ % Please edit documentation in R/teal.modules.clinical.R \docType{package} \name{teal.modules.clinical} +\alias{teal.modules.clinical-package} \alias{teal.modules.clinical} \title{Teal Modules for Standard Clinical Outputs} \description{ From 0ecc85374e9cb4cf06b10e0719f7ecfa4e3d5df0 Mon Sep 17 00:00:00 2001 From: m7pr Date: Wed, 7 Feb 2024 14:04:50 +0100 Subject: [PATCH 09/31] Empty-Commit From f95e5a837221896a9205b6c16887cd06508cde3e Mon Sep 17 00:00:00 2001 From: m7pr Date: Wed, 7 Feb 2024 14:08:55 +0100 Subject: [PATCH 10/31] typo --- R/tm_g_forest_tte.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/tm_g_forest_tte.R b/R/tm_g_forest_tte.R index 53a66ac7e2..b42fe2bae9 100644 --- a/R/tm_g_forest_tte.R +++ b/R/tm_g_forest_tte.R @@ -28,7 +28,7 @@ template_forest_tte <- function(dataname = "ANL", checkmate::assert_string(dataname) checkmate::assert_string(arm_var) checkmate::assert_string(obj_var_name) - checkmate::assert_character(subgroup_va, null.ok = TRUE) + checkmate::assert_character(subgroup_var, null.ok = TRUE) y <- list() ref_arm_val <- paste(ref_arm, collapse = "/") From d08e2c5f113324f5e35d08331a269967bbd5c01a Mon Sep 17 00:00:00 2001 From: m7pr Date: Wed, 7 Feb 2024 14:13:30 +0100 Subject: [PATCH 11/31] change order of testing for interact_y in tm_t_ancova --- R/tm_t_ancova.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/tm_t_ancova.R b/R/tm_t_ancova.R index ba268f5f9a..c3136f827b 100644 --- a/R/tm_t_ancova.R +++ b/R/tm_t_ancova.R @@ -42,6 +42,7 @@ template_ancova <- function(dataname = "ANL", visit_var = "AVISIT", conf_level = 0.95, basic_table_args = teal.widgets::basic_table_args()) { + checkmate::assert_string(dataname) checkmate::assert_string(parentname) checkmate::assert_string(arm_var) @@ -50,7 +51,7 @@ template_ancova <- function(dataname = "ANL", checkmate::assert_string(aval_var) checkmate::assert_character(cov_var) checkmate::assert_flag(include_interact) - stopifnot(all(sapply(interact_y, checkmate::assert_string)) || isFALSE(interact_y)) + if (isTRUE(interact_y)) { all(sapply(interact_y, checkmate::assert_string)) } checkmate::assert_string(interact_var, null.ok = TRUE) y <- list() From 40401e61d591d2261a1c1eb3eae1e148ef2b8478 Mon Sep 17 00:00:00 2001 From: m7pr Date: Wed, 7 Feb 2024 14:33:56 +0100 Subject: [PATCH 12/31] remove curly brackets --- R/tm_t_ancova.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/tm_t_ancova.R b/R/tm_t_ancova.R index c3136f827b..c844a96d4f 100644 --- a/R/tm_t_ancova.R +++ b/R/tm_t_ancova.R @@ -51,7 +51,7 @@ template_ancova <- function(dataname = "ANL", checkmate::assert_string(aval_var) checkmate::assert_character(cov_var) checkmate::assert_flag(include_interact) - if (isTRUE(interact_y)) { all(sapply(interact_y, checkmate::assert_string)) } + if (isTRUE(interact_y)) all(sapply(interact_y, checkmate::assert_string)) checkmate::assert_string(interact_var, null.ok = TRUE) y <- list() From 8112e0956b0aa1fc31faa201375dcc97009fb629 Mon Sep 17 00:00:00 2001 From: m7pr Date: Wed, 7 Feb 2024 15:41:05 +0100 Subject: [PATCH 13/31] styling files --- R/tm_g_forest_rsp.R | 1 - R/tm_g_forest_tte.R | 1 - R/tm_g_km.R | 1 - R/tm_g_lineplot.R | 1 - R/tm_g_pp_adverse_events.R | 1 - R/tm_g_pp_therapy.R | 1 - R/tm_t_abnormality.R | 1 - R/tm_t_abnormality_by_worst_grade.R | 1 - R/tm_t_ancova.R | 1 - R/tm_t_binary_outcome.R | 1 - R/tm_t_events.R | 1 - R/tm_t_events_by_grade.R | 2 -- R/tm_t_events_summary.R | 1 - R/tm_t_exposure.R | 1 - R/tm_t_mult_events.R | 1 - R/tm_t_pp_prior_medication.R | 1 - R/tm_t_shift_by_grade.R | 1 - R/tm_t_smq.R | 1 - R/tm_t_summary.R | 1 - R/tm_t_summary_by.R | 1 - R/tm_t_tte.R | 1 - R/utils.R | 4 +--- 22 files changed, 1 insertion(+), 25 deletions(-) diff --git a/R/tm_g_forest_rsp.R b/R/tm_g_forest_rsp.R index 4a0efa6e0a..6edcb4c57d 100644 --- a/R/tm_g_forest_rsp.R +++ b/R/tm_g_forest_rsp.R @@ -34,7 +34,6 @@ template_forest_rsp <- function(dataname = "ANL", conf_level = 0.95, col_symbol_size = NULL, ggplot2_args = teal.widgets::ggplot2_args()) { - checkmate::assert_string(dataname) checkmate::assert_string(parentname) checkmate::assert_string(arm_var) diff --git a/R/tm_g_forest_tte.R b/R/tm_g_forest_tte.R index b42fe2bae9..ce19aff206 100644 --- a/R/tm_g_forest_tte.R +++ b/R/tm_g_forest_tte.R @@ -24,7 +24,6 @@ template_forest_tte <- function(dataname = "ANL", col_symbol_size = NULL, time_unit_var = "AVALU", ggplot2_args = teal.widgets::ggplot2_args()) { - checkmate::assert_string(dataname) checkmate::assert_string(arm_var) checkmate::assert_string(obj_var_name) diff --git a/R/tm_g_km.R b/R/tm_g_km.R index 66e9acab5b..95c528b620 100644 --- a/R/tm_g_km.R +++ b/R/tm_g_km.R @@ -37,7 +37,6 @@ template_g_km <- function(dataname = "ANL", width_annots = list(surv_med = grid::unit(0.45, "npc"), coxph = grid::unit(0.6, "npc")), ci_ribbon = FALSE, title = "KM Plot") { - checkmate::assert_string(dataname) checkmate::assert_string(arm_var) checkmate::assert_string(aval_var) diff --git a/R/tm_g_lineplot.R b/R/tm_g_lineplot.R index b372f52bd1..6ed0ee91a6 100644 --- a/R/tm_g_lineplot.R +++ b/R/tm_g_lineplot.R @@ -39,7 +39,6 @@ template_g_lineplot <- function(dataname = "ANL", title = "Line Plot", y_lab = "", ggplot2_args = teal.widgets::ggplot2_args()) { - checkmate::assert_string(dataname) checkmate::assert_string(strata) checkmate::assert_string(x) diff --git a/R/tm_g_pp_adverse_events.R b/R/tm_g_pp_adverse_events.R index 392ef05fb7..e3e191ca90 100644 --- a/R/tm_g_pp_adverse_events.R +++ b/R/tm_g_pp_adverse_events.R @@ -27,7 +27,6 @@ template_adverse_events <- function(dataname = "ANL", patient_id, font_size = 12L, ggplot2_args = teal.widgets::ggplot2_args()) { - checkmate::assert_string(dataname) checkmate::assert_string(aeterm) checkmate::assert_string(tox_grade) diff --git a/R/tm_g_pp_therapy.R b/R/tm_g_pp_therapy.R index 313d422db9..d858c88a1b 100644 --- a/R/tm_g_pp_therapy.R +++ b/R/tm_g_pp_therapy.R @@ -30,7 +30,6 @@ template_therapy <- function(dataname = "ANL", patient_id, font_size = 12L, ggplot2_args = teal.widgets::ggplot2_args()) { - checkmate::assert_string(dataname) checkmate::assert_string(atirel) checkmate::assert_string(cmdecod) diff --git a/R/tm_t_abnormality.R b/R/tm_t_abnormality.R index ef404fd0ef..2c47a9ff8c 100644 --- a/R/tm_t_abnormality.R +++ b/R/tm_t_abnormality.R @@ -34,7 +34,6 @@ template_abnormality <- function(parentname, na_level = default_na_str(), basic_table_args = teal.widgets::basic_table_args(), tbl_title) { - checkmate::assert_string(dataname) checkmate::assert_string(id_var) checkmate::assert_string(parentname) diff --git a/R/tm_t_abnormality_by_worst_grade.R b/R/tm_t_abnormality_by_worst_grade.R index 4a30f667c8..b2aa7d0be4 100644 --- a/R/tm_t_abnormality_by_worst_grade.R +++ b/R/tm_t_abnormality_by_worst_grade.R @@ -28,7 +28,6 @@ template_abnormality_by_worst_grade <- function(parentname, # nolint total_label = default_total_label(), drop_arm_levels = TRUE, basic_table_args = teal.widgets::basic_table_args()) { - checkmate::assert_string(dataname) checkmate::assert_string(parentname) checkmate::assert_string(arm_var) diff --git a/R/tm_t_ancova.R b/R/tm_t_ancova.R index c844a96d4f..c0017c7fd2 100644 --- a/R/tm_t_ancova.R +++ b/R/tm_t_ancova.R @@ -42,7 +42,6 @@ template_ancova <- function(dataname = "ANL", visit_var = "AVISIT", conf_level = 0.95, basic_table_args = teal.widgets::basic_table_args()) { - checkmate::assert_string(dataname) checkmate::assert_string(parentname) checkmate::assert_string(arm_var) diff --git a/R/tm_t_binary_outcome.R b/R/tm_t_binary_outcome.R index 92b57e5367..c695afac2e 100644 --- a/R/tm_t_binary_outcome.R +++ b/R/tm_t_binary_outcome.R @@ -36,7 +36,6 @@ template_binary_outcome <- function(dataname, total_label = default_total_label(), na_level = default_na_str(), basic_table_args = teal.widgets::basic_table_args()) { - checkmate::assert_string(dataname) checkmate::assert_string(parentname) checkmate::assert_string(arm_var) diff --git a/R/tm_t_events.R b/R/tm_t_events.R index ee0f9d50db..49e3f62465 100644 --- a/R/tm_t_events.R +++ b/R/tm_t_events.R @@ -30,7 +30,6 @@ template_events <- function(dataname, drop_arm_levels = TRUE, incl_overall_sum = TRUE, basic_table_args = teal.widgets::basic_table_args()) { - checkmate::assert_string(dataname) checkmate::assert_string(parentname) checkmate::assert_character(arm_var, min.len = 1, max.len = 2) diff --git a/R/tm_t_events_by_grade.R b/R/tm_t_events_by_grade.R index e89b13ecc1..1df3660b5c 100644 --- a/R/tm_t_events_by_grade.R +++ b/R/tm_t_events_by_grade.R @@ -30,7 +30,6 @@ template_events_by_grade <- function(dataname, na_level = default_na_str(), drop_arm_levels = TRUE, basic_table_args = teal.widgets::basic_table_args()) { - checkmate::assert_string(dataname) checkmate::assert_string(parentname) checkmate::assert_string(arm_var) @@ -408,7 +407,6 @@ template_events_col_by_grade <- function(dataname, na_level = default_na_str(), drop_arm_levels = TRUE, basic_table_args = teal.widgets::basic_table_args()) { - checkmate::assert_string(dataname) checkmate::assert_string(parentname) checkmate::assert_string(arm_var) diff --git a/R/tm_t_events_summary.R b/R/tm_t_events_summary.R index 994a319b13..909b6ae774 100644 --- a/R/tm_t_events_summary.R +++ b/R/tm_t_events_summary.R @@ -42,7 +42,6 @@ template_events_summary <- function(anl_name, count_subj = TRUE, count_pt = TRUE, count_events = TRUE) { - checkmate::assert_string(anl_name) checkmate::assert_string(parentname) checkmate::assert_character(arm_var, min.len = 1, max.len = 2) diff --git a/R/tm_t_exposure.R b/R/tm_t_exposure.R index e042dbdcb2..bbc39e9da4 100644 --- a/R/tm_t_exposure.R +++ b/R/tm_t_exposure.R @@ -34,7 +34,6 @@ template_exposure <- function(parentname, aval_var, avalu_var, basic_table_args = teal.widgets::basic_table_args()) { - checkmate::assert_string(dataname) checkmate::assert_string(parentname) checkmate::assert_string(row_by_var) diff --git a/R/tm_t_mult_events.R b/R/tm_t_mult_events.R index 6ccffdb6ae..01db87f92c 100644 --- a/R/tm_t_mult_events.R +++ b/R/tm_t_mult_events.R @@ -23,7 +23,6 @@ template_mult_events <- function(dataname, event_type = "event", drop_arm_levels = TRUE, basic_table_args = teal.widgets::basic_table_args()) { - checkmate::assert_string(dataname) checkmate::assert_string(parentname) checkmate::assert_string(arm_var) diff --git a/R/tm_t_pp_prior_medication.R b/R/tm_t_pp_prior_medication.R index 0ffaffa35e..c85924ffa0 100644 --- a/R/tm_t_pp_prior_medication.R +++ b/R/tm_t_pp_prior_medication.R @@ -14,7 +14,6 @@ template_prior_medication <- function(dataname = "ANL", cmdecod = "CMDECOD", cmindc = "CMINDC", cmstdy = "CMSTDY") { - checkmate::assert_string(dataname) checkmate::assert_string(atirel) checkmate::assert_string(cmdecod) diff --git a/R/tm_t_shift_by_grade.R b/R/tm_t_shift_by_grade.R index 54f072140e..26e892cce3 100644 --- a/R/tm_t_shift_by_grade.R +++ b/R/tm_t_shift_by_grade.R @@ -28,7 +28,6 @@ template_shift_by_grade <- function(parentname, na_level = default_na_str(), code_missing_baseline = FALSE, basic_table_args = teal.widgets::basic_table_args()) { - checkmate::assert_string(dataname) checkmate::assert_string(parentname) checkmate::assert_string(arm_var) diff --git a/R/tm_t_smq.R b/R/tm_t_smq.R index 2ccf919d90..9b2d65ec2f 100644 --- a/R/tm_t_smq.R +++ b/R/tm_t_smq.R @@ -24,7 +24,6 @@ template_smq <- function(dataname, baskets = c("SMQ01NAM", "SMQ02NAM", "CQ01NAM"), id_var = "USUBJID", basic_table_args = teal.widgets::basic_table_args()) { - checkmate::assert_string(parentname) checkmate::assert_string(dataname) checkmate::assert_character(arm_var, min.len = 1, max.len = 2) diff --git a/R/tm_t_summary.R b/R/tm_t_summary.R index 86148e6242..881416c022 100644 --- a/R/tm_t_summary.R +++ b/R/tm_t_summary.R @@ -27,7 +27,6 @@ template_summary <- function(dataname, denominator = c("N", "n", "omit"), drop_arm_levels = TRUE, basic_table_args = teal.widgets::basic_table_args()) { - checkmate::assert_string(dataname) checkmate::assert_string(parentname) checkmate::assert_character(sum_vars) diff --git a/R/tm_t_summary_by.R b/R/tm_t_summary_by.R index aa9d6333dd..15830d3cf0 100644 --- a/R/tm_t_summary_by.R +++ b/R/tm_t_summary_by.R @@ -33,7 +33,6 @@ template_summary_by <- function(parentname, drop_arm_levels = TRUE, drop_zero_levels = TRUE, basic_table_args = teal.widgets::basic_table_args()) { - checkmate::assert_string(parentname) checkmate::assert_string(dataname) checkmate::assert_string(id_var) diff --git a/R/tm_t_tte.R b/R/tm_t_tte.R index e1d118ef00..02789dfcc5 100644 --- a/R/tm_t_tte.R +++ b/R/tm_t_tte.R @@ -65,7 +65,6 @@ template_tte <- function(dataname = "ANL", total_label = default_total_label(), na_level = default_na_str(), basic_table_args = teal.widgets::basic_table_args()) { - checkmate::assert_string(dataname) checkmate::assert_string(parentname) checkmate::assert_string(arm_var) diff --git a/R/utils.R b/R/utils.R index bb1e8cbf23..130602cd57 100644 --- a/R/utils.R +++ b/R/utils.R @@ -160,7 +160,7 @@ pipe_expr <- function(exprs, pipe_str = "%>%") { add_expr <- function(expr_ls, new_expr) { stopifnot( is.list(expr_ls) && - (is.call(new_expr) || is.name(new_expr)) + (is.call(new_expr) || is.name(new_expr)) ) # support nested expressions such as expr({a <- 1; b <- 2}) @@ -527,7 +527,6 @@ prepare_arm <- function(dataname, compare_arm = !is.null(ref_arm), ref_arm_val = paste(ref_arm, collapse = "/"), drop = TRUE) { - checkmate::assert_string(dataname) checkmate::assert_string(arm_var) checkmate::assert_character(ref_arm, null.ok = TRUE) @@ -627,7 +626,6 @@ prepare_arm_levels <- function(dataname, parentname, arm_var, drop_arm_levels = TRUE) { - checkmate::assert_string(dataname) checkmate::assert_string(parentname) checkmate::assert_string(arm_var) From a53fcb50a82f01ed1dc83e248f392bb8349d586d Mon Sep 17 00:00:00 2001 From: m7pr Date: Wed, 7 Feb 2024 15:47:43 +0100 Subject: [PATCH 14/31] more informative message in t_events_by_grade --- R/tm_t_events_by_grade.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/tm_t_events_by_grade.R b/R/tm_t_events_by_grade.R index 1df3660b5c..3b5d908e3f 100644 --- a/R/tm_t_events_by_grade.R +++ b/R/tm_t_events_by_grade.R @@ -35,7 +35,7 @@ template_events_by_grade <- function(dataname, checkmate::assert_string(arm_var) checkmate::assert_string(hlt, null.ok = TRUE) checkmate::assert_string(llt, null.ok = TRUE) - stopifnot(!is.null(hlt) || !is.null(llt)) + if (is.null(hlt) && is.null(llt)) stop("At least one of 'hlt' or 'llt' can not be empty.") checkmate::assert_string(label_hlt, null.ok = TRUE) checkmate::assert_string(label_llt, null.ok = TRUE) checkmate::assert_string(grade) From 0da828ce6cd864d47da6b1977bf1b9cb286871be Mon Sep 17 00:00:00 2001 From: m7pr Date: Wed, 7 Feb 2024 15:52:43 +0100 Subject: [PATCH 15/31] make conditions more meanigful in tm_g_pp_patient_timeline --- R/tm_g_pp_patient_timeline.R | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/R/tm_g_pp_patient_timeline.R b/R/tm_g_pp_patient_timeline.R index edb5fcba70..b6da55493f 100644 --- a/R/tm_g_pp_patient_timeline.R +++ b/R/tm_g_pp_patient_timeline.R @@ -470,10 +470,15 @@ tm_g_pp_patient_timeline <- function(label, plot_width[1], lower = plot_width[2], upper = plot_width[3], null.ok = TRUE, .var.name = "plot_width" ) - stopifnot(!xor(is.null(aetime_start), is.null(aetime_end))) - stopifnot(!xor(is.null(dstime_start), is.null(dstime_end))) - stopifnot(!xor(is.null(aerelday_start), is.null(aerelday_end))) - stopifnot(!xor(is.null(dsrelday_start), is.null(dsrelday_end))) + if (is.null(aetime_start) + is.null(aetime_end) == 1) + stop("Both 'aetime_start' and 'aetime_end' need to be provided or both need to be empty.") + if (is.null(dstime_start) + is.null(dstime_end) == 1) + stop("Both 'dstime_start' and 'dstime_end' need to be provided or both need to be empty.") + if (is.null(aerelday_start) + is.null(aerelday_end) == 1) + stop("Both 'aerelday_start' and 'aerelday_end' need to be provided or both need to be empty.") + if (is.null(dsrelday_start) + is.null(dsrelday_end) == 1) + stop("Both 'dsrelday_start' and 'dsrelday_end' need to be provided or both need to be empty.") + stopifnot( (!is.null(aeterm) && (!is.null(aetime_start) || !is.null(aerelday_start))) || (!is.null(cmdecod) && (!is.null(dstime_start) || !is.null(dsrelday_start))) From 45f6e9b0809a79b6785b75963843de482da1a842 Mon Sep 17 00:00:00 2001 From: m7pr Date: Thu, 8 Feb 2024 12:43:02 +0100 Subject: [PATCH 16/31] rewrite complicated stopifnots into something easier --- R/facet_grid_formula.R | 2 +- R/tm_g_pp_patient_timeline.R | 11 +++++++---- R/utils.R | 6 ++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/R/facet_grid_formula.R b/R/facet_grid_formula.R index 7dc7a4127c..b72133c0fe 100644 --- a/R/facet_grid_formula.R +++ b/R/facet_grid_formula.R @@ -22,6 +22,6 @@ facet_grid_formula <- function(x_facet, y_facet) { if (length(y_facet) == 0) y_facet <- "." checkmate::assert_string(x_facet) checkmate::assert_string(y_facet) - stopifnot(x_facet != y_facet) + if (x_facet == y_facet) stop("'x_facet' and 'y_facet' must not be equal.") stats::as.formula(paste0(y_facet, " ~ ", x_facet)) # must invert it } diff --git a/R/tm_g_pp_patient_timeline.R b/R/tm_g_pp_patient_timeline.R index b6da55493f..98a4bab3ec 100644 --- a/R/tm_g_pp_patient_timeline.R +++ b/R/tm_g_pp_patient_timeline.R @@ -479,10 +479,13 @@ tm_g_pp_patient_timeline <- function(label, if (is.null(dsrelday_start) + is.null(dsrelday_end) == 1) stop("Both 'dsrelday_start' and 'dsrelday_end' need to be provided or both need to be empty.") - stopifnot( - (!is.null(aeterm) && (!is.null(aetime_start) || !is.null(aerelday_start))) || - (!is.null(cmdecod) && (!is.null(dstime_start) || !is.null(dsrelday_start))) - ) + if (!(is.null(aeterm) || is.null(cmdecod))) + stop("At least one of 'aeterm' or 'cmdecod' needs to be provided.") + if (!is.null(aeterm) && (is.null(aetime_start) & is.null(aerelday_start))) + stop("If 'aeterm' is provided, then one of 'aetime_start' and 'aerelday_start' must not be empty.") + if (!is.null(cmdecod) && (is.null(dstime_start) & is.null(dsrelday_start))) + stop("If 'cmdecod' is provided, then one of 'dstime_start' and 'dsrelday_start' must not be empty.") + checkmate::assert_class(pre_output, classes = "shiny.tag", null.ok = TRUE) checkmate::assert_class(post_output, classes = "shiny.tag", null.ok = TRUE) checkmate::assert_class(ggplot2_args, "ggplot2_args") diff --git a/R/utils.R b/R/utils.R index 130602cd57..9a610cc81f 100644 --- a/R/utils.R +++ b/R/utils.R @@ -158,10 +158,8 @@ pipe_expr <- function(exprs, pipe_str = "%>%") { #' lyt <- teal.modules.clinical:::add_expr(lyt, quote(rtables::build_table(df = dta))) #' teal.modules.clinical:::pipe_expr(lyt) add_expr <- function(expr_ls, new_expr) { - stopifnot( - is.list(expr_ls) && - (is.call(new_expr) || is.name(new_expr)) - ) + checkmate::assert_list(expr_ls) + checkmate::assert_multi_class(new_expr, c('call', 'name')) # support nested expressions such as expr({a <- 1; b <- 2}) if (inherits(new_expr, "{")) { From 9b1bdef3ddc1c7111f145e11fc3c92e6bd6bfb31 Mon Sep 17 00:00:00 2001 From: Marcin <133694481+m7pr@users.noreply.github.com> Date: Thu, 8 Feb 2024 12:44:13 +0100 Subject: [PATCH 17/31] Update R/tm_g_pp_patient_timeline.R MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com> Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com> --- R/tm_g_pp_patient_timeline.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/tm_g_pp_patient_timeline.R b/R/tm_g_pp_patient_timeline.R index 98a4bab3ec..854e40bea9 100644 --- a/R/tm_g_pp_patient_timeline.R +++ b/R/tm_g_pp_patient_timeline.R @@ -46,7 +46,7 @@ template_patient_timeline <- function(dataname = "ANL", checkmate::assert_string(cmdecod, null.ok = TRUE) checkmate::assert_string(aerelday_start, null.ok = TRUE) checkmate::assert_string(dsrelday_start, null.ok = TRUE) - checkmate::assert_numeric(font_size) + checkmate::assert_number(font_size) checkmate::assert_logical(relative_day) checkmate::assert_string(patient_id) From a3d2d3e1198a5c8339c147f93ef5ce661626fed4 Mon Sep 17 00:00:00 2001 From: Marcin <133694481+m7pr@users.noreply.github.com> Date: Thu, 8 Feb 2024 12:51:23 +0100 Subject: [PATCH 18/31] Update R/tm_g_pp_patient_timeline.R MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com> Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com> --- R/tm_g_pp_patient_timeline.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/tm_g_pp_patient_timeline.R b/R/tm_g_pp_patient_timeline.R index 854e40bea9..dd50898f01 100644 --- a/R/tm_g_pp_patient_timeline.R +++ b/R/tm_g_pp_patient_timeline.R @@ -47,7 +47,7 @@ template_patient_timeline <- function(dataname = "ANL", checkmate::assert_string(aerelday_start, null.ok = TRUE) checkmate::assert_string(dsrelday_start, null.ok = TRUE) checkmate::assert_number(font_size) - checkmate::assert_logical(relative_day) + checkmate::assert_flag(relative_day) checkmate::assert_string(patient_id) chart_list <- list() From 71df57caf22910957c57100bf1bb92ab56485d23 Mon Sep 17 00:00:00 2001 From: Marcin <133694481+m7pr@users.noreply.github.com> Date: Thu, 8 Feb 2024 12:51:32 +0100 Subject: [PATCH 19/31] Update R/tm_g_pp_adverse_events.R MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com> Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com> --- R/tm_g_pp_adverse_events.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/tm_g_pp_adverse_events.R b/R/tm_g_pp_adverse_events.R index e3e191ca90..90e1a2108f 100644 --- a/R/tm_g_pp_adverse_events.R +++ b/R/tm_g_pp_adverse_events.R @@ -36,7 +36,7 @@ template_adverse_events <- function(dataname = "ANL", checkmate::assert_string(time, null.ok = TRUE) checkmate::assert_string(decod, null.ok = TRUE) checkmate::assert_string(patient_id) - checkmate::assert_numeric(font_size) + checkmate::assert_number(font_size) y <- list() From 125cde8b78771fb5ab232381136bd7323a7fe32a Mon Sep 17 00:00:00 2001 From: Marcin <133694481+m7pr@users.noreply.github.com> Date: Thu, 8 Feb 2024 12:52:16 +0100 Subject: [PATCH 20/31] Update R/tm_g_pp_therapy.R MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com> Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com> --- R/tm_g_pp_therapy.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/tm_g_pp_therapy.R b/R/tm_g_pp_therapy.R index d858c88a1b..4e8774c087 100644 --- a/R/tm_g_pp_therapy.R +++ b/R/tm_g_pp_therapy.R @@ -42,7 +42,7 @@ template_therapy <- function(dataname = "ANL", checkmate::assert_string(cmstdy) checkmate::assert_string(cmendy) checkmate::assert_string(patient_id) - checkmate::assert_numeric(font_size) + checkmate::assert_number(font_size) y <- list() y$table_list <- list() From 3e9632d83723b44f443761d3b9eb5622938b4ae8 Mon Sep 17 00:00:00 2001 From: Marcin <133694481+m7pr@users.noreply.github.com> Date: Thu, 8 Feb 2024 12:52:23 +0100 Subject: [PATCH 21/31] Update R/tm_g_pp_vitals.R MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com> Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com> --- R/tm_g_pp_vitals.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/tm_g_pp_vitals.R b/R/tm_g_pp_vitals.R index 789d32219c..4ce788c8e3 100644 --- a/R/tm_g_pp_vitals.R +++ b/R/tm_g_pp_vitals.R @@ -34,7 +34,7 @@ template_vitals <- function(dataname = "ANL", checkmate::assert_string(xaxis) checkmate::assert_string(aval_var) checkmate::assert_string(patient_id) - checkmate::assert_numeric(font_size) + checkmate::assert_number(font_size) # Note: VSDY (study day of vital signs) was replaced with ADY (analysis day) y <- list() From c0e24e06ee93f18b80debdc5556858a1808ea58e Mon Sep 17 00:00:00 2001 From: m7pr Date: Thu, 8 Feb 2024 12:58:11 +0100 Subject: [PATCH 22/31] use function and move back to XOR --- R/tm_g_pp_patient_timeline.R | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/R/tm_g_pp_patient_timeline.R b/R/tm_g_pp_patient_timeline.R index 98a4bab3ec..620872e728 100644 --- a/R/tm_g_pp_patient_timeline.R +++ b/R/tm_g_pp_patient_timeline.R @@ -470,14 +470,18 @@ tm_g_pp_patient_timeline <- function(label, plot_width[1], lower = plot_width[2], upper = plot_width[3], null.ok = TRUE, .var.name = "plot_width" ) - if (is.null(aetime_start) + is.null(aetime_end) == 1) - stop("Both 'aetime_start' and 'aetime_end' need to be provided or both need to be empty.") - if (is.null(dstime_start) + is.null(dstime_end) == 1) - stop("Both 'dstime_start' and 'dstime_end' need to be provided or both need to be empty.") - if (is.null(aerelday_start) + is.null(aerelday_end) == 1) - stop("Both 'aerelday_start' and 'aerelday_end' need to be provided or both need to be empty.") - if (is.null(dsrelday_start) + is.null(dsrelday_end) == 1) - stop("Both 'dsrelday_start' and 'dsrelday_end' need to be provided or both need to be empty.") + + xor_error_string <- function(x, y) { + paste( + "Assertion on `", x, "` and `", y, "` failed:", + "Both `", x, "` and `", y, "` needs to be provided or both need to be `NULL`." + ) + } + + if (xor(is.null(aetime_start), is.null(aetime_end))) stop(xor_error_string("aetime_start", "aetime_end")) + if (xor(is.null(dstime_start), is.null(dstime_end))) stop(xor_error_string("dstime_start", "dstime_end")) + if (xor(is.null(aerelday_start), is.null(aerelday_end))) stop(xor_error_string("aerelday_start", "aerelday_end")) + if (xor(is.null(dsrelday_start), is.null(dsrelday_end))) stop(xor_error_string("dsrelday_start", "dsrelday_end")) if (!(is.null(aeterm) || is.null(cmdecod))) stop("At least one of 'aeterm' or 'cmdecod' needs to be provided.") From c81fee934cf53959e39e708676e39013745ac239 Mon Sep 17 00:00:00 2001 From: m7pr Date: Thu, 8 Feb 2024 13:16:37 +0100 Subject: [PATCH 23/31] remove dynamic_assertions --- NAMESPACE | 2 -- R/dynamic_assertions.R | 62 ------------------------------------------ man/dyn_assertion.Rd | 41 ---------------------------- 3 files changed, 105 deletions(-) delete mode 100644 R/dynamic_assertions.R delete mode 100644 man/dyn_assertion.Rd diff --git a/NAMESPACE b/NAMESPACE index 10e6611848..16e59ee399 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -27,8 +27,6 @@ export(set_default_total_label) export(split_choices) export(split_col_expr) export(split_interactions) -export(teal_enough_rows) -export(teal_has_element) export(tm_a_gee) export(tm_a_mmrm) export(tm_g_barchart_simple) diff --git a/R/dynamic_assertions.R b/R/dynamic_assertions.R deleted file mode 100644 index fc922e96bc..0000000000 --- a/R/dynamic_assertions.R +++ /dev/null @@ -1,62 +0,0 @@ -#' Dynamic assertion -#' -#' Verifies assertions for dynamic outputs. -#' -#' @name dyn_assertion -#' @keywords internal -NULL - -#' @describeIn dyn_assertion the dataset is large enough. -#' -#' @param data (`dataframe`). -#' @param min_nrow (`number`)\cr minimum number of rows for a valid analysis. -#' -#' @export -#' -#' @examples -#' -#' library(assertthat) -#' library(testthat) -#' expect_error(assertthat::assert_that(teal_enough_rows(data = iris, min_nrow = 1500))) -teal_enough_rows <- function(data, min_nrow) nrow(data) >= min_nrow -assertthat::on_failure(teal_enough_rows) <- function(call, env) { - call[[1]] <- validate_enough_rows - eval(call, envir = env) -} -validate_enough_rows <- function(data, min_nrow) { - shiny::validate( - shiny::need( - FALSE, - label = paste0( - substitute(data), - ": Minimum number of records not met: >= ", min_nrow, - " records required." - ) - ) - ) -} - -#' @describeIn dyn_assertion the element exist. -#' @param str (`name`)\cr the name of the object which must _exist_. -#' @param ... (`character`)\cr the label to be displayed. -#' -#' @export -#' -#' @examples -#' -#' armcd <- NULL -#' expect_error(assertthat::assert_that(teal_has_element(str = armcd, "ARMCD"))) -teal_has_element <- function(str, ...) length(str) > 0 -assertthat::on_failure(teal_has_element) <- function(call, env) { - call[[1]] <- validate_has_elements - eval(call, envir = env) -} - -validate_has_elements <- function(str, label = str) { - shiny::validate( - shiny::need( - FALSE, - message = paste0(label, ": required variable not assigned.") - ) - ) -} diff --git a/man/dyn_assertion.Rd b/man/dyn_assertion.Rd deleted file mode 100644 index 9b9881a0b6..0000000000 --- a/man/dyn_assertion.Rd +++ /dev/null @@ -1,41 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dynamic_assertions.R -\name{dyn_assertion} -\alias{dyn_assertion} -\alias{teal_enough_rows} -\alias{teal_has_element} -\title{Dynamic assertion} -\usage{ -teal_enough_rows(data, min_nrow) - -teal_has_element(str, ...) -} -\arguments{ -\item{data}{(\code{dataframe}).} - -\item{min_nrow}{(\code{number})\cr minimum number of rows for a valid analysis.} - -\item{str}{(\code{name})\cr the name of the object which must \emph{exist}.} - -\item{...}{(\code{character})\cr the label to be displayed.} -} -\description{ -Verifies assertions for dynamic outputs. -} -\section{Functions}{ -\itemize{ -\item \code{teal_enough_rows()}: the dataset is large enough. - -\item \code{teal_has_element()}: the element exist. - -}} -\examples{ - -library(assertthat) -library(testthat) -expect_error(assertthat::assert_that(teal_enough_rows(data = iris, min_nrow = 1500))) - -armcd <- NULL -expect_error(assertthat::assert_that(teal_has_element(str = armcd, "ARMCD"))) -} -\keyword{internal} From a00a4cff7552b2c9c32fca995cb4297ae35503f0 Mon Sep 17 00:00:00 2001 From: m7pr Date: Thu, 8 Feb 2024 13:57:16 +0100 Subject: [PATCH 24/31] fix conditions --- R/tm_g_pp_patient_timeline.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/tm_g_pp_patient_timeline.R b/R/tm_g_pp_patient_timeline.R index 1a666a8eda..46c2288223 100644 --- a/R/tm_g_pp_patient_timeline.R +++ b/R/tm_g_pp_patient_timeline.R @@ -485,9 +485,9 @@ tm_g_pp_patient_timeline <- function(label, if (!(is.null(aeterm) || is.null(cmdecod))) stop("At least one of 'aeterm' or 'cmdecod' needs to be provided.") - if (!is.null(aeterm) && (is.null(aetime_start) & is.null(aerelday_start))) + if (!is.null(aeterm) && (is.null(aetime_start) || is.null(aerelday_start))) stop("If 'aeterm' is provided, then one of 'aetime_start' and 'aerelday_start' must not be empty.") - if (!is.null(cmdecod) && (is.null(dstime_start) & is.null(dsrelday_start))) + if (!is.null(cmdecod) && (is.null(dstime_start) || is.null(dsrelday_start))) stop("If 'cmdecod' is provided, then one of 'dstime_start' and 'dsrelday_start' must not be empty.") checkmate::assert_class(pre_output, classes = "shiny.tag", null.ok = TRUE) From ddedc8297ac7371809027cb9447a359744d470f5 Mon Sep 17 00:00:00 2001 From: m7pr Date: Thu, 8 Feb 2024 14:07:22 +0100 Subject: [PATCH 25/31] bring back original assert on add_expr --- R/utils.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utils.R b/R/utils.R index 9a610cc81f..6aa0513947 100644 --- a/R/utils.R +++ b/R/utils.R @@ -159,7 +159,7 @@ pipe_expr <- function(exprs, pipe_str = "%>%") { #' teal.modules.clinical:::pipe_expr(lyt) add_expr <- function(expr_ls, new_expr) { checkmate::assert_list(expr_ls) - checkmate::assert_multi_class(new_expr, c('call', 'name')) + checkmate::assert(is.call(new_expr) || is.name(new_expr)) # support nested expressions such as expr({a <- 1; b <- 2}) if (inherits(new_expr, "{")) { From 9d9c4f23531ebd92b6e10854276d439c3780261a Mon Sep 17 00:00:00 2001 From: m7pr Date: Thu, 8 Feb 2024 16:13:52 +0100 Subject: [PATCH 26/31] styler styling files --- R/tm_g_pp_patient_timeline.R | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/R/tm_g_pp_patient_timeline.R b/R/tm_g_pp_patient_timeline.R index 46c2288223..422cd640ce 100644 --- a/R/tm_g_pp_patient_timeline.R +++ b/R/tm_g_pp_patient_timeline.R @@ -483,12 +483,15 @@ tm_g_pp_patient_timeline <- function(label, if (xor(is.null(aerelday_start), is.null(aerelday_end))) stop(xor_error_string("aerelday_start", "aerelday_end")) if (xor(is.null(dsrelday_start), is.null(dsrelday_end))) stop(xor_error_string("dsrelday_start", "dsrelday_end")) - if (!(is.null(aeterm) || is.null(cmdecod))) + if (!(is.null(aeterm) || is.null(cmdecod))) { stop("At least one of 'aeterm' or 'cmdecod' needs to be provided.") - if (!is.null(aeterm) && (is.null(aetime_start) || is.null(aerelday_start))) + } + if (!is.null(aeterm) && (is.null(aetime_start) || is.null(aerelday_start))) { stop("If 'aeterm' is provided, then one of 'aetime_start' and 'aerelday_start' must not be empty.") - if (!is.null(cmdecod) && (is.null(dstime_start) || is.null(dsrelday_start))) + } + if (!is.null(cmdecod) && (is.null(dstime_start) || is.null(dsrelday_start))) { stop("If 'cmdecod' is provided, then one of 'dstime_start' and 'dsrelday_start' must not be empty.") + } checkmate::assert_class(pre_output, classes = "shiny.tag", null.ok = TRUE) checkmate::assert_class(post_output, classes = "shiny.tag", null.ok = TRUE) From 44ddd2c20e964c15bd110bb83de3fec2b4129cf1 Mon Sep 17 00:00:00 2001 From: m7pr Date: Thu, 8 Feb 2024 16:21:27 +0100 Subject: [PATCH 27/31] wrong condition in tm_g_pp_patient_timeline testing --- R/tm_g_pp_patient_timeline.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/tm_g_pp_patient_timeline.R b/R/tm_g_pp_patient_timeline.R index 422cd640ce..d002958e1d 100644 --- a/R/tm_g_pp_patient_timeline.R +++ b/R/tm_g_pp_patient_timeline.R @@ -483,7 +483,7 @@ tm_g_pp_patient_timeline <- function(label, if (xor(is.null(aerelday_start), is.null(aerelday_end))) stop(xor_error_string("aerelday_start", "aerelday_end")) if (xor(is.null(dsrelday_start), is.null(dsrelday_end))) stop(xor_error_string("dsrelday_start", "dsrelday_end")) - if (!(is.null(aeterm) || is.null(cmdecod))) { + if (!is.null(aeterm) || !is.null(cmdecod)) { stop("At least one of 'aeterm' or 'cmdecod' needs to be provided.") } if (!is.null(aeterm) && (is.null(aetime_start) || is.null(aerelday_start))) { From a7cdc6d351a78b4ac11841e726c78b72672f49cf Mon Sep 17 00:00:00 2001 From: m7pr Date: Thu, 8 Feb 2024 16:30:39 +0100 Subject: [PATCH 28/31] ugh --- R/tm_g_pp_patient_timeline.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/tm_g_pp_patient_timeline.R b/R/tm_g_pp_patient_timeline.R index d002958e1d..369b6ea321 100644 --- a/R/tm_g_pp_patient_timeline.R +++ b/R/tm_g_pp_patient_timeline.R @@ -483,7 +483,7 @@ tm_g_pp_patient_timeline <- function(label, if (xor(is.null(aerelday_start), is.null(aerelday_end))) stop(xor_error_string("aerelday_start", "aerelday_end")) if (xor(is.null(dsrelday_start), is.null(dsrelday_end))) stop(xor_error_string("dsrelday_start", "dsrelday_end")) - if (!is.null(aeterm) || !is.null(cmdecod)) { + if (is.null(aeterm) && is.null(cmdecod)) { stop("At least one of 'aeterm' or 'cmdecod' needs to be provided.") } if (!is.null(aeterm) && (is.null(aetime_start) || is.null(aerelday_start))) { From 97b5801c8a88426233d0d00228b389110677b258 Mon Sep 17 00:00:00 2001 From: Marcin <133694481+m7pr@users.noreply.github.com> Date: Fri, 9 Feb 2024 11:31:12 +0100 Subject: [PATCH 29/31] Update R/tm_t_ancova.R MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com> Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com> --- R/tm_t_ancova.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/tm_t_ancova.R b/R/tm_t_ancova.R index c0017c7fd2..b5338c6c7a 100644 --- a/R/tm_t_ancova.R +++ b/R/tm_t_ancova.R @@ -50,7 +50,7 @@ template_ancova <- function(dataname = "ANL", checkmate::assert_string(aval_var) checkmate::assert_character(cov_var) checkmate::assert_flag(include_interact) - if (isTRUE(interact_y)) all(sapply(interact_y, checkmate::assert_string)) + if (!isFALSE(interact_y)) checkmate::assert_character(interact_y) checkmate::assert_string(interact_var, null.ok = TRUE) y <- list() From 57c7b3e3effff20dbfd3b8d486c96250e60e3967 Mon Sep 17 00:00:00 2001 From: Marcin <133694481+m7pr@users.noreply.github.com> Date: Fri, 9 Feb 2024 12:38:08 +0100 Subject: [PATCH 30/31] Update R/tm_t_events_by_grade.R MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com> Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com> --- R/tm_t_events_by_grade.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/tm_t_events_by_grade.R b/R/tm_t_events_by_grade.R index 3b5d908e3f..1924c4d280 100644 --- a/R/tm_t_events_by_grade.R +++ b/R/tm_t_events_by_grade.R @@ -1091,7 +1091,10 @@ srv_t_events_by_grade <- function(id, anl_filtered <- merged$anl_q()[[dataname]] adsl_keys <- merged$adsl_input_r()$keys - stopifnot("USUBJID" %in% adsl_keys) + checkmate::assert( + .var.name = "adsl_keys", + if ("USUBJID" %in% adsl_keys) TRUE else "Must contain \"USUBJID\"" + ) input_arm_var <- as.vector(merged$anl_input_r()$columns_source$arm_var) input_level_term <- c( From 970096ebd312d68f7150dd7e00d1aa0d4cf37767 Mon Sep 17 00:00:00 2001 From: m7pr Date: Fri, 9 Feb 2024 12:40:50 +0100 Subject: [PATCH 31/31] remove DYNAMIC assertions --- R/dynamic_assertions.R | 62 ------------------------------------------ man/dyn_assertion.Rd | 41 ---------------------------- 2 files changed, 103 deletions(-) delete mode 100644 R/dynamic_assertions.R delete mode 100644 man/dyn_assertion.Rd diff --git a/R/dynamic_assertions.R b/R/dynamic_assertions.R deleted file mode 100644 index 9552e994e4..0000000000 --- a/R/dynamic_assertions.R +++ /dev/null @@ -1,62 +0,0 @@ -#' Dynamic assertion -#' -#' Verifies assertions for dynamic outputs. -#' -#' @name dyn_assertion -#' @keywords internal -NULL - -#' @describeIn dyn_assertion the dataset is large enough. -#' -#' @param data (`dataframe`). -#' @param min_nrow (`number`)\cr minimum number of rows for a valid analysis. -#' -#' @export -#' -#' @examples -#' -#' library(assertthat) -#' library(testthat) -#' expect_error(assert_that(teal_enough_rows(data = iris, min_nrow = 1500))) -teal_enough_rows <- function(data, min_nrow) nrow(data) >= min_nrow -assertthat::on_failure(teal_enough_rows) <- function(call, env) { - call[[1]] <- validate_enough_rows - eval(call, envir = env) -} -validate_enough_rows <- function(data, min_nrow) { - shiny::validate( - shiny::need( - FALSE, - label = paste0( - substitute(data), - ": Minimum number of records not met: >= ", min_nrow, - " records required." - ) - ) - ) -} - -#' @describeIn dyn_assertion the element exist. -#' @param str (`name`)\cr the name of the object which must _exist_. -#' @param ... (`character`)\cr the label to be displayed. -#' -#' @export -#' -#' @examples -#' library(assertthat) -#' armcd <- NULL -#' expect_error(assert_that(teal_has_element(str = armcd, "ARMCD"))) -teal_has_element <- function(str, ...) length(str) > 0 -assertthat::on_failure(teal_has_element) <- function(call, env) { - call[[1]] <- validate_has_elements - eval(call, envir = env) -} - -validate_has_elements <- function(str, label = str) { - shiny::validate( - shiny::need( - FALSE, - message = paste0(label, ": required variable not assigned.") - ) - ) -} diff --git a/man/dyn_assertion.Rd b/man/dyn_assertion.Rd deleted file mode 100644 index 2b81889c25..0000000000 --- a/man/dyn_assertion.Rd +++ /dev/null @@ -1,41 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dynamic_assertions.R -\name{dyn_assertion} -\alias{dyn_assertion} -\alias{teal_enough_rows} -\alias{teal_has_element} -\title{Dynamic assertion} -\usage{ -teal_enough_rows(data, min_nrow) - -teal_has_element(str, ...) -} -\arguments{ -\item{data}{(\code{dataframe}).} - -\item{min_nrow}{(\code{number})\cr minimum number of rows for a valid analysis.} - -\item{str}{(\code{name})\cr the name of the object which must \emph{exist}.} - -\item{...}{(\code{character})\cr the label to be displayed.} -} -\description{ -Verifies assertions for dynamic outputs. -} -\section{Functions}{ -\itemize{ -\item \code{teal_enough_rows()}: the dataset is large enough. - -\item \code{teal_has_element()}: the element exist. - -}} -\examples{ - -library(assertthat) -library(testthat) -expect_error(assert_that(teal_enough_rows(data = iris, min_nrow = 1500))) -library(assertthat) -armcd <- NULL -expect_error(assert_that(teal_has_element(str = armcd, "ARMCD"))) -} -\keyword{internal}