Skip to content

Commit 77ab7df

Browse files
authored
Merge pull request #532 from PriKalra/cliErrorRssample514
There are snapshot test errors for validation_set and vfold.
2 parents 6e2721a + a4f7e5c commit 77ab7df

9 files changed

+43
-42
lines changed

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ export(validation_time_split)
416416
export(vfold_cv)
417417
import(vctrs)
418418
importFrom(cli,cli_abort)
419+
importFrom(cli,cli_warn)
419420
importFrom(dplyr,"%>%")
420421
importFrom(dplyr,arrange)
421422
importFrom(dplyr,arrange_)

NEWS.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
* 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).
44

5-
* Started moving error messages to cli (#499, #502). With contributions from @PriKalra (#523, #526, #528, #530, #531) and @JamesHWade (#518).
5+
* Started moving error messages to cli (#499, #502). With contributions from @PriKalra (#523, #526, #528, #530, #531, #532) and @JamesHWade (#518).
66

77
* Fixed example for `nested_cv()` (@seb09, #520).
88

R/rsample-package.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
## usethis namespace: start
55
#' @importFrom lifecycle deprecated
6-
#' @importFrom cli cli_abort
6+
#' @importFrom cli cli_abort cli_warn
77
## usethis namespace: end
88
NULL
99

R/tidy.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ tidy.nested_cv <- function(x, unique_ind = TRUE, ...) {
119119

120120
inner_id <- grep("^id", names(inner_tidy))
121121
if (length(inner_id) != length(id_cols)) {
122-
rlang::abort("Cannot merge tidy data sets")
122+
cli_abort("Cannot merge tidy data sets.")
123123
}
124124
names(inner_tidy)[inner_id] <- id_cols
125125
full_join(outer_tidy, inner_tidy, by = id_cols)

R/validation_set.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ validation.val_split <- function(x, ...) {
9191
#' @rdname validation_set
9292
#' @export
9393
testing.val_split <- function(x, ...) {
94-
rlang::abort(
95-
"The testing data is not part of the validation set object.",
96-
i = "It is part of the result of the initial 3-way split, e.g., with `initial_validation_split()`."
97-
)
94+
cli_abort(c(
95+
"The testing data is not part of the validation set object.",
96+
"i" = "It is part of the result of the initial 3-way split, e.g., with {.fun initial_validation_split}."
97+
))
9898
}

R/vfold.R

+19-20
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ vfold_cv <- function(data, v = 10, repeats = 1,
8181
)
8282
} else {
8383
if (v == nrow(data)) {
84-
rlang::abort(
85-
glue::glue("Repeated resampling when `v` is {v} would create identical resamples")
84+
cli_abort(
85+
"Repeated resampling when {.arg v} is {v} would create identical resamples."
8686
)
8787
}
8888
for (i in 1:repeats) {
@@ -225,14 +225,13 @@ group_vfold_cv <- function(data, group = NULL, v = NULL, repeats = 1, balance =
225225
split_objs <- group_vfold_splits(data = data, group = group, v = v, balance = balance, strata = strata, pool = pool)
226226
} else {
227227
if (is.null(v)) {
228-
rlang::abort(
229-
"Repeated resampling when `v` is `NULL` would create identical resamples"
228+
cli_abort(
229+
"Repeated resampling when {.arg v} is {.val NULL} would create identical resamples."
230230
)
231231
}
232232
if (v == length(unique(getElement(data, group)))) {
233-
rlang::abort(
234-
glue::glue("Repeated resampling when `v` is {v} would create identical resamples")
235-
)
233+
cli_abort("Repeated resampling when {.arg v} is {.val {v}} would create identical resamples.")
234+
236235
}
237236
for (i in 1:repeats) {
238237
tmp <- group_vfold_splits(data = data, group = group, v = v, balance = balance, strata = strata, pool = pool)
@@ -288,21 +287,20 @@ group_vfold_splits <- function(data, group, v = NULL, balance, strata = NULL, po
288287
)$count
289288
)
290289
message <- c(
291-
"Leaving `v = NULL` while using stratification will set `v` to the number of groups present in the least common stratum."
290+
"Leaving {.code v = NULL} while using stratification will set {.arg v} to the number of groups present in the least common stratum."
292291
)
293292

294293
if (max_v < 5) {
295-
rlang::abort(c(
294+
cli_abort(c(
296295
message,
297-
x = glue::glue("The least common stratum only had {max_v} groups, which may not be enough for cross-validation."),
298-
i = "Set `v` explicitly to override this error."
299-
),
300-
call = rlang::caller_env())
296+
"*" = "The least common stratum only had {.val {max_v}} groups, which may not be enough for cross-validation.",
297+
"i" = "Set {.arg v} explicitly to override this error."
298+
), call = rlang::caller_env())
301299
}
302300

303-
rlang::warn(c(
301+
cli_warn(c(
304302
message,
305-
i = "Set `v` explicitly to override this warning."
303+
i = "Set {.arg v} explicitly to override this warning."
306304
),
307305
call = rlang::caller_env())
308306
}
@@ -334,10 +332,11 @@ add_vfolds <- function(x, v) {
334332

335333
check_v <- function(v, max_v, rows = "rows", prevent_loo = TRUE, call = rlang::caller_env()) {
336334
if (!is.numeric(v) || length(v) != 1 || v < 2) {
337-
rlang::abort("`v` must be a single positive integer greater than 1", call = call)
335+
cli_abort("{.arg v} must be a single positive integer greater than 1.", call = call)
338336
} else if (v > max_v) {
339-
rlang::abort(
340-
glue::glue("The number of {rows} is less than `v = {v}`"), call = call
337+
cli_abort(
338+
"The number of {rows} is less than {.arg v} = {.val {v}}.",
339+
call = call
341340
)
342341
} else if (prevent_loo && isTRUE(v == max_v)) {
343342
cli_abort(c(
@@ -364,14 +363,14 @@ check_grouped_strata <- function(group, strata, pool, data) {
364363

365364
if (nrow(vctrs::vec_unique(grouped_table)) !=
366365
nrow(vctrs::vec_unique(grouped_table["group"]))) {
367-
rlang::abort("`strata` must be constant across all members of each `group`.")
366+
cli_abort("{.arg strata} must be constant across all members of each {.arg group}.")
368367
}
369368

370369
strata
371370
}
372371

373372
check_repeats <- function(repeats, call = rlang::caller_env()) {
374373
if (!is.numeric(repeats) || length(repeats) != 1 || repeats < 1) {
375-
rlang::abort("`repeats` must be a single positive integer", call = call)
374+
cli_abort("{.arg repeats} must be a single positive integer.", call = call)
376375
}
377376
}

tests/testthat/_snaps/clustering.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
---
66

7-
`v` must be a single positive integer greater than 1
7+
`v` must be a single positive integer greater than 1.
88

99
---
1010

11-
The number of rows is less than `v = 500`
11+
The number of rows is less than `v` = 500.
1212

1313
---
1414

@@ -20,15 +20,15 @@
2020
clustering_cv(Orange, v = 1, vars = "Tree")
2121
Condition
2222
Error in `clustering_cv()`:
23-
! `v` must be a single positive integer greater than 1
23+
! `v` must be a single positive integer greater than 1.
2424

2525
---
2626

27-
`repeats` must be a single positive integer
27+
`repeats` must be a single positive integer.
2828

2929
---
3030

31-
`repeats` must be a single positive integer
31+
`repeats` must be a single positive integer.
3232

3333
---
3434

tests/testthat/_snaps/validation_set.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
Condition
66
Error in `testing()`:
77
! The testing data is not part of the validation set object.
8+
i It is part of the result of the initial 3-way split, e.g., with `initial_validation_split()`.
89

tests/testthat/_snaps/vfold.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,31 @@
99

1010
# bad args
1111

12-
`v` must be a single positive integer greater than 1
12+
`v` must be a single positive integer greater than 1.
1313

1414
---
1515

16-
`v` must be a single positive integer greater than 1
16+
`v` must be a single positive integer greater than 1.
1717

1818
---
1919

20-
`v` must be a single positive integer greater than 1
20+
`v` must be a single positive integer greater than 1.
2121

2222
---
2323

24-
The number of rows is less than `v = 500`
24+
The number of rows is less than `v` = 500.
2525

2626
---
2727

28-
Repeated resampling when `v` is 150 would create identical resamples
28+
Repeated resampling when `v` is 150 would create identical resamples.
2929

3030
---
3131

32-
`repeats` must be a single positive integer
32+
`repeats` must be a single positive integer.
3333

3434
---
3535

36-
`repeats` must be a single positive integer
36+
`repeats` must be a single positive integer.
3737

3838
---
3939

@@ -67,19 +67,19 @@
6767

6868
# grouping -- bad args
6969

70-
Repeated resampling when `v` is 4 would create identical resamples
70+
Repeated resampling when `v` is 4 would create identical resamples.
7171

7272
---
7373

74-
Repeated resampling when `v` is `NULL` would create identical resamples
74+
Repeated resampling when `v` is "NULL" would create identical resamples.
7575

7676
---
7777

7878
Code
7979
group_vfold_cv(Orange, v = 1, group = "Tree")
8080
Condition
8181
Error in `group_vfold_cv()`:
82-
! `v` must be a single positive integer greater than 1
82+
! `v` must be a single positive integer greater than 1.
8383

8484
# grouping -- other balance methods
8585

0 commit comments

Comments
 (0)