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 31 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
3 changes: 0 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
62 changes: 0 additions & 62 deletions R/dynamic_assertions.R

This file was deleted.

2 changes: 1 addition & 1 deletion R/facet_grid_formula.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
19 changes: 7 additions & 12 deletions R/tm_g_forest_rsp.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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 +310,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
10 changes: 4 additions & 6 deletions R/tm_g_forest_tte.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "/")
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
20 changes: 9 additions & 11 deletions R/tm_g_km.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
19 changes: 9 additions & 10 deletions R/tm_g_lineplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
22 changes: 10 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,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()

Expand Down
58 changes: 36 additions & 22 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_number(font_size)
checkmate::assert_flag(relative_day)
checkmate::assert_string(patient_id)

chart_list <- list()
if (!relative_day) {
Expand Down Expand Up @@ -471,14 +470,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")
Expand Down
28 changes: 13 additions & 15 deletions R/tm_g_pp_therapy.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading
Loading