Skip to content

Commit

Permalink
Merge pull request #1180 from tidymodels/loopify-depth
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilHvitfeldt authored Aug 2, 2023
2 parents 8aab612 + 1b5afd8 commit e912be2
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions R/depth.R
Original file line number Diff line number Diff line change
Expand Up @@ -176,27 +176,32 @@ get_depth <- function(tr_dat, new_dat, metric, opts) {

#' @export
bake.step_depth <- function(object, new_data, ...) {
if (ncol(object$data[[1]]) == 0) {
col_names <- colnames(object$data[[1]])
check_new_data(col_names, object, new_data)

if (length(col_names) == 0) {
return(new_data)
}

x_names <- colnames(object$data[[1]])
check_new_data(x_names, object, new_data)
x_data <- as.matrix(new_data[, col_names])

x_data <- as.matrix(new_data[, x_names])
res <- lapply(
object$data,
get_depth,
new_dat = x_data,
metric = object$metric,
opts = object$options
)
res <- as_tibble(res)
newname <- paste0(object$prefix, colnames(res))
res <- check_name(res, new_data, object, newname)
res <- vec_cbind(new_data, res)
res <- remove_original_cols(res, object, x_names)
res
res <- tibble::new_tibble(res)

new_names <- paste0(object$prefix, colnames(res))
colnames(res) <- new_names

res <- check_name(res, new_data, object, new_names)

new_data <- vctrs::vec_cbind(new_data, res)
new_data <- remove_original_cols(new_data, object, col_names)
new_data
}

print.step_depth <-
Expand Down

0 comments on commit e912be2

Please sign in to comment.