Skip to content

Commit

Permalink
improve error message for fit_xy() when y = NULL (#1064)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpcouch authored Feb 12, 2024
1 parent e0ea0be commit 25fc2c6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions R/fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ check_xy_interface <- function(x, y, cl, model) {
if (df_interface) {
return("data.frame")
}

check_outcome(y, model)

rlang::abort("Error when checking the interface")
}

Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/_snaps/misc.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@
! `linear_reg()` was unable to find an outcome.
i Ensure that you have specified an outcome column and that it hasn't been removed in pre-processing.

---

Code
fit_xy(reg_spec, data.frame(x = 1:5), y = NULL)
Condition
Error:
! `linear_reg()` was unable to find an outcome.
i Ensure that you have specified an outcome column and that it hasn't been removed in pre-processing.

---

Code
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test_misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ test_that('check_outcome works as expected', {
fit(reg_spec, ~ mpg, mtcars)
)

expect_snapshot(
error = TRUE,
fit_xy(reg_spec, data.frame(x = 1:5), y = NULL)
)

class_spec <- logistic_reg()

expect_no_error(
Expand Down

0 comments on commit 25fc2c6

Please sign in to comment.