diff --git a/NEWS.md b/NEWS.md index 4960e310..dcd0ac7f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,7 @@ * The new `inner_split()` function and its methods for various resamples is for usage in tune to create a inner resample of the analysis set to fit the preprocessor and model on one part and the post-processor on the other part (#483, #488, #489). -* Started moving error messages to cli (#499, #502). With contributions from @PriKalra (#523, #526, #528, #530) and @JamesHWade (#518). +* Started moving error messages to cli (#499, #502). With contributions from @PriKalra (#523, #526, #528, #530, #531) and @JamesHWade (#518). * Fixed example for `nested_cv()` (@seb09, #520). diff --git a/R/permutations.R b/R/permutations.R index c9702e48..44ae1b39 100644 --- a/R/permutations.R +++ b/R/permutations.R @@ -53,14 +53,19 @@ permutations <- function(data, permute <- rlang::enquo(permute) if (is.null(permute)) { - rlang::abort("You must specify at least one column to permute!") + cli_abort("You must specify at least one column to permute.") } col_id <- tidyselect::eval_select(permute, data) if (identical(length(col_id), 0L)) { - rlang::abort("You must specify at least one column to permute!") + cli_abort("You must specify at least one column to permute.") } else if (identical(length(col_id), ncol(data))) { - rlang::abort("You have selected all columns to permute. This effectively reorders the rows in the original data without changing the data structure. Please select fewer columns to permute.") + cli_abort(c( + "You have selected all columns to permute.", + "i" = "This effectively reorders the rows in the original data without + changing the data structure.", + ">" = "Please select fewer columns to permute." + )) } split_objs <- perm_splits(data, times) diff --git a/R/reg_intervals.R b/R/reg_intervals.R index e820ab77..05610636 100644 --- a/R/reg_intervals.R +++ b/R/reg_intervals.R @@ -54,12 +54,12 @@ reg_intervals <- } else { times <- times[1] if (!is.numeric(times)) { - rlang::abort("'times' should be a single integer.") + cli_abort("{.arg times} should be a single integer.") } } if (length(alpha) != 1 || !is.numeric(alpha)) { - abort("`alpha` must be a single numeric value.") + cli_abort("{.arg alpha} must be a single numeric value.") } if (model_fn %in% c("survreg", "coxph")) { diff --git a/tests/testthat/_snaps/permutations.md b/tests/testthat/_snaps/permutations.md index 1f1b3571..84233a4f 100644 --- a/tests/testthat/_snaps/permutations.md +++ b/tests/testthat/_snaps/permutations.md @@ -6,6 +6,16 @@ Error in `as.data.frame()`: ! There is no assessment data set for an `rsplit` object with class . +# bad args + + Code + permutations(mtcars, everything()) + Condition + Error in `permutations()`: + ! You have selected all columns to permute. + i This effectively reorders the rows in the original data without changing the data structure. + > Please select fewer columns to permute. + # printing Code diff --git a/tests/testthat/test-permutations.R b/tests/testthat/test-permutations.R index e2cd4702..91e3dfdf 100644 --- a/tests/testthat/test-permutations.R +++ b/tests/testthat/test-permutations.R @@ -37,7 +37,7 @@ test_that("bad args", { expect_error(permutations(mtcars)) # no columns specified expect_error(permutations(mtcars, foo)) # column doesn't exist expect_error(permutations(mtcars, start_with("z"))) # column doesn't exist - expect_error(permutations(mtcars, everything())) # all columns + expect_snapshot(error = TRUE, {permutations(mtcars, everything())}) # all columns }) test_that("printing", {