Skip to content

Commit dea8445

Browse files
authored
make more obvious what triggers which conversion (#846)
1 parent c2cb86d commit dea8445

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

R/predict.R

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -390,16 +390,14 @@ check_pred_type_dots <- function(object, type, ...) {
390390
#' @keywords internal
391391
#' @export
392392
prepare_data <- function(object, new_data) {
393-
fit_interface <- object$spec$method$fit$interface
394-
395-
pp_names <- names(object$preproc)
396-
if (any(pp_names == "terms") | any(pp_names == "x_var")) {
397-
# Translation code
398-
if (fit_interface == "formula") {
399-
new_data <- .convert_xy_to_form_new(object$preproc, new_data)
400-
} else {
401-
new_data <- .convert_form_to_xy_new(object$preproc, new_data)$x
402-
}
393+
preproc_names <- names(object$preproc)
394+
translate_from_formula_to_xy <- any(preproc_names == "terms", na.rm = TRUE)
395+
translate_from_xy_to_formula <- any(preproc_names == "x_var", na.rm = TRUE)
396+
397+
if (translate_from_formula_to_xy) {
398+
new_data <- .convert_form_to_xy_new(object$preproc, new_data)$x
399+
} else if (translate_from_xy_to_formula) {
400+
new_data <- .convert_xy_to_form_new(object$preproc, new_data)
403401
}
404402

405403
remove_intercept <-
@@ -410,6 +408,7 @@ prepare_data <- function(object, new_data) {
410408
new_data <- new_data %>% dplyr::select(-dplyr::one_of("(Intercept)"))
411409
}
412410

411+
fit_interface <- object$spec$method$fit$interface
413412
switch(
414413
fit_interface,
415414
none = new_data,

0 commit comments

Comments
 (0)