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

improve error messages #80

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

improve error messages #80

wants to merge 13 commits into from

Conversation

topepo
Copy link
Member

@topepo topepo commented Oct 22, 2024

This needed sooo much upkeep that it was difficult to separate the different modes of error upgrades.

This PR adds type checkers, refines cli messages, routes calls to the user-facing function, and cleans up a bunch of dplyr/purrr calls that lack namespaces.

@@ -89,6 +89,7 @@
#' cart_pca_bag
#' }
#' @export
#' @include validate.R
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DOWN WITH aaa FILES

}

# TODO extend to use mode from model object(s)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could eventually extend baguette to censored regression models. There is a lot of code that looks at the data to get the mode or assumes that they are either regression or classification.

@topepo topepo mentioned this pull request Oct 22, 2024
}

if (!is.na(msg)) {
# escape any brackets in the error message
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A long way to get there but this should make much much nicer error messages when models fail

Code
bagger(Sepal.Length ~ ., data = iris, times = 2L, base_model = "C5.0")
Condition
Error in `validate_outcomes_are_factors()`:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of our snapshots are going to change once these hardhat functions can take calls

@topepo topepo marked this pull request as ready for review October 22, 2024 14:26
Copy link
Member

@EmilHvitfeldt EmilHvitfeldt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

by looking at the snapshots, i see some calls aren't passed through to hardhat::validate_outcomes_are_factors() and
validate_outcomes_are_univariate(). these don't yet have call arguments so we have to wait for {hardhat} for them

there is also a call to stop() on line 100 of R/bagger.R that needs to be converted. Wasn't able to tag directly as it is "outside of github scope"

Comment on lines +180 to +185
expect_snapshot({
set.seed(459394)
bagger(a ~ ., data = bad_iris, base_model = "CART", times = 3)
},
error = TRUE
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This snapshot bubbles up the issue that check_for_disaster() doesn't pass calls around

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at one point in time. ideally this should say Error in bagger(): not Error in check_for_disaster():

}

integer_B <- function(B) {
if (is.numeric(B) & !is.integer(B)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (is.numeric(B) & !is.integer(B)) {
if (is.double(B)) {

Comment on lines +71 to +73
msg <- gsub("(\\{)", "\\1\\1", msg)
msg <- gsub("(\\})", "\\1\\1", msg)
msg <- cli::format_error(msg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as per r-lib/cli#735 (comment)

Suggested change
msg <- gsub("(\\{)", "\\1\\1", msg)
msg <- gsub("(\\})", "\\1\\1", msg)
msg <- cli::format_error(msg)
msg <- cli::format_error("{msg}")

rpart,
rsample,
tibble,
tidyr,
utils,
withr
Suggests:
AmesHousing,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm going to assume that this is leftover from a long time ago, and that we don't need it since we have modeldata

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants