@@ -226,18 +226,17 @@ formula_to_matrix <- function(object, formula, data, control, ...) {
226226
227227# ' @importFrom recipes prep juice all_predictors all_outcomes
228228
229- recipe_data <- function (recipe , data , control , output = " matrix" , combine = FALSE ) {
229+ # add case weights as extra object returned (out$weights)
230+ recipe_data <- function (recipe , data , object , control , output = " matrix" , combine = FALSE ) {
230231 recipe <-
231232 prep(recipe , training = data , retain = TRUE , verbose = control $ verbosity > 1 )
232233
233234 if (combine ) {
234- out <- list (data = juice(recipe , all_predictors(), all_outcomes(), composition = output ))
235- data_info <- summary(recipe )
236- y_names <- data_info $ variable [data_info $ role == " outcome" ]
237- if (length(y_names ) > 1 )
238- out $ form <- paste0(" cbind(" , paste0(y_names , collapse = " ," ), " )~." )
239- else
240- out $ form <- paste0(y_names , " ~." )
235+ out <- list (
236+ data = juice(recipe , composition = output ),
237+ form = formula(object , (recipe ))
238+ )
239+
241240 } else {
242241 out <-
243242 list (
@@ -257,16 +256,16 @@ recipe_data <- function(recipe, data, control, output = "matrix", combine = FALS
257256
258257recipe_to_formula <-
259258 function (object , recipe , data , control , ... ) {
260- info <- recipe_data(recipe , data , control , output = " tibble" , combine = TRUE )
259+ info <- recipe_data(recipe , data , object , control , output = " tibble" , combine = TRUE )
261260 formula_to_formula(object , info $ form , info $ data , control , ... )
262261 }
263262
264263recipe_to_data.frame <- function (object , recipe , data , control , ... ) {
265- info <- recipe_data(recipe , data , control , output = " tibble" , combine = FALSE )
264+ info <- recipe_data(recipe , data , object , control , output = " tibble" , combine = FALSE )
266265 xy_to_xy(object , info $ x , info $ y , control , ... )
267266}
268267
269268recipe_to_matrix <- function (object , recipe , data , control , ... ) {
270- info <- recipe_data(recipe , data , control , output = " matrix" , combine = FALSE )
269+ info <- recipe_data(recipe , data , object , control , output = " matrix" , combine = FALSE )
271270 xy_to_xy(object , info $ x , info $ y , control , ... )
272271}
0 commit comments