Skip to content

Commit 25fc2c6

Browse files
authored
improve error message for fit_xy() when y = NULL (#1064)
1 parent e0ea0be commit 25fc2c6

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

R/fit.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,9 @@ check_xy_interface <- function(x, y, cl, model) {
438438
if (df_interface) {
439439
return("data.frame")
440440
}
441+
442+
check_outcome(y, model)
443+
441444
rlang::abort("Error when checking the interface")
442445
}
443446

tests/testthat/_snaps/misc.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,15 @@
167167
! `linear_reg()` was unable to find an outcome.
168168
i Ensure that you have specified an outcome column and that it hasn't been removed in pre-processing.
169169

170+
---
171+
172+
Code
173+
fit_xy(reg_spec, data.frame(x = 1:5), y = NULL)
174+
Condition
175+
Error:
176+
! `linear_reg()` was unable to find an outcome.
177+
i Ensure that you have specified an outcome column and that it hasn't been removed in pre-processing.
178+
170179
---
171180

172181
Code

tests/testthat/test_misc.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ test_that('check_outcome works as expected', {
220220
fit(reg_spec, ~ mpg, mtcars)
221221
)
222222

223+
expect_snapshot(
224+
error = TRUE,
225+
fit_xy(reg_spec, data.frame(x = 1:5), y = NULL)
226+
)
227+
223228
class_spec <- logistic_reg()
224229

225230
expect_no_error(

0 commit comments

Comments
 (0)