R/required_pkgs.R

Defines functions get_pkgs required_pkgs.cluster_fit required_pkgs.cluster_spec

# https://github.com/tidymodels/parsnip/blob/main/R/required_pkgs.R

required_pkgs.cluster_spec <- function(x, infra = TRUE, ...) {
  if (is.null(x$engine)) {
    rlang::abort("Please set an engine.")
  }
  get_pkgs(x, infra)
}

required_pkgs.cluster_fit <- function(x, infra = TRUE, ...) {
  get_pkgs(x$spec, infra)
}

get_pkgs <- function(x, infra) {
  cls <- class(x)[1]
  pkgs <-
    modelenv::get_from_env(paste0(cls, "_pkgs")) %>%
    dplyr::filter(engine == x$engine)
  res <- pkgs$pkg[[1]]
  if (length(res) == 0) {
    res <- character(0)
  }
  if (infra) {
    infra_pkgs <- c("tidyclust")
    res <- c(infra_pkgs, res)
  }
  res <- unique(res)
  res <- res[length(res) != 0]
  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.