Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rsample fix for rlang::abort as cli_abort for 506 #523

Merged
merged 8 commits into from
Sep 9, 2024
28 changes: 14 additions & 14 deletions R/initial_validation_split.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,25 @@ initial_validation_split <- function(data,

check_prop_3 <- function(prop, call = rlang::caller_env()) {
if (!is.numeric(prop)) {
rlang::abort("`prop` needs to be numeric.", call = call)
cli_abort("`prop` needs to be numeric.", call = call)
hfrick marked this conversation as resolved.
Show resolved Hide resolved
}
if (any(is.na(prop))) {
rlang::abort("`prop` cannot contain `NA`.", call = call)
cli_abort("`prop` cannot contain `NA`.", call = call)
}
if (any(is.null(prop))) {
rlang::abort("`prop` cannot contain `NULL`.", call = call)
cli_abort("`prop` cannot contain `NULL`.", call = call)
}
if (length(prop) != 2L) {
rlang::abort(
cli_abort(
"`prop` needs to contain the proportions for training and validation.",
call = call
)
}
if (any(!(prop > 0)) | any(!(prop < 1))) {
rlang::abort("Elements of `prop` need to be in (0, 1).", call = call)
cli_abort("Elements of `prop` need to be in (0, 1).", call = call)
}
if (!(sum(prop) > 0 ) | !(sum(prop) < 1) ) {
rlang::abort(
cli_abort(
"The sum of the proportions in `prop` needs to be in (0, 1).",
call = call
)
Expand Down Expand Up @@ -303,8 +303,8 @@ validation <- function(x, ...) {
#' @rdname initial_validation_split
validation.default <- function(x, ...) {
cls <- class(x)
cli::cli_abort(
"No method for objects of class{?es}: {cls}"
cli_abort(
"No method for objects of class{?es}: {.cls {cls}} "
hfrick marked this conversation as resolved.
Show resolved Hide resolved
)
}

Expand All @@ -321,18 +321,18 @@ validation.initial_validation_split <- function(x, ...) {
#' @export
#' @keywords internal
analysis.initial_validation_split <- function(x, ...) {
rlang::abort(
"The initial validation split does not contain an analysis set.",
i = "You can access the training data with `training()`."
cli_abort(
c("The initial validation split does not contain an analysis set.",
"i" = "You can access the training data with {.fun training}.")
)
}

#' @export
#' @keywords internal
assessment.initial_validation_split <- function(x, ...) {
rlang::abort(
"The initial validation split does not contain an assessment set.",
i = "You can access the testing data with `testing()`."
cli_abort(
c("The initial validation split does not contain an assessment set.",
"i" = "You can access the testing data with {.fun testing}.")
)
}

Expand Down
8 changes: 4 additions & 4 deletions R/make_groups.R
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ check_prop <- function(prop, replace) {
((prop <= 1 && replace) || (prop < 1 && !replace))
acceptable_prop <- acceptable_prop && prop > 0
if (!acceptable_prop) {
rlang::abort(
cli_abort(
"`prop` must be a number between 0 and 1.",
hfrick marked this conversation as resolved.
Show resolved Hide resolved
call = rlang::caller_env()
)
Expand Down Expand Up @@ -345,13 +345,13 @@ validate_group <- function(group, data, call = rlang::caller_env()) {
}

if (is.null(group) || !is.character(group) || length(group) != 1) {
rlang::abort(
"`group` should be a single character value for the column that will be used for splitting.",
cli_abort(
"{.arg {group}} should be a single character value for the column that will be used for splitting.",
hfrick marked this conversation as resolved.
Show resolved Hide resolved
call = call
)
}
if (!any(names(data) == group)) {
rlang::abort("`group` should be a column in `data`.", call = call)
cli_abort("{.arg {group}} should be a column in {.arg {data}}.", call = call)
hfrick marked this conversation as resolved.
Show resolved Hide resolved
}

group
Expand Down
4 changes: 2 additions & 2 deletions R/mc.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ mc_complement <- function(ind, n) {
mc_splits <- function(data, prop = 3 / 4, times = 25,
strata = NULL, breaks = 4, pool = 0.1) {
if (!is.numeric(prop) | prop >= 1 | prop <= 0) {
rlang::abort("`prop` must be a number on (0, 1).")
cli_abort("`prop` must be a number on (0, 1).")
hfrick marked this conversation as resolved.
Show resolved Hide resolved
}

n <- nrow(data)
Expand Down Expand Up @@ -244,7 +244,7 @@ group_mc_splits <- function(data, group, prop = 3 / 4, times = 25, strata = NULL

all_assessable <- purrr::map(split_objs, function(x) nrow(assessment(x)))
if (any(all_assessable == 0)) {
rlang::abort(
cli_abort(
c(
"Some assessment sets contained zero rows",
i = "Consider using a non-grouped resampling method"
Expand Down
6 changes: 3 additions & 3 deletions R/nest.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ nested_cv <- function(data, outside, inside) {

inner_cl <- cl[["inside"]]
if (!is_call(inner_cl)) {
abort(
"`inside` should be a expression such as `vfold()` or ",
"bootstraps(times = 10)` instead of an existing object.",
cli_abort(
"{.arg {inside}} should be a expression such as {.fun vfold} or //
hfrick marked this conversation as resolved.
Show resolved Hide resolved
{.code bootstraps(times = 10)} instead of an existing object."
)
}
inside <- map(outside$splits, inside_resample, cl = inner_cl, env = env)
Expand Down
Loading