Skip to content

move method for tune_args() from tune to here #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Depends:
Imports:
cli (>= 2.0.0),
ellipsis (>= 0.2.0),
generics (>= 0.1.0),
generics (>= 0.1.0.9000),
glue,
hardhat (>= 0.1.6),
lifecycle (>= 1.0.0),
Expand Down
16 changes: 16 additions & 0 deletions R/generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,19 @@ required_pkgs.workflow <- function(x, infra = TRUE, ...) {
out <- unique(out)
out
}

# Lazily registered in .onLoad()
tune_args_workflow <- function(object, ...) {
model <- extract_spec_parsnip(object)

param_data <- generics::tune_args(model)

if (has_preprocessor_recipe(object)) {
recipe <- extract_preprocessor(object)
recipe_param_data <- generics::tune_args(recipe)
param_data <- vctrs::vec_rbind(param_data, recipe_param_data)
}

param_data
}

1 change: 0 additions & 1 deletion R/reexports.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ hardhat::extract_mold
#' @importFrom hardhat extract_preprocessor
#' @export
hardhat::extract_preprocessor
#'
12 changes: 12 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
vctrs::s3_register("butcher::axe_fitted", "workflow")

vctrs::s3_register("generics::required_pkgs", "workflow")

# - If tune isn't installed, register the method (`packageVersion()` will error here)
# - If tune >= 0.1.6.9001 is installed, register the method
should_register_tune_args_method <- tryCatch(
expr = utils::packageVersion("tune") >= "0.1.6.9001",
error = function(cnd) TRUE
)

if (should_register_tune_args_method) {
# `tune_args.workflow()` moved from tune to workflows
vctrs::s3_register("generics::tune_args", "workflow", tune_args_workflow)
}
}

# nocov end