Skip to content

Commit

Permalink
pass call to check_for_disaster()
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilHvitfeldt committed Jan 21, 2025
1 parent 828cecd commit e2d17c0
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 17 deletions.
4 changes: 2 additions & 2 deletions R/C5.0.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

c5_bagger <- function(rs, control, ...) {
c5_bagger <- function(rs, control, ..., call) {

opt <- rlang::dots_list(...)
mod_spec <- make_c5_spec(opt)
Expand All @@ -17,7 +17,7 @@ c5_bagger <- function(rs, control, ...) {
control = control
))

rs <- check_for_disaster(rs)
rs <- check_for_disaster(rs, call = call)

rs <- filter_rs(rs)

Expand Down
8 changes: 4 additions & 4 deletions R/bridge.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ bagger_bridge <- function(processed, weights, base_model, seed, times, control,
if (is.null(cost)) {
res <- switch(
base_model,
CART = cart_bagger(rs, control, ...),
C5.0 = c5_bagger(rs, control, ...),
MARS = mars_bagger(rs, control, ...),
nnet = nnet_bagger(rs, control, ...)
CART = cart_bagger(rs, control, ..., call = call),
C5.0 = c5_bagger(rs, control, ..., call = call),
MARS = mars_bagger(rs, control, ..., call = call),
nnet = nnet_bagger(rs, control, ..., call = call)
)
} else {
res <- switch(
Expand Down
4 changes: 2 additions & 2 deletions R/cart.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

cart_bagger <- function(rs, control, ...) {
cart_bagger <- function(rs, control, ..., call) {
opt <- rlang::dots_list(...)
is_classif <- is.factor(rs$splits[[1]]$data$.outcome)
mod_spec <- make_cart_spec(is_classif, opt)
Expand All @@ -19,7 +19,7 @@ cart_bagger <- function(rs, control, ...) {
)
)

rs <- check_for_disaster(rs)
rs <- check_for_disaster(rs, call = call)

rs <- filter_rs(rs)

Expand Down
4 changes: 2 additions & 2 deletions R/cost_models.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ cost_sens_cart_bagger <- function(rs, control, cost, ..., call = rlang::caller_e
opt$parms <- list(loss = cost)
}

cart_bagger(rs = rs, control = control, !!!opt)
cart_bagger(rs = rs, control = control, call = call, !!!opt)
}


Expand All @@ -54,5 +54,5 @@ cost_sens_c5_bagger <- function(rs, control, cost, ..., call = rlang::caller_env
# Attach cost matrix to options
opt$costs <- cost

c5_bagger(rs = rs, control = control, !!!opt)
c5_bagger(rs = rs, control = control, call = call, !!!opt)
}
4 changes: 2 additions & 2 deletions R/mars.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

mars_bagger <- function(rs, control, ...) {
mars_bagger <- function(rs, control, ..., call) {

opt <- rlang::dots_list(...)
is_classif <- is.factor(rs$splits[[1]]$data$.outcome)
Expand All @@ -18,7 +18,7 @@ mars_bagger <- function(rs, control, ...) {
control = control
))

rs <- check_for_disaster(rs)
rs <- check_for_disaster(rs, call = call)

rs <- filter_rs(rs)

Expand Down
4 changes: 2 additions & 2 deletions R/nnet.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

nnet_bagger <- function(rs, control, ...) {
nnet_bagger <- function(rs, control, ..., call) {
opt <- rlang::dots_list(...)
is_classif <- is.factor(rs$splits[[1]]$data$.outcome)
mod_spec <- make_nnet_spec(is_classif, opt)
Expand All @@ -19,7 +19,7 @@ nnet_bagger <- function(rs, control, ...) {
)
)

rs <- check_for_disaster(rs)
rs <- check_for_disaster(rs, call = call)

rs <- filter_rs(rs)

Expand Down
7 changes: 5 additions & 2 deletions R/validate.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,12 @@ check_for_disaster <- function(x, call = rlang::caller_env()) {
if (!is.na(msg)) {
# escape any brackets in the error message
msg <- cli::format_error("{msg}")
cli::cli_abort(c("All of the models failed. Example:", "x" = "{msg}"))
cli::cli_abort(
c("All of the models failed. Example:", "x" = "{msg}"),
call = call
)
} else {
cli::cli_abort("All of the models failed.")
cli::cli_abort("All of the models failed.", call = call)

Check warning on line 77 in R/validate.R

View check run for this annotation

Codecov / codecov/patch

R/validate.R#L77

Added line #L77 was not covered by tests
}
}
x
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
set.seed(459394)
bagger(a ~ ., data = bad_iris, base_model = "CART", times = 3)
Condition
Error in `check_for_disaster()`:
Error in `bagger()`:
! All of the models failed. Example:
x Error in cbind(yval2, yprob, nodeprob) : number of rows of matrices must match (see arg 2)

Expand Down

0 comments on commit e2d17c0

Please sign in to comment.