From 5abcc9368a914faa4cb5eb5cd2d3182392a5bda0 Mon Sep 17 00:00:00 2001 From: Emil Hvitfeldt Date: Mon, 31 Jul 2023 13:34:55 -0700 Subject: [PATCH 1/2] loopify step_profile() --- R/profile.R | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/R/profile.R b/R/profile.R index 48e7f25c9..3203bcc0c 100644 --- a/R/profile.R +++ b/R/profile.R @@ -200,17 +200,24 @@ prep.step_profile <- function(x, training, info = NULL, ...) { #' @export bake.step_profile <- function(object, new_data, ...) { - n <- length(object$profile[[1]]) - new_data <- new_data[rep(1, n), ] - keepers <- c(names(object$columns), names(object$profile)) - # Keep the predictors in the same order - keepers <- names(new_data)[names(new_data) %in% keepers] - new_data <- dplyr::select(new_data, !!keepers) + col_names <- names(object$columns) + profile_names <- names(object$profile) + keepers <- c(col_names, profile_names) - for (i in names(object$columns)) { - new_data[[i]] <- rep(object$columns[[i]], n) + new_data <- list() + + for (col_name in col_names) { + new_data[[col_name]] <- object$columns[[col_name]] } + new_data[[names(object$profile)]] <- object$profile[[1]] + + new_data <- vctrs::vec_recycle_common(!!!new_data) + new_data <- tibble::new_tibble(new_data) + + # Keep the predictors in the same order + keepers <- names(new_data)[names(new_data) %in% keepers] + new_data <- dplyr::select(new_data, !!keepers) new_data } From 5e55cfc3b30490448cf418bdaa10016cb3396033 Mon Sep 17 00:00:00 2001 From: Emil Hvitfeldt Date: Tue, 1 Aug 2023 12:28:24 -0700 Subject: [PATCH 2/2] Update R/profile.R Co-authored-by: Simon P. Couch --- R/profile.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/profile.R b/R/profile.R index 3203bcc0c..c1e3be27c 100644 --- a/R/profile.R +++ b/R/profile.R @@ -217,7 +217,7 @@ bake.step_profile <- function(object, new_data, ...) { # Keep the predictors in the same order keepers <- names(new_data)[names(new_data) %in% keepers] - new_data <- dplyr::select(new_data, !!keepers) + new_data <- new_data[keepers] new_data }