@@ -134,11 +134,9 @@ translate.boost_tree <- function(x, engine = x$engine, ...) {
134
134
135
135
if (engine == " spark" ) {
136
136
if (x $ mode == " unknown" ) {
137
- rlang :: abort(
138
- glue :: glue(
139
- " For spark boosted trees models, the mode cannot be 'unknown' " ,
140
- " if the specification is to be translated."
141
- )
137
+ cli :: cli_abort(
138
+ " For spark boosted tree models, the mode cannot be {.val unknown}
139
+ if the specification is to be translated."
142
140
)
143
141
} else {
144
142
arg_vals $ type <- x $ mode
@@ -172,7 +170,7 @@ check_args.boost_tree <- function(object, call = rlang::caller_env()) {
172
170
check_number_decimal(args $ sample_size , min = 0 , max = 1 , allow_null = TRUE , call = call , arg = " sample_size" )
173
171
check_number_whole(args $ tree_depth , min = 0 , allow_null = TRUE , call = call , arg = " tree_depth" )
174
172
check_number_whole(args $ min_n , min = 0 , allow_null = TRUE , call = call , arg = " min_n" )
175
-
173
+
176
174
invisible (object )
177
175
}
178
176
@@ -229,15 +227,15 @@ xgb_train <- function(
229
227
num_class <- length(levels(y ))
230
228
231
229
if (! is.numeric(validation ) || validation < 0 || validation > = 1 ) {
232
- rlang :: abort( " ` validation` should be on [0, 1)." )
230
+ cli :: cli_abort( " {.arg validation} should be on [0, 1)." )
233
231
}
234
232
235
233
if (! is.null(early_stop )) {
236
234
if (early_stop < = 1 ) {
237
- rlang :: abort(paste0( " ` early_stop` should be on [2, " , nrounds , " )." ) )
235
+ cli :: cli_abort( " {.arg early_stop} should be on [2, { nrounds} )." )
238
236
} else if (early_stop > = nrounds ) {
239
237
early_stop <- nrounds - 1
240
- rlang :: warn(paste0( " ` early_stop` was reduced to " , early_stop , " . " ) )
238
+ cli :: cli_warn( " {.arg early_stop} was reduced to { early_stop}. " )
241
239
}
242
240
}
243
241
@@ -252,7 +250,7 @@ xgb_train <- function(
252
250
253
251
254
252
if (! is.numeric(subsample ) || subsample < 0 || subsample > 1 ) {
255
- rlang :: abort( " ` subsample` should be on [0, 1]." )
253
+ cli :: cli_abort( " {.arg subsample} should be on [0, 1]." )
256
254
}
257
255
258
256
# initialize
@@ -268,9 +266,13 @@ xgb_train <- function(
268
266
}
269
267
270
268
if (min_child_weight > n ) {
271
- msg <- paste0(min_child_weight , " samples were requested but there were " ,
272
- n , " rows in the data. " , n , " will be used." )
273
- rlang :: warn(msg )
269
+ cli :: cli_warn(
270
+ c(
271
+ " !" = " {min_child_weight} samples were requested but there were {n} rows
272
+ in the data." ,
273
+ " i" = " {n} will be used."
274
+ )
275
+ )
274
276
min_child_weight <- min(min_child_weight , n )
275
277
}
276
278
@@ -369,14 +371,16 @@ recalc_param <- function(x, counts, denom) {
369
371
x
370
372
}
371
373
372
- maybe_proportion <- function (x , nm ) {
374
+ maybe_proportion <- function (x , nm , call = rlang :: caller_env() ) {
373
375
if (x < 1 ) {
374
- msg <- paste0(
375
- " The option `counts = TRUE` was used but parameter `" , nm ,
376
- " ` was given as " , signif(x , 3 ), " . Please use a value >= 1 or use " ,
377
- " `counts = FALSE`."
376
+ cli :: cli_abort(
377
+ c(
378
+ " The option `counts = TRUE` was used but {.arg {nm}} was given
379
+ as {signif(x, 3)}." ,
380
+ " i" = " Please use a value >= 1 or use {.code counts = FALSE}."
381
+ ),
382
+ call = call
378
383
)
379
- rlang :: abort(msg )
380
384
}
381
385
}
382
386
@@ -418,7 +422,9 @@ as_xgb_data <- function(x, y, validation = 0, weights = NULL, event_level = "fir
418
422
y <- as.numeric(y ) - 1
419
423
}
420
424
} else {
421
- if (event_level == " second" ) rlang :: warn(" `event_level` can only be set for binary variables." )
425
+ if (event_level == " second" ) {
426
+ cli :: cli_warn(" {.arg event_level} can only be set for binary outcomes." )
427
+ }
422
428
y <- as.numeric(y ) - 1
423
429
}
424
430
}
@@ -573,15 +579,19 @@ C5.0_train <-
573
579
574
580
n <- nrow(x )
575
581
if (n == 0 ) {
576
- rlang :: abort (" There are zero rows in the predictor set." )
582
+ cli :: cli_abort (" There are zero rows in the predictor set." )
577
583
}
578
584
579
585
580
586
ctrl <- call2(" C5.0Control" , .ns = " C50" )
581
587
if (minCases > n ) {
582
- msg <- paste0(minCases , " samples were requested but there were " ,
583
- n , " rows in the data. " , n , " will be used." )
584
- rlang :: warn(msg )
588
+
589
+ cli :: cli_warn(
590
+ c(
591
+ " !" = " {minCases} samples were requested but there were {n} rows in the data." ,
592
+ " i" = " {n} will be used."
593
+ )
594
+ )
585
595
minCases <- n
586
596
}
587
597
ctrl $ minCases <- minCases
0 commit comments