diff --git a/R/checks.R b/R/checks.R index 2a19ca0..f857ed6 100644 --- a/R/checks.R +++ b/R/checks.R @@ -1,18 +1,5 @@ # Additional type checkers designed for testing argument values. -check_single_logical <- function(x, call = rlang::caller_env()) { - cl <- match.call() - arg_nm <- as.character(cl$x) - msg <- "{.arg {arg_nm}} should be a single logical value, not {obj_type_friendly(x)}." - if (!is.logical(x)) { - cli::cli_abort(msg, call = call) - } - if (length(x) > 1 || any(is.na(x))) { - cli::cli_abort(msg, call = call) - } - invisible(x) -} - check_number_whole_vec <- function(x, call = rlang::caller_env(), arg = rlang::caller_arg(x), ...) { for (i in x) { diff --git a/tests/testthat/_snaps/checkers.md b/tests/testthat/_snaps/checks.md similarity index 56% rename from tests/testthat/_snaps/checkers.md rename to tests/testthat/_snaps/checks.md index 1f22a86..843762e 100644 --- a/tests/testthat/_snaps/checkers.md +++ b/tests/testthat/_snaps/checks.md @@ -1,27 +1,3 @@ -# checking single logicals - - Code - brulee:::check_single_logical(variable) - Condition - Error: - ! `variable` should be a single logical value, not the string "pie". - ---- - - Code - brulee:::check_single_logical(variable) - Condition - Error: - ! `variable` should be a single logical value, not `NA`. - ---- - - Code - brulee:::check_single_logical(variable) - Condition - Error: - ! `variable` should be a single logical value, not a logical vector. - # checking double vectors Code diff --git a/tests/testthat/_snaps/tunable.md b/tests/testthat/_snaps/tunable.md deleted file mode 100644 index 431476f..0000000 --- a/tests/testthat/_snaps/tunable.md +++ /dev/null @@ -1,429 +0,0 @@ -# tunable values - - Code - brulee:::tunable.brulee_linear_reg(1)$call_info - Output - [[1]] - [[1]]$pkg - [1] "dials" - - [[1]]$fun - [1] "epochs" - - [[1]]$range - [1] 5 100 - - - [[2]] - [[2]]$pkg - [1] "dials" - - [[2]]$fun - [1] "penalty" - - - [[3]] - [[3]]$pkg - [1] "dials" - - [[3]]$fun - [1] "learn_rate" - - [[3]]$range - [1] -3.0 -0.2 - - - [[4]] - [[4]]$pkg - [1] "dials" - - [[4]]$fun - [1] "momentum" - - [[4]]$range - [1] 0.50 0.95 - - - [[5]] - [[5]]$pkg - [1] "dials" - - [[5]]$fun - [1] "batch_size" - - - [[6]] - [[6]]$pkg - [1] "dials" - - [[6]]$fun - [1] "stop_iter" - - - ---- - - Code - brulee:::tunable.brulee_logistic_reg(1)$call_info - Output - [[1]] - [[1]]$pkg - [1] "dials" - - [[1]]$fun - [1] "epochs" - - [[1]]$range - [1] 5 100 - - - [[2]] - [[2]]$pkg - [1] "dials" - - [[2]]$fun - [1] "penalty" - - - [[3]] - [[3]]$pkg - [1] "dials" - - [[3]]$fun - [1] "learn_rate" - - [[3]]$range - [1] -3.0 -0.2 - - - [[4]] - [[4]]$pkg - [1] "dials" - - [[4]]$fun - [1] "momentum" - - [[4]]$range - [1] 0.50 0.95 - - - [[5]] - [[5]]$pkg - [1] "dials" - - [[5]]$fun - [1] "batch_size" - - - [[6]] - [[6]]$pkg - [1] "dials" - - [[6]]$fun - [1] "stop_iter" - - - [[7]] - [[7]]$pkg - [1] "dials" - - [[7]]$fun - [1] "class_weights" - - - ---- - - Code - brulee:::tunable.brulee_multinomial_reg(1)$call_info - Output - [[1]] - [[1]]$pkg - [1] "dials" - - [[1]]$fun - [1] "epochs" - - [[1]]$range - [1] 5 100 - - - [[2]] - [[2]]$pkg - [1] "dials" - - [[2]]$fun - [1] "penalty" - - - [[3]] - [[3]]$pkg - [1] "dials" - - [[3]]$fun - [1] "learn_rate" - - [[3]]$range - [1] -3.0 -0.2 - - - [[4]] - [[4]]$pkg - [1] "dials" - - [[4]]$fun - [1] "momentum" - - [[4]]$range - [1] 0.50 0.95 - - - [[5]] - [[5]]$pkg - [1] "dials" - - [[5]]$fun - [1] "batch_size" - - - [[6]] - [[6]]$pkg - [1] "dials" - - [[6]]$fun - [1] "stop_iter" - - - [[7]] - [[7]]$pkg - [1] "dials" - - [[7]]$fun - [1] "class_weights" - - - ---- - - Code - brulee:::tunable.brulee_mlp(1)$call_info - Output - [[1]] - [[1]]$pkg - [1] "dials" - - [[1]]$fun - [1] "epochs" - - [[1]]$range - [1] 5 500 - - - [[2]] - [[2]]$pkg - [1] "dials" - - [[2]]$fun - [1] "hidden_units" - - [[2]]$range - [1] 2 50 - - - [[3]] - [[3]]$pkg - [1] "dials" - - [[3]]$fun - [1] "activation" - - [[3]]$values - [1] "relu" "tanh" "elu" "log_sigmoid" "tanhshrink" - - - [[4]] - [[4]]$pkg - [1] "dials" - - [[4]]$fun - [1] "penalty" - - - [[5]] - [[5]]$pkg - [1] "dials" - - [[5]]$fun - [1] "dropout" - - - [[6]] - [[6]]$pkg - [1] "dials" - - [[6]]$fun - [1] "learn_rate" - - [[6]]$range - [1] -3.0 -0.2 - - - [[7]] - [[7]]$pkg - [1] "dials" - - [[7]]$fun - [1] "momentum" - - [[7]]$range - [1] 0.50 0.95 - - - [[8]] - [[8]]$pkg - [1] "dials" - - [[8]]$fun - [1] "batch_size" - - - [[9]] - [[9]]$pkg - [1] "dials" - - [[9]]$fun - [1] "stop_iter" - - - [[10]] - [[10]]$pkg - [1] "dials" - - [[10]]$fun - [1] "class_weights" - - - ---- - - Code - brulee:::tunable.brulee_mlp_two_layer(1)$call_info - Output - [[1]] - [[1]]$pkg - [1] "dials" - - [[1]]$fun - [1] "epochs" - - [[1]]$range - [1] 5 500 - - - [[2]] - [[2]]$pkg - [1] "dials" - - [[2]]$fun - [1] "hidden_units" - - [[2]]$range - [1] 2 50 - - - [[3]] - [[3]]$pkg - [1] "dials" - - [[3]]$fun - [1] "hidden_units_2" - - [[3]]$range - [1] 2 50 - - - [[4]] - [[4]]$pkg - [1] "dials" - - [[4]]$fun - [1] "activation" - - [[4]]$values - [1] "relu" "tanh" "elu" "log_sigmoid" "tanhshrink" - - - [[5]] - [[5]]$pkg - [1] "dials" - - [[5]]$fun - [1] "activation_2" - - [[5]]$values - [1] "relu" "tanh" "elu" "log_sigmoid" "tanhshrink" - - - [[6]] - [[6]]$pkg - [1] "dials" - - [[6]]$fun - [1] "penalty" - - - [[7]] - [[7]]$pkg - [1] "dials" - - [[7]]$fun - [1] "dropout" - - - [[8]] - [[8]]$pkg - [1] "dials" - - [[8]]$fun - [1] "learn_rate" - - [[8]]$range - [1] -3.0 -0.2 - - - [[9]] - [[9]]$pkg - [1] "dials" - - [[9]]$fun - [1] "momentum" - - [[9]]$range - [1] 0.50 0.95 - - - [[10]] - [[10]]$pkg - [1] "dials" - - [[10]]$fun - [1] "batch_size" - - - [[11]] - [[11]]$pkg - [1] "dials" - - [[11]]$fun - [1] "stop_iter" - - - [[12]] - [[12]]$pkg - [1] "dials" - - [[12]]$fun - [1] "class_weights" - - - diff --git a/tests/testthat/test-checkers.R b/tests/testthat/test-checks.R similarity index 71% rename from tests/testthat/test-checkers.R rename to tests/testthat/test-checks.R index 40a2730..c2f087c 100644 --- a/tests/testthat/test-checkers.R +++ b/tests/testthat/test-checks.R @@ -1,19 +1,3 @@ -test_that("checking single logicals", { - library(rlang) - - variable <- "pie" - expect_snapshot(brulee:::check_single_logical(variable), error = TRUE) - - variable <- NA - expect_snapshot(brulee:::check_single_logical(variable), error = TRUE) - - variable <- c(TRUE, FALSE) - expect_snapshot(brulee:::check_single_logical(variable), error = TRUE) - - variable <- TRUE - expect_silent(brulee:::check_single_logical(variable)) -}) - test_that("checking double vectors", { library(rlang)