Skip to content

export extension check helpers #836

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 1 commit into from
Nov 3, 2022
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
@@ -1,6 +1,6 @@
Package: parsnip
Title: A Common API to Modeling and Analysis Functions
Version: 1.0.2.9002
Version: 1.0.2.9003
Authors@R: c(
person("Max", "Kuhn", , "max@rstudio.com", role = c("aut", "cre")),
person("Davis", "Vaughan", , "davis@rstudio.com", role = "aut"),
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ export(predict_time)
export(predict_time.model_fit)
export(prepare_data)
export(print_model_spec)
export(prompt_missing_implementation)
export(proportional_hazards)
export(rand_forest)
export(repair_call)
Expand All @@ -275,6 +276,8 @@ export(show_call)
export(show_engines)
export(show_fit)
export(show_model_info)
export(spec_is_loaded)
export(spec_is_possible)
export(stan_conf_int)
export(surv_reg)
export(survival_reg)
Expand Down
79 changes: 44 additions & 35 deletions R/misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,39 +54,42 @@ mode_filter_condition <- function(mode, user_specified_mode) {
rlang::quo(mode == !!mode)
}

# Model Specification Checking:
#
# The helpers `spec_is_possible()`, `spec_is_loaded()`, and
# `prompt_missing_implementation()` provide tooling for checking
# model specifications. In addition to the `spec`, `engine`, and `mode`
# arguments, the functions take arguments `user_specified_engine` and
# `user_specified_mode`, denoting whether the user themselves has
# specified the engine or mode, respectively.
#
# `spec_is_possible()` checks against the union of
#
# * the current parsnip model environment and
# * the `model_info_table` of "pre-registered" model specifications
#
# to determine whether a model is well-specified. See
# `parsnip:::read_model_info_table()` for this table.
#
# `spec_is_loaded()` checks only against the current parsnip model environment.
#
# `spec_is_possible()` is executed automatically on `new_model_spec()`,
# `set_mode()`, and `set_engine()`, and `spec_is_loaded()` is executed
# automatically in `print.model_spec()`, among other places. `spec_is_possible()`
# should be used when a model specification is still "in progress" of being
# specified, while `spec_is_loaded` should only be called when parsnip or an
# extension receives some indication that the user is "done" specifying a model
# specification: at print, fit, addition to a workflow, or `extract_*()`, for
# example.
#
# When `spec_is_loaded()` is `FALSE`, the `prompt_missing_implementation()`
# helper will construct an informative message to prompt users to load or
# install needed packages. It's `prompt` argument refers to the prompting
# function to use, usually [cli::cli_inform] or [cli::cli_abort], and the
# ellipses are passed to that function.
#' Model Specification Checking:
#'
#' The helpers `spec_is_possible()`, `spec_is_loaded()`, and
#' `prompt_missing_implementation()` provide tooling for checking
#' model specifications. In addition to the `spec`, `engine`, and `mode`
#' arguments, the functions take arguments `user_specified_engine` and
#' `user_specified_mode`, denoting whether the user themselves has
#' specified the engine or mode, respectively.
#'
#' `spec_is_possible()` checks against the union of
#'
#' * the current parsnip model environment and
#' * the `model_info_table` of "pre-registered" model specifications
#'
#' to determine whether a model is well-specified. See
#' `parsnip:::read_model_info_table()` for this table.
#'
#' `spec_is_loaded()` checks only against the current parsnip model environment.
#'
#' `spec_is_possible()` is executed automatically on `new_model_spec()`,
#' `set_mode()`, and `set_engine()`, and `spec_is_loaded()` is executed
#' automatically in `print.model_spec()`, among other places. `spec_is_possible()`
#' should be used when a model specification is still "in progress" of being
#' specified, while `spec_is_loaded` should only be called when parsnip or an
#' extension receives some indication that the user is "done" specifying a model
#' specification: at print, fit, addition to a workflow, or `extract_*()`, for
#' example.
#'
#' When `spec_is_loaded()` is `FALSE`, the `prompt_missing_implementation()`
#' helper will construct an informative message to prompt users to load or
#' install needed packages. It's `prompt` argument refers to the prompting
#' function to use, usually [cli::cli_inform] or [cli::cli_abort], and the
#' ellipses are passed to that function.
#' @export
#' @keywords internal
#' @rdname extension-check-helpers
spec_is_possible <- function(spec,
engine = spec$engine,
user_specified_engine = spec$user_specified_engine,
Expand Down Expand Up @@ -115,7 +118,10 @@ spec_is_possible <- function(spec,
return(nrow(possibilities) > 0)
}

# see notes above spec_is_possible for more information on usage
# see ?add_on_exports for more information on usage
#' @export
#' @keywords internal
#' @rdname extension-check-helpers
spec_is_loaded <- function(spec,
engine = spec$engine,
user_specified_engine = spec$user_specified_engine,
Expand Down Expand Up @@ -153,7 +159,10 @@ is_printable_spec <- function(x) {
# if there's a "pre-registered" extension supporting that setup,
# nudge the user to install/load it.
#
# see notes above spec_is_possible for more information on usage
# see ?add_on_exports for more information on usage
#' @export
#' @keywords internal
#' @rdname extension-check-helpers
prompt_missing_implementation <- function(spec,
engine = spec$engine,
user_specified_engine = spec$user_specified_engine,
Expand Down
70 changes: 70 additions & 0 deletions man/extension-check-helpers.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.