Skip to content

Commit

Permalink
Merge pull request #518 from JamesHWade/rsplit-cli-errors
Browse files Browse the repository at this point in the history
Use cli erros in rsplit.R Fixes #512
  • Loading branch information
hfrick authored Aug 15, 2024
2 parents 5eb77d4 + 0e87add commit 90b2a87
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 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).
* Started moving error messages to cli (#499, #502). With contributions from @JamesHWade (#518).

## Bug fixes

Expand Down
31 changes: 15 additions & 16 deletions R/rsplit.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
rsplit <- function(data, in_id, out_id) {
if (!is.data.frame(data) & !is.matrix(data)) {
rlang::abort("`data` must be a data frame.")
cli_abort("{.arg data} must be a data frame.")
}

if (!is.integer(in_id) | any(in_id < 1)) {
rlang::abort("`in_id` must be a positive integer vector.")
cli_abort("{.arg in_id} must be a positive integer vector.")
}

if (!all(is.na(out_id))) {
if (!is.integer(out_id) | any(out_id < 1)) {
rlang::abort("`out_id` must be a positive integer vector.")
cli_abort("{.arg out_id} must be a positive integer vector.")
}
}

if (length(in_id) == 0) {
rlang::abort("At least one row should be selected for the analysis set.")
cli_abort("At least one row should be selected for the analysis set.")
}

structure(
Expand Down Expand Up @@ -88,26 +88,25 @@ as.data.frame.rsplit <-
data = "analysis",
...) {
if (!is.null(row.names)) {
rlang::warn(paste0(
"`row.names` is kept for consistency with the underlying class but ",
"non-NULL values will be ignored."
))
cli::cli_warn(
"{.arg row.names} is kept for consistency with the underlying class but
non-NULL values will be ignored."
)
}
if (optional) {
rlang::warn(paste0(
"`optional` is kept for consistency with the underlying class but ",
"TRUE values will be ignored."
))
cli::cli_warn(
"{.arg optional} is kept for consistency with the underlying class but
TRUE values will be ignored."
)

}
if (!is.null(x$col_id)) {
if (identical(data, "assessment")) {
rsplit_class <- class(x)[[1]]
msg <- paste0(
"There is no assessment data set for an `rsplit` object",
" with class `", rsplit_class, "`."
cli_abort(
"There is no assessment data set for an {.arg rsplit} object
with class {.cls {rsplit_class}}."
)
rlang::abort(msg)
}
ind <- as.integer(x, data = data, ...)
permuted_col <- vctrs::vec_slice(x$data, ind) %>%
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/permutations.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
assessment(xx$splits[[1]])
Condition
Error in `as.data.frame()`:
! There is no assessment data set for an `rsplit` object with class `perm_split`.
! There is no assessment data set for an `rsplit` object with class <perm_split>.

# printing

Expand Down

0 comments on commit 90b2a87

Please sign in to comment.