@@ -24,7 +24,8 @@ make_splits <- function(x, ...) {
24
24
# ' data frame of analysis or training data.
25
25
# ' @export
26
26
make_splits.default <- function (x , ... ) {
27
- rlang :: abort(" There is no method available to make an rsplit from `x`." )
27
+ cls <- class(x )
28
+ cli_abort(" No method for objects of class{?es}: {cls}" )
28
29
}
29
30
30
31
# ' @rdname make_splits
@@ -47,15 +48,15 @@ make_splits.list <- function(x, data, class = NULL, ...) {
47
48
make_splits.data.frame <- function (x , assessment , ... ) {
48
49
rlang :: check_dots_empty()
49
50
if (nrow(x ) == 0 ) {
50
- rlang :: abort (" The analysis set must contain at least one row." )
51
+ cli_abort (" The analysis set must contain at least one row." )
51
52
}
52
53
53
54
ind_analysis <- seq_len(nrow(x ))
54
55
if (nrow(assessment ) == 0 ) {
55
56
ind_assessment <- integer()
56
57
} else {
57
58
if (! identical(colnames(x ), colnames(assessment ))) {
58
- rlang :: abort (" The analysis and assessment sets must have the same columns." )
59
+ cli_abort (" The analysis and assessment sets must have the same columns." )
59
60
}
60
61
ind_assessment <- nrow(x ) + seq_len(nrow(assessment ))
61
62
}
@@ -100,13 +101,13 @@ add_class <- function(x, cls) {
100
101
strata_check <- function (strata , data ) {
101
102
if (! is.null(strata )) {
102
103
if (! is.character(strata ) | length(strata ) != 1 ) {
103
- rlang :: abort( " ` strata` should be a single name or character value." )
104
+ cli_abort( " {.arg strata} should be a single name or character value." )
104
105
}
105
106
if (inherits(data [, strata ], " Surv" )) {
106
- rlang :: abort( " ` strata` cannot be a ` Surv` object. Use the time or event variable directly." )
107
+ cli_abort( " {.arg strata} cannot be a {.cls Surv} object. Use the time or event variable directly." )
107
108
}
108
109
if (! (strata %in% names(data ))) {
109
- rlang :: abort( strata , " is not in ` data` ." )
110
+ cli_abort( " { strata} is not in {.arg data} ." )
110
111
}
111
112
}
112
113
invisible (NULL )
@@ -148,10 +149,8 @@ split_unnamed <- function(x, f) {
148
149
# ' @export
149
150
# ' @rdname get_fingerprint
150
151
.get_fingerprint.default <- function (x , ... ) {
151
- cls <- paste0(" '" , class(x ), " '" , collapse = " , " )
152
- rlang :: abort(
153
- paste(" No `.get_fingerprint()` method for this class(es)" , cls )
154
- )
152
+ cls <- class(x )
153
+ cli_abort(" No method for objects of class{?es}: {cls}" )
155
154
}
156
155
157
156
# ' @export
@@ -192,16 +191,16 @@ reverse_splits <- function(x, ...) {
192
191
# ' @rdname reverse_splits
193
192
# ' @export
194
193
reverse_splits.default <- function (x , ... ) {
195
- rlang :: abort (
196
- " `x` must be either an ` rsplit` or an ` rset` object"
194
+ cli_abort (
195
+ " {.arg x} must be either an {.cls rsplit} or an {.cls rset} object. "
197
196
)
198
197
}
199
198
200
199
# ' @rdname reverse_splits
201
200
# ' @export
202
201
reverse_splits.permutations <- function (x , ... ) {
203
- rlang :: abort (
204
- " Permutations cannot have their splits reversed"
202
+ cli_abort (
203
+ " Permutations cannot have their splits reversed. "
205
204
)
206
205
}
207
206
@@ -253,18 +252,18 @@ reverse_splits.rset <- function(x, ...) {
253
252
# ' @export
254
253
reshuffle_rset <- function (rset ) {
255
254
if (! inherits(rset , " rset" )) {
256
- rlang :: abort( " ` rset` must be an rset object" )
255
+ cli_abort( " {.arg rset} must be an {.cls rset} object. " )
257
256
}
258
257
259
258
if (inherits(rset , " manual_rset" )) {
260
- rlang :: abort( " ` manual_rset` objects cannot be reshuffled" )
259
+ cli_abort( " {.arg manual_rset} objects cannot be reshuffled. " )
261
260
}
262
261
263
262
# non-random classes is defined below
264
263
if (any(non_random_classes %in% class(rset ))) {
265
264
cls <- class(rset )[[1 ]]
266
- rlang :: warn (
267
- glue :: glue( " ` reshuffle_rset()` will return an identical rset when called on {cls} objects" )
265
+ cli :: cli_warn (
266
+ " {.fun reshuffle_rset} will return an identical {.cls rset} when called on {. cls {cls}} objects. "
268
267
)
269
268
if (" validation_set" %in% class(rset )) {
270
269
return (rset )
@@ -274,10 +273,10 @@ reshuffle_rset <- function(rset) {
274
273
rset_type <- class(rset )[[1 ]]
275
274
split_arguments <- .get_split_args(rset )
276
275
if (identical(split_arguments $ strata , TRUE )) {
277
- rlang :: abort (
278
- " Cannot reshuffle this rset (` attr(rset, 'strata')` is ` TRUE` , not a column identifier)" ,
279
- i = " If the original object was created with an older version of rsample, try recreating it with the newest version of the package"
280
- )
276
+ cli_abort(c (
277
+ " Cannot reshuffle this rset ({.code attr(rset, 'strata')} is {.val TRUE} , not a column identifier)" ,
278
+ i = " If the original object was created with an older version of rsample, try recreating it with the newest version of the package. "
279
+ ))
281
280
}
282
281
283
282
do.call(
@@ -297,8 +296,8 @@ non_random_classes <- c(
297
296
298
297
# ' Get the split arguments from an rset
299
298
# ' @param x An `rset` or `initial_split` object.
300
- # ' @param allow_strata_false A logical to specify which value to use if no
301
- # ' stratification was specified. The default is to use `strata = NULL`, the
299
+ # ' @param allow_strata_false A logical to specify which value to use if no
300
+ # ' stratification was specified. The default is to use `strata = NULL`, the
302
301
# ' alternative is `strata = FALSE`.
303
302
# ' @return A list of arguments used to create the rset.
304
303
# ' @keywords internal
@@ -315,7 +314,7 @@ non_random_classes <- c(
315
314
args <- names(formals(function_used_to_create ))
316
315
split_args <- all_attributes [args ]
317
316
split_args <- split_args [! is.na(names(split_args ))]
318
-
317
+
319
318
if (identical(split_args $ strata , FALSE ) && ! allow_strata_false ) {
320
319
split_args $ strata <- NULL
321
320
}
@@ -361,10 +360,10 @@ get_rsplit.rset <- function(x, index, ...) {
361
360
glue :: glue(" A value of {index} was provided." )
362
361
)
363
362
364
- rlang :: abort (
363
+ cli_abort (
365
364
c(
366
- glue :: glue( " ` index` must be a length-1 integer between 1 and {n_rows}." ) ,
367
- x = msg
365
+ " {.arg index} must be a length-1 integer between 1 and {n_rows}." ,
366
+ " * " = msg
368
367
)
369
368
)
370
369
}
@@ -375,8 +374,6 @@ get_rsplit.rset <- function(x, index, ...) {
375
374
# ' @rdname get_rsplit
376
375
# ' @export
377
376
get_rsplit.default <- function (x , index , ... ) {
378
- cls <- paste0(" '" , class(x ), " '" , collapse = " , " )
379
- rlang :: abort(
380
- paste(" No `get_rsplit()` method for this class(es)" , cls )
381
- )
377
+ cls <- class(x )
378
+ cli_abort(" No method for objects of class{?es}: {cls}" )
382
379
}
0 commit comments