diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 35c7cbd95..710d0e6c6 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 945e6c0d3..a79e83f30 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 10e661184..ed4503098 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) @@ -65,7 +63,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 deleted file mode 100644 index 9552e994e..000000000 --- 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/R/facet_grid_formula.R b/R/facet_grid_formula.R index 2936aa656..a5cf4d174 100644 --- a/R/facet_grid_formula.R +++ b/R/facet_grid_formula.R @@ -23,6 +23,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_forest_rsp.R b/R/tm_g_forest_rsp.R index 8263f195a..0df97cf59 100644 --- a/R/tm_g_forest_rsp.R +++ b/R/tm_g_forest_rsp.R @@ -34,14 +34,12 @@ 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 = "/") @@ -314,10 +312,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_forest_tte.R b/R/tm_g_forest_tte.R index 8b8805ca2..475e03632 100644 --- a/R/tm_g_forest_tte.R +++ b/R/tm_g_forest_tte.R @@ -24,12 +24,10 @@ 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_var, null.ok = TRUE) y <- list() ref_arm_val <- paste(ref_arm, collapse = "/") diff --git a/R/tm_g_ipp.R b/R/tm_g_ipp.R index 8e00ecba9..cc5b8f637 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_g_km.R b/R/tm_g_km.R index c2f7adab0..02adc71d3 100644 --- a/R/tm_g_km.R +++ b/R/tm_g_km.R @@ -37,17 +37,15 @@ 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_lineplot.R b/R/tm_g_lineplot.R index 12fd1f5a7..7b814638d 100644 --- a/R/tm_g_lineplot.R +++ b/R/tm_g_lineplot.R @@ -39,16 +39,15 @@ 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_adverse_events.R b/R/tm_g_pp_adverse_events.R index 8a9f86684..a709d15d1 100644 --- a/R/tm_g_pp_adverse_events.R +++ b/R/tm_g_pp_adverse_events.R @@ -27,18 +27,16 @@ 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_number(font_size) y <- list() diff --git a/R/tm_g_pp_patient_timeline.R b/R/tm_g_pp_patient_timeline.R index e7e4ba83e..741e74654 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_number(font_size) + checkmate::assert_flag(relative_day) + checkmate::assert_string(patient_id) chart_list <- list() if (!relative_day) { @@ -473,14 +472,29 @@ 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( - (!is.null(aeterm) && (!is.null(aetime_start) || !is.null(aerelday_start))) || - (!is.null(cmdecod) && (!is.null(dstime_start) || !is.null(dsrelday_start))) - ) + + 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.") + } + 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/tm_g_pp_therapy.R b/R/tm_g_pp_therapy.R index 224fa5a92..6bbff227e 100644 --- a/R/tm_g_pp_therapy.R +++ b/R/tm_g_pp_therapy.R @@ -30,21 +30,19 @@ 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) + checkmate::assert_number(font_size) y <- list() y$table_list <- list() diff --git a/R/tm_g_pp_vitals.R b/R/tm_g_pp_vitals.R index 16311f304..4ce788c8e 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_number(font_size) # Note: VSDY (study day of vital signs) was replaced with ADY (analysis day) y <- list() diff --git a/R/tm_t_abnormality.R b/R/tm_t_abnormality.R index d551821d6..c48c9961f 100644 --- a/R/tm_t_abnormality.R +++ b/R/tm_t_abnormality.R @@ -34,23 +34,21 @@ 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 73992de9f..065237b9c 100644 --- a/R/tm_t_abnormality_by_worst_grade.R +++ b/R/tm_t_abnormality_by_worst_grade.R @@ -28,20 +28,18 @@ 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_ancova.R b/R/tm_t_ancova.R index d7d31550a..b5338c6c7 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) + if (!isFALSE(interact_y)) checkmate::assert_character(interact_y) + checkmate::assert_string(interact_var, null.ok = TRUE) y <- list() diff --git a/R/tm_t_binary_outcome.R b/R/tm_t_binary_outcome.R index 7b3fa75d2..e0a9907d9 100644 --- a/R/tm_t_binary_outcome.R +++ b/R/tm_t_binary_outcome.R @@ -36,18 +36,16 @@ 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_events.R b/R/tm_t_events.R index 6653d18a4..a7f3a6ebd 100644 --- a/R/tm_t_events.R +++ b/R/tm_t_events.R @@ -30,21 +30,19 @@ 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_events_by_grade.R b/R/tm_t_events_by_grade.R index 1b2553b36..760d1c5bf 100644 --- a/R/tm_t_events_by_grade.R +++ b/R/tm_t_events_by_grade.R @@ -30,22 +30,20 @@ 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) + 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) + 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) @@ -409,27 +407,24 @@ 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( - assertthat::is.string(dataname), - assertthat::is.string(parentname), - assertthat::is.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_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. @@ -1099,7 +1094,10 @@ 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) + 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( diff --git a/R/tm_t_events_summary.R b/R/tm_t_events_summary.R index 4384c7f0c..f5998a173 100644 --- a/R/tm_t_events_summary.R +++ b/R/tm_t_events_summary.R @@ -42,23 +42,21 @@ 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_exposure.R b/R/tm_t_exposure.R index 0fae335f7..42fee6bbe 100644 --- a/R/tm_t_exposure.R +++ b/R/tm_t_exposure.R @@ -34,22 +34,20 @@ 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 1561c0a85..385b40e63 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() @@ -53,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( - assertthat::is.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/R/tm_t_mult_events.R b/R/tm_t_mult_events.R index 71a2613ce..e4a8f6063 100644 --- a/R/tm_t_mult_events.R +++ b/R/tm_t_mult_events.R @@ -23,20 +23,17 @@ 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_laboratory.R b/R/tm_t_pp_laboratory.R index 55be70997..694c516d4 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_pp_medical_history.R b/R/tm_t_pp_medical_history.R index 9ec5309fb..7213c2c0e 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_pp_prior_medication.R b/R/tm_t_pp_prior_medication.R index 048933d08..3497a021a 100644 --- a/R/tm_t_pp_prior_medication.R +++ b/R/tm_t_pp_prior_medication.R @@ -14,13 +14,11 @@ 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_shift_by_arm.R b/R/tm_t_shift_by_arm.R index 674039ab3..df985069c 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 d9175cf07..b46d71b70 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() diff --git a/R/tm_t_shift_by_grade.R b/R/tm_t_shift_by_grade.R index ffceeec19..26e892cce 100644 --- a/R/tm_t_shift_by_grade.R +++ b/R/tm_t_shift_by_grade.R @@ -28,22 +28,20 @@ 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 98bdf7f13..9b2d65ec2 100644 --- a/R/tm_t_smq.R +++ b/R/tm_t_smq.R @@ -24,19 +24,17 @@ 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/tm_t_summary.R b/R/tm_t_summary.R index 4998fb081..881416c02 100644 --- a/R/tm_t_summary.R +++ b/R/tm_t_summary.R @@ -27,23 +27,22 @@ 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_summary_by.R b/R/tm_t_summary_by.R index 84e0fceda..15830d3cf 100644 --- a/R/tm_t_summary_by.R +++ b/R/tm_t_summary_by.R @@ -33,24 +33,23 @@ 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() diff --git a/R/tm_t_tte.R b/R/tm_t_tte.R index 86275e2e4..02789dfcc 100644 --- a/R/tm_t_tte.R +++ b/R/tm_t_tte.R @@ -65,19 +65,17 @@ 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() diff --git a/R/utils.R b/R/utils.R index 8ae7a1d21..5fb609646 100644 --- a/R/utils.R +++ b/R/utils.R @@ -139,7 +139,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 @@ -161,10 +160,8 @@ pipe_expr <- function(exprs, pipe_str = "%>%") { #' lyt <- add_expr(lyt, quote(build_table(df = dta))) #' 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) - ) + checkmate::assert_list(expr_ls) + checkmate::assert(is.call(new_expr) || is.name(new_expr)) # support nested expressions such as expr({a <- 1; b <- 2}) if (inherits(new_expr, "{")) { @@ -528,15 +525,13 @@ 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() @@ -627,12 +622,10 @@ 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() diff --git a/man/dyn_assertion.Rd b/man/dyn_assertion.Rd deleted file mode 100644 index 2b81889c2..000000000 --- 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}