@@ -156,7 +156,7 @@ fit_formula <- function(object, formula, data, engine = engine, .control, ...) {
156156 res
157157}
158158
159- fit_xy <- function (object , x , .control , ... ) {
159+ fit_xy <- function (object , x , y , .control , ... ) {
160160 opts <- quos(... )
161161
162162 # Look up the model's interface (e.g. formula, recipes, etc)
@@ -166,13 +166,15 @@ fit_xy <- function(object, x, .control, ...) {
166166 } else {
167167 if (object $ method $ interface %in% c(" data.frame" , " matrix" )) {
168168 fit_expr <- object $ method $ fit_call
169-
170- if (is_missing_arg(fit_expr [[" x" ]]))
171- fit_expr [[" x" ]] <- quote(x )
172- if (is_missing_arg(fit_expr [[" y" ]]))
173- fit_expr [[" y" ]] <- rlang :: get_expr(opts $ y )
174-
175- res <- eval_mod(fit_expr , capture = .control $ verbosity == 0 , catch = .control $ catch , env = get_env())
169+ fit_expr [[" x" ]] <- quote(x )
170+ fit_expr [[" y" ]] <- quote(y )
171+ res <-
172+ eval_mod(
173+ fit_expr ,
174+ capture = .control $ verbosity == 0 ,
175+ catch = .control $ catch ,
176+ env = current_enf()
177+ )
176178 } else {
177179 stop(" I don't know about the " ,
178180 object $ method $ interface , " interface." ,
@@ -182,7 +184,7 @@ fit_xy <- function(object, x, .control, ...) {
182184 res
183185}
184186
185- fit_recipe <- function (object , recipe , .control , ... ) {
187+ fit_recipe <- function (object , recipe , data , .control , ... ) {
186188 opts <- quos(... )
187189
188190 # Look up the model's interface (e.g. formula, recipes, etc)
@@ -255,7 +257,7 @@ formula_to_xy <- function(object, formula, data, .control) {
255257recipe_to_formula <- function (object , recipe , data , .control ) {
256258 # TODO case weights
257259 recipe <-
258- prep(recipe , training = eval_tidy( data [[ " data " ]]) , retain = TRUE )
260+ prep(recipe , training = data , retain = TRUE , verbose = .control $ verbosity > 1 )
259261 dat <- juice(recipe , all_predictors(), all_outcomes())
260262 dat <- as.data.frame(dat )
261263
@@ -272,14 +274,14 @@ recipe_to_formula <- function(object, recipe, data, .control) {
272274 fit_expr ,
273275 capture = .control $ verbosity == 0 ,
274276 catch = .control $ catch ,
275- env = get_env ()
277+ env = current_env ()
276278 )
277279}
278280
279281recipe_to_xy <- function (object , recipe , data , .control ) {
280282 # TODO case weights
281283 recipe <-
282- prep(recipe , training = eval_tidy( data [[ " data " ]]) , retain = TRUE )
284+ prep(recipe , training = data , retain = TRUE , verbose = .control $ verbosity > 1 )
283285
284286 x <- juice(recipe , all_predictors())
285287 x <- as.data.frame(x )
@@ -291,16 +293,14 @@ recipe_to_xy <- function(object, recipe, data, .control) {
291293
292294 fit_expr <- object $ method $ fit_call
293295
294- if (is_missing_arg(fit_expr [[" x" ]]))
295- fit_expr [[" x" ]] <- quote(x )
296- if (is_missing_arg(fit_expr [[" y" ]]))
297- fit_expr [[" y" ]] <- quote(y )
296+ fit_expr [[" x" ]] <- quote(x )
297+ fit_expr [[" y" ]] <- quote(y )
298298
299299 eval_mod(
300300 fit_expr ,
301301 capture = .control $ verbosity == 0 ,
302302 catch = .control $ catch ,
303- env = get_env ()
303+ env = current_env ()
304304 )
305305}
306306
@@ -309,11 +309,11 @@ recipe_to_xy <- function(object, recipe, data, .control) {
309309xy_to_formula <- function (object , x , y , .control ) {
310310 if (! is.data.frame(x ))
311311 x <- as.data.frame(x )
312- x $ .y <- eval_tidy( y [[ " y " ]])
312+ x $ .y <- y
313313 fit_expr <- object $ method $ fit_call
314314 fit_expr $ formula <- as.formula(.y ~ . )
315315 fit_expr $ data <- quote(x )
316- eval_tidy(fit_expr )
316+ eval_tidy(fit_expr , env = current_env() )
317317}
318318
319319xy_to_recipe <- function (object , x , y , .control ) {
@@ -389,7 +389,9 @@ check_interface <- function(formula, recipe, x, y, data, cl) {
389389 inher(formula , " formula" , cl )
390390 inher(recipe , " recipe" , cl )
391391 inher(x , c(" data.frame" , " matrix" ), cl )
392- inher(y , c(" data.frame" , " matrix" , " vector" ), cl )
392+ # `y` can be a vector (which is not a class)
393+ if (! is.null(y ) && ! is.vector(y ))
394+ inher(y , c(" data.frame" , " matrix" ), cl )
393395 inher(data , c(" data.frame" , " matrix" ), cl )
394396
395397 x_interface <- ! is.null(x ) & ! is.null(y )
0 commit comments