7
7
form_form <-
8
8
function (object , control , env , ... ) {
9
9
10
+ # prob rewrite this as simple subset/levels
11
+ y_levels <- levels_from_formula(env $ formula , env $ data )
12
+
10
13
if (object $ mode == " classification" ) {
11
- # prob rewrite this as simple subset/levels
12
- y_levels <- levels_from_formula(env $ formula , env $ data )
13
14
if (! inherits(env $ data , " tbl_spark" ) && is.null(y_levels ))
14
- rlang :: abort(" For classification models, the outcome should be a factor." )
15
- } else {
16
- y_levels <- NULL
15
+ rlang :: abort(" For a classification model, the outcome should be a factor." )
16
+ } else if (object $ mode == " regression" ) {
17
+ if (! inherits(env $ data , " tbl_spark" ) && ! is.null(y_levels ))
18
+ rlang :: abort(" For a regression model, the outcome should be numeric." )
17
19
}
18
20
19
21
object <- check_mode(object , y_levels )
@@ -57,11 +59,7 @@ xy_xy <- function(object, env, control, target = "none", ...) {
57
59
rlang :: abort(" spark objects can only be used with the formula interface to `fit()`" )
58
60
59
61
object <- check_mode(object , levels(env $ y ))
60
-
61
- if (object $ mode == " classification" ) {
62
- if (is.null(levels(env $ y )))
63
- rlang :: abort(" For classification models, the outcome should be a factor." )
64
- }
62
+ check_outcome(env $ y , object )
65
63
66
64
encoding_info <-
67
65
get_encoding(class(object )[1 ]) %> %
@@ -133,7 +131,10 @@ form_xy <- function(object, control, env,
133
131
res <- list (lvl = levels_from_formula(env $ formula , env $ data ), spec = object )
134
132
if (object $ mode == " classification" ) {
135
133
if (is.null(res $ lvl ))
136
- rlang :: abort(" For classification models, the outcome should be a factor." )
134
+ rlang :: abort(" For a classification model, the outcome should be a factor." )
135
+ } else if (object $ mode == " regression" ) {
136
+ if (! is.null(res $ lvl ))
137
+ rlang :: abort(" For a regression model, the outcome should be numeric." )
137
138
}
138
139
139
140
res <- xy_xy(
@@ -153,10 +154,7 @@ form_xy <- function(object, control, env,
153
154
154
155
xy_form <- function (object , env , control , ... ) {
155
156
156
- if (object $ mode == " classification" ) {
157
- if (is.null(levels(env $ y )))
158
- rlang :: abort(" For classification models, the outcome should be a factor." )
159
- }
157
+ check_outcome(env $ y , object )
160
158
161
159
encoding_info <-
162
160
get_encoding(class(object )[1 ]) %> %
0 commit comments