Skip to content

Commit

Permalink
revert: back to old way of checking for c(value, min, max)
Browse files Browse the repository at this point in the history
  • Loading branch information
averissimo committed Feb 26, 2024
1 parent 37dd947 commit d692cbc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 125 deletions.
57 changes: 33 additions & 24 deletions R/tm_a_regression.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,28 +165,31 @@ tm_a_regression <- function(label = "Regression Analysis",
stop("'response' should not allow multiple selection")
}

checkmate::assert(
.var.name = "plot_height",
check_range_slider(plot_height, lower = 1)
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)
checkmate::assert_numeric(
plot_width[1],
lower = plot_width[2],
upper = plot_width[3],
null.ok = TRUE,
.var.name = "plot_width"
)

checkmate::assert(
.var.name = "plot_width",
check_range_slider(plot_width, lower = 1),
checkmate::check_null(plot_width)
)

checkmate::assert(
.var.name = "alpha",
check_range_slider(alpha, lower = 0, upper = 1),
checkmate::check_number(alpha, lower = 0, upper = 1)
)
if (length(alpha) == 1) {
checkmate::assert_numeric(alpha, any.missing = FALSE, finite = TRUE)
} else {
checkmate::assert_numeric(alpha, len = 3, any.missing = FALSE, finite = TRUE)
checkmate::assert_numeric(alpha[1], lower = alpha[2], upper = alpha[3], .var.name = "alpha")
}

checkmate::assert(
.var.name = "size",
check_range_slider(size, lower = 0),
checkmate::check_number(size, lower = 0)
)
if (length(size) == 1) {
checkmate::assert_numeric(size, any.missing = FALSE, finite = TRUE)
} else {
checkmate::assert_numeric(size, len = 3, any.missing = FALSE, finite = TRUE)
checkmate::assert_numeric(size[1], lower = size[2], upper = size[3], .var.name = "size")
}

ggtheme <- match.arg(ggtheme)

Expand All @@ -202,11 +205,17 @@ tm_a_regression <- function(label = "Regression Analysis",
checkmate::assert_integerish(default_plot_type, lower = 1, upper = 7)
checkmate::assert_string(default_outlier_label)

checkmate::assert(
.var.name = "label_segment_threshold",
check_range_slider(label_segment_threshold, lower = 0),
checkmate::check_number(label_segment_threshold, lower = 0)
)
if (length(label_segment_threshold) == 1) {
checkmate::assert_numeric(label_segment_threshold, any.missing = FALSE, finite = TRUE)
} else {
checkmate::assert_numeric(label_segment_threshold, len = 3, any.missing = FALSE, finite = TRUE)
checkmate::assert_numeric(
label_segment_threshold[1],
lower = label_segment_threshold[2],
upper = label_segment_threshold[3],
.var.name = "label_segment_threshold"
)
}
# End of assertions

# Send ui args
Expand Down
44 changes: 0 additions & 44 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -348,47 +348,3 @@ is_tab_active_js <- function(id, name) {
id, name
)
}

#' Check if an argument is a bounded numeric vector of length 3
#'
#' Must follow form `c(value, min, max)` and `test_fun` must be a function that
#' supports checks on vectorized input
#' @noRd
#'
check_range_slider <- function(value,
lower = -Inf,
upper = Inf,
finite = TRUE,
test_fun = checkmate::test_numeric) {
checkmate::assert_flag(finite)
checkmate::assert_function(test_fun)
checkmate::assert_number(lower)
checkmate::assert_number(upper)

is_numeric <- test_fun(
value,
len = 3,
any.missing = FALSE
)

# Finite is not available in integer tests
if (finite && "finite" %in% names(formals(test_fun))) {
test_fun(value, finite = finite)
}

is_bounded <- is_numeric && test_fun(
value[[1]],
len = 1,
lower = max(lower, value[[2]]),
upper = min(upper, value[[3]])
)
if (isFALSE(is_numeric) || isFALSE(is_bounded)) {
return(
paste(
"Must be a numeric vector of length 3 with `c(value, min, max)`",
"where the `value` must be between `min` and `max`"
)
)
}
TRUE
}
57 changes: 0 additions & 57 deletions tests/testthat/test-utils.R

This file was deleted.

0 comments on commit d692cbc

Please sign in to comment.