Skip to content

Commit

Permalink
Used cli abort for make_groups.r mc.R and nest.R
Browse files Browse the repository at this point in the history
  • Loading branch information
PriKalra committed Aug 15, 2024
1 parent fc4436c commit 4195508
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
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.",
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.",
call = call
)
}
if (!any(names(data) == group)) {
rlang::abort("`group` should be a column in `data`.", call = call)
cli_abort("`group` should be a column in `data`.", call = call)
}

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).")
}

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 //
{.code bootstraps(times = 10)} instead of an existing object."
)
}
inside <- map(outside$splits, inside_resample, cl = inner_cl, env = env)
Expand Down

0 comments on commit 4195508

Please sign in to comment.