Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1012 substitute {assertthat} with {checkmate} in a couple of functions #1046

Merged
merged 35 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
79ebc56
substitute assertthat with checkmate in a couple of functions
m7pr Feb 7, 2024
a28a7f8
substitute assertthat with checkmate in few more files
m7pr Feb 7, 2024
4d05e36
substitute assertthat with checkmate in few more files
m7pr Feb 7, 2024
2ca71ce
substitute asserthtat with checkmate in few more files
m7pr Feb 7, 2024
53b320a
remove asserthat from few more files
m7pr Feb 7, 2024
3eaef34
remove assertthat complitely
m7pr Feb 7, 2024
24dabd3
change is.numeric to checkmate::assert_numeric in tm_g_pp_therapy
m7pr Feb 7, 2024
37ffe55
[skip actions] Roxygen Man Pages Auto Update
dependabot-preview[bot] Feb 7, 2024
0ecc853
Empty-Commit
m7pr Feb 7, 2024
f95e5a8
typo
m7pr Feb 7, 2024
d08e2c5
change order of testing for interact_y in tm_t_ancova
m7pr Feb 7, 2024
40401e6
remove curly brackets
m7pr Feb 7, 2024
8112e09
styling files
m7pr Feb 7, 2024
a53fcb5
more informative message in t_events_by_grade
m7pr Feb 7, 2024
0da828c
make conditions more meanigful in tm_g_pp_patient_timeline
m7pr Feb 7, 2024
45f6e9b
rewrite complicated stopifnots into something easier
m7pr Feb 8, 2024
9b1bdef
Update R/tm_g_pp_patient_timeline.R
m7pr Feb 8, 2024
a3d2d3e
Update R/tm_g_pp_patient_timeline.R
m7pr Feb 8, 2024
71df57c
Update R/tm_g_pp_adverse_events.R
m7pr Feb 8, 2024
125cde8
Update R/tm_g_pp_therapy.R
m7pr Feb 8, 2024
3e9632d
Update R/tm_g_pp_vitals.R
m7pr Feb 8, 2024
c0e24e0
use function and move back to XOR
m7pr Feb 8, 2024
90094d7
Merge branch '1012_assert_1@main' of https://github.com/insightsengin…
m7pr Feb 8, 2024
c81fee9
remove dynamic_assertions
m7pr Feb 8, 2024
b44a726
merge
m7pr Feb 8, 2024
a00a4cf
fix conditions
m7pr Feb 8, 2024
ddedc82
bring back original assert on add_expr
m7pr Feb 8, 2024
9d9c4f2
styler styling files
m7pr Feb 8, 2024
44ddd2c
wrong condition in tm_g_pp_patient_timeline testing
m7pr Feb 8, 2024
a7cdc6d
ugh
m7pr Feb 8, 2024
97b5801
Update R/tm_t_ancova.R
m7pr Feb 9, 2024
57c7b3e
Update R/tm_t_events_by_grade.R
m7pr Feb 9, 2024
a62b153
git merge
m7pr Feb 9, 2024
55bf195
Merge branch 'main' into 1012_assert_1@main
m7pr Feb 9, 2024
970096e
remove DYNAMIC assertions
m7pr Feb 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ repos:
- insightsengineering/teal
- insightsengineering/teal.transform
- tern
- assertthat
- broom
- checkmate
- dplyr
Expand Down
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions R/dynamic_assertions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 8 additions & 12 deletions R/tm_g_forest_rsp.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
m7pr marked this conversation as resolved.
Show resolved Hide resolved

y <- list()
ref_arm_val <- paste(ref_arm, collapse = "/")
Expand Down Expand Up @@ -312,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)
Expand Down
11 changes: 5 additions & 6 deletions R/tm_g_forest_tte.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "/")
Expand Down
26 changes: 12 additions & 14 deletions R/tm_g_ipp.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 10 additions & 11 deletions R/tm_g_km.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 10 additions & 10 deletions R/tm_g_lineplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
23 changes: 11 additions & 12 deletions R/tm_g_pp_adverse_events.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
m7pr marked this conversation as resolved.
Show resolved Hide resolved

y <- list()

Expand Down
37 changes: 18 additions & 19 deletions R/tm_g_pp_patient_timeline.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
m7pr marked this conversation as resolved.
Show resolved Hide resolved
checkmate::assert_logical(relative_day)
m7pr marked this conversation as resolved.
Show resolved Hide resolved
checkmate::assert_string(patient_id)

chart_list <- list()
if (!relative_day) {
Expand Down Expand Up @@ -471,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(
m7pr marked this conversation as resolved.
Show resolved Hide resolved
(!is.null(aeterm) && (!is.null(aetime_start) || !is.null(aerelday_start))) ||
(!is.null(cmdecod) && (!is.null(dstime_start) || !is.null(dsrelday_start)))
)
Expand Down
29 changes: 14 additions & 15 deletions R/tm_g_pp_therapy.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
m7pr marked this conversation as resolved.
Show resolved Hide resolved

y <- list()
y$table_list <- list()
Expand Down
14 changes: 6 additions & 8 deletions R/tm_g_pp_vitals.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
m7pr marked this conversation as resolved.
Show resolved Hide resolved

# Note: VSDY (study day of vital signs) was replaced with ADY (analysis day)
y <- list()
Expand Down
33 changes: 16 additions & 17 deletions R/tm_t_abnormality.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Loading
Loading