R/predict_raw.R

Defines functions predict_raw.cluster_fit

Documented in predict_raw.cluster_fit

#' @rdname predict.cluster_fit
#' @method predict_raw cluster_fit
#' @export predict_raw.cluster_fit
#' @export
predict_raw.cluster_fit <- function(object, new_data, opts = list(), ...) {
  protected_args <- names(object$spec$method$pred$raw$args)
  dup_args <- names(opts) %in% protected_args
  if (any(dup_args)) {
    opts <- opts[[!dup_args]]
  }
  if (length(opts) > 0) {
    object$spec$method$pred$raw$args <-
      c(object$spec$method$pred$raw$args, opts)
  }

  check_spec_pred_type(object, "raw")

  if (inherits(object$fit, "try-error")) {
    rlang::warn("Cluster fit failed; cannot make predictions.")
    return(NULL)
  }

  new_data <- prepare_data(object, new_data)

  # preprocess data
  if (!is.null(object$spec$method$pred$raw$pre)) {
    new_data <- object$spec$method$pred$raw$pre(new_data, object)
  }

  # create prediction call
  pred_call <- make_pred_call(object$spec$method$pred$raw)

  res <- rlang::eval_tidy(pred_call)
  res
}

Try the tidyclust package in your browser

Any scripts or data that you put into this service are public.

tidyclust documentation built on Sept. 26, 2023, 1:08 a.m.