@@ -81,8 +81,8 @@ vfold_cv <- function(data, v = 10, repeats = 1,
81
81
)
82
82
} else {
83
83
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. "
86
86
)
87
87
}
88
88
for (i in 1 : repeats ) {
@@ -225,14 +225,13 @@ group_vfold_cv <- function(data, group = NULL, v = NULL, repeats = 1, balance =
225
225
split_objs <- group_vfold_splits(data = data , group = group , v = v , balance = balance , strata = strata , pool = pool )
226
226
} else {
227
227
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. "
230
230
)
231
231
}
232
232
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
+
236
235
}
237
236
for (i in 1 : repeats ) {
238
237
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
288
287
)$ count
289
288
)
290
289
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."
292
291
)
293
292
294
293
if (max_v < 5 ) {
295
- rlang :: abort (c(
294
+ cli_abort (c(
296
295
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())
301
299
}
302
300
303
- rlang :: warn (c(
301
+ cli_warn (c(
304
302
message ,
305
- i = " Set `v` explicitly to override this warning."
303
+ i = " Set {.arg v} explicitly to override this warning."
306
304
),
307
305
call = rlang :: caller_env())
308
306
}
@@ -334,10 +332,11 @@ add_vfolds <- function(x, v) {
334
332
335
333
check_v <- function (v , max_v , rows = " rows" , prevent_loo = TRUE , call = rlang :: caller_env()) {
336
334
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 )
338
336
} 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
341
340
)
342
341
} else if (prevent_loo && isTRUE(v == max_v )) {
343
342
cli_abort(c(
@@ -364,14 +363,14 @@ check_grouped_strata <- function(group, strata, pool, data) {
364
363
365
364
if (nrow(vctrs :: vec_unique(grouped_table )) !=
366
365
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} ." )
368
367
}
369
368
370
369
strata
371
370
}
372
371
373
372
check_repeats <- function (repeats , call = rlang :: caller_env()) {
374
373
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 )
376
375
}
377
376
}
0 commit comments