From f31a40a4bc4f54658f00dfbe6b305165fe642f3a Mon Sep 17 00:00:00 2001 From: Julia Silge Date: Mon, 7 Jun 2021 10:19:06 -0600 Subject: [PATCH 1/2] Fix augment bind_cols bug --- R/augment.R | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/R/augment.R b/R/augment.R index fa264f69e..4095a9ebf 100644 --- a/R/augment.R +++ b/R/augment.R @@ -56,34 +56,35 @@ #' augment(cls_xy, cls_tst[, -3]) #' augment.model_fit <- function(x, new_data, ...) { + ret <- new_data if (x$spec$mode == "regression") { check_spec_pred_type(x, "numeric") - new_data <- - new_data %>% + ret <- + ret %>% dplyr::bind_cols( predict(x, new_data = new_data) ) if (length(x$preproc$y_var) > 0) { y_nm <- x$preproc$y_var if (any(names(new_data) == y_nm)) { - new_data <- dplyr::mutate(new_data, .resid = !!rlang::sym(y_nm) - .pred) + ret <- dplyr::mutate(ret, .resid = !!rlang::sym(y_nm) - .pred) } } } else if (x$spec$mode == "classification") { if (spec_has_pred_type(x, "class")) { - new_data <- dplyr::bind_cols( - new_data, + ret <- dplyr::bind_cols( + ret, predict(x, new_data = new_data, type = "class") ) } if (spec_has_pred_type(x, "prob")) { - new_data <- dplyr::bind_cols( - new_data, + ret <- dplyr::bind_cols( + ret, predict(x, new_data = new_data, type = "prob") ) } } else { rlang::abort(paste("Unknown mode:", x$spec$mode)) } - as_tibble(new_data) + as_tibble(ret) } From 86a1c2608f3be10e2a4d97c0d806eb42b75f055c Mon Sep 17 00:00:00 2001 From: Julia Silge Date: Tue, 8 Jun 2021 09:27:40 -0600 Subject: [PATCH 2/2] Update NEWS --- NEWS.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 05a9d002f..95edff59a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,8 @@ * The helper functions `.convert_form_to_xy_fit()`, `.convert_form_to_xy_new()`, `.convert_xy_to_form_fit()`, and `.convert_xy_to_form_new()` for converting between formula and matrix interface are now exported for developer use (#508). +* Fix bug in `augment()` when non-predictor, non-outcome variables are included in data (#510). + # parsnip 0.1.6 ## Model Specification Changes @@ -19,7 +21,6 @@ * For xgboost, `mtry` and `colsample_bytree` can be passed as integer counts or proportions, while `subsample` and `validation` should always be proportions. `xgb_train()` now has a new option `counts` (`TRUE` or `FALSE`) that states which scale for `mtry` and `colsample_bytree` is being used. (#461) -r ## Other Changes * Re-licensed package from GPL-2 to MIT. See [consent from copyright holders here](https://github.com/tidymodels/parsnip/issues/462).