Skip to content

Commit

Permalink
Merge pull request #517 from Dpananos/cli_caret
Browse files Browse the repository at this point in the history
Uses cli_abort in R/caret.R
  • Loading branch information
hfrick authored Sep 12, 2024
2 parents 5c84b97 + 417aae3 commit e489196
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, #531, #532), @Dpananos (#516), and @JamesHWade (#518).
* Started moving error messages to cli (#499, #502). With contributions from @PriKalra (#523, #526, #528, #530, #531, #532), @Dpananos (#516, #517), and @JamesHWade (#518).

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

Expand Down
25 changes: 10 additions & 15 deletions R/caret.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' @export
rsample2caret <- function(object, data = c("analysis", "assessment")) {
if (!inherits(object, "rset")) {
rlang::abort("`object` must be an `rset`")
cli_abort("{.arg object} must be an {.cls rset}.")
}
data <- rlang::arg_match(data)
in_ind <- purrr::map(object$splits, as.integer, data = "analysis")
Expand All @@ -32,19 +32,19 @@ rsample2caret <- function(object, data = c("analysis", "assessment")) {
#' @export
caret2rsample <- function(ctrl, data = NULL) {
if (is.null(data)) {
rlang::abort("Must supply original data")
cli_abort("Must supply original data")
}
if (!any(names(ctrl) == "index")) {
rlang::abort("`ctrl` should have an element `index`")
cli_abort("{.arg ctrl} should have an element {.val index}")
}
if (!any(names(ctrl) == "indexOut")) {
rlang::abort("`ctrl` should have an element `indexOut`")
cli_abort("{.arg ctrl} should have an element {.val indexOut}")
}
if (is.null(ctrl$index)) {
rlang::abort("`ctrl$index` should be populated with integers")
cli_abort("{.val ctrl$index} should be populated with integers")
}
if (is.null(ctrl$indexOut)) {
rlang::abort("`ctrl$indexOut` should be populated with integers")
cli_abort("{.val ctrl$indexOut} should be populated with integers")
}

indices <- purrr::map2(ctrl$index, ctrl$indexOut, extract_int)
Expand Down Expand Up @@ -112,10 +112,8 @@ map_rsplit_method <- function(method) {
"error"
)
if (out == "error") {
rlang::abort(
"Resampling method `",
method,
"` cannot be converted into an `rsplit` object"
cli_abort(
"Resampling method {.arg method} cannot be converted into an {.cls rsplit} object"
)
}
out
Expand All @@ -139,10 +137,7 @@ map_rset_method <- function(method) {
"error"
)
if (out == "error") {
rlang::abort("Resampling method `",
method,
"` cannot be converted into an `rset` object"
)
cli_abort("Resampling method {.arg method} cannot be converted into an {.cls rset} object")
}
out
}
Expand Down Expand Up @@ -179,7 +174,7 @@ map_attr <- function(object) {
skip = object$skip
)
} else {
rlang::abort("Method", object$method, "cannot be converted")
cli_abort("Method {.arg object$method} cannot be converted")
}
out
}

0 comments on commit e489196

Please sign in to comment.