Skip to content

Commit 073b856

Browse files
authored
export extension check helpers (#836)
1 parent 9e7a6ec commit 073b856

File tree

4 files changed

+118
-36
lines changed

4 files changed

+118
-36
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: parsnip
22
Title: A Common API to Modeling and Analysis Functions
3-
Version: 1.0.2.9002
3+
Version: 1.0.2.9003
44
Authors@R: c(
55
person("Max", "Kuhn", , "max@rstudio.com", role = c("aut", "cre")),
66
person("Davis", "Vaughan", , "davis@rstudio.com", role = "aut"),

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ export(predict_time)
250250
export(predict_time.model_fit)
251251
export(prepare_data)
252252
export(print_model_spec)
253+
export(prompt_missing_implementation)
253254
export(proportional_hazards)
254255
export(rand_forest)
255256
export(repair_call)
@@ -275,6 +276,8 @@ export(show_call)
275276
export(show_engines)
276277
export(show_fit)
277278
export(show_model_info)
279+
export(spec_is_loaded)
280+
export(spec_is_possible)
278281
export(stan_conf_int)
279282
export(surv_reg)
280283
export(survival_reg)

R/misc.R

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -54,39 +54,42 @@ mode_filter_condition <- function(mode, user_specified_mode) {
5454
rlang::quo(mode == !!mode)
5555
}
5656

57-
# Model Specification Checking:
58-
#
59-
# The helpers `spec_is_possible()`, `spec_is_loaded()`, and
60-
# `prompt_missing_implementation()` provide tooling for checking
61-
# model specifications. In addition to the `spec`, `engine`, and `mode`
62-
# arguments, the functions take arguments `user_specified_engine` and
63-
# `user_specified_mode`, denoting whether the user themselves has
64-
# specified the engine or mode, respectively.
65-
#
66-
# `spec_is_possible()` checks against the union of
67-
#
68-
# * the current parsnip model environment and
69-
# * the `model_info_table` of "pre-registered" model specifications
70-
#
71-
# to determine whether a model is well-specified. See
72-
# `parsnip:::read_model_info_table()` for this table.
73-
#
74-
# `spec_is_loaded()` checks only against the current parsnip model environment.
75-
#
76-
# `spec_is_possible()` is executed automatically on `new_model_spec()`,
77-
# `set_mode()`, and `set_engine()`, and `spec_is_loaded()` is executed
78-
# automatically in `print.model_spec()`, among other places. `spec_is_possible()`
79-
# should be used when a model specification is still "in progress" of being
80-
# specified, while `spec_is_loaded` should only be called when parsnip or an
81-
# extension receives some indication that the user is "done" specifying a model
82-
# specification: at print, fit, addition to a workflow, or `extract_*()`, for
83-
# example.
84-
#
85-
# When `spec_is_loaded()` is `FALSE`, the `prompt_missing_implementation()`
86-
# helper will construct an informative message to prompt users to load or
87-
# install needed packages. It's `prompt` argument refers to the prompting
88-
# function to use, usually [cli::cli_inform] or [cli::cli_abort], and the
89-
# ellipses are passed to that function.
57+
#' Model Specification Checking:
58+
#'
59+
#' The helpers `spec_is_possible()`, `spec_is_loaded()`, and
60+
#' `prompt_missing_implementation()` provide tooling for checking
61+
#' model specifications. In addition to the `spec`, `engine`, and `mode`
62+
#' arguments, the functions take arguments `user_specified_engine` and
63+
#' `user_specified_mode`, denoting whether the user themselves has
64+
#' specified the engine or mode, respectively.
65+
#'
66+
#' `spec_is_possible()` checks against the union of
67+
#'
68+
#' * the current parsnip model environment and
69+
#' * the `model_info_table` of "pre-registered" model specifications
70+
#'
71+
#' to determine whether a model is well-specified. See
72+
#' `parsnip:::read_model_info_table()` for this table.
73+
#'
74+
#' `spec_is_loaded()` checks only against the current parsnip model environment.
75+
#'
76+
#' `spec_is_possible()` is executed automatically on `new_model_spec()`,
77+
#' `set_mode()`, and `set_engine()`, and `spec_is_loaded()` is executed
78+
#' automatically in `print.model_spec()`, among other places. `spec_is_possible()`
79+
#' should be used when a model specification is still "in progress" of being
80+
#' specified, while `spec_is_loaded` should only be called when parsnip or an
81+
#' extension receives some indication that the user is "done" specifying a model
82+
#' specification: at print, fit, addition to a workflow, or `extract_*()`, for
83+
#' example.
84+
#'
85+
#' When `spec_is_loaded()` is `FALSE`, the `prompt_missing_implementation()`
86+
#' helper will construct an informative message to prompt users to load or
87+
#' install needed packages. It's `prompt` argument refers to the prompting
88+
#' function to use, usually [cli::cli_inform] or [cli::cli_abort], and the
89+
#' ellipses are passed to that function.
90+
#' @export
91+
#' @keywords internal
92+
#' @rdname extension-check-helpers
9093
spec_is_possible <- function(spec,
9194
engine = spec$engine,
9295
user_specified_engine = spec$user_specified_engine,
@@ -115,7 +118,10 @@ spec_is_possible <- function(spec,
115118
return(nrow(possibilities) > 0)
116119
}
117120

118-
# see notes above spec_is_possible for more information on usage
121+
# see ?add_on_exports for more information on usage
122+
#' @export
123+
#' @keywords internal
124+
#' @rdname extension-check-helpers
119125
spec_is_loaded <- function(spec,
120126
engine = spec$engine,
121127
user_specified_engine = spec$user_specified_engine,
@@ -153,7 +159,10 @@ is_printable_spec <- function(x) {
153159
# if there's a "pre-registered" extension supporting that setup,
154160
# nudge the user to install/load it.
155161
#
156-
# see notes above spec_is_possible for more information on usage
162+
# see ?add_on_exports for more information on usage
163+
#' @export
164+
#' @keywords internal
165+
#' @rdname extension-check-helpers
157166
prompt_missing_implementation <- function(spec,
158167
engine = spec$engine,
159168
user_specified_engine = spec$user_specified_engine,

man/extension-check-helpers.Rd

Lines changed: 70 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)