@@ -58,7 +58,7 @@ mode_filter_condition <- function(mode, user_specified_mode) {
5858# '
5959# ' The helpers `spec_is_possible()`, `spec_is_loaded()`, and
6060# ' `prompt_missing_implementation()` provide tooling for checking
61- # ' model specifications. In addition to the `cls `, `engine`, and `mode`
61+ # ' model specifications. In addition to the `spec `, `engine`, and `mode`
6262# ' arguments, the functions take arguments `user_specified_engine` and
6363# ' `user_specified_mode`, denoting whether the user themselves has
6464# ' specified the engine or mode, respectively.
@@ -91,9 +91,13 @@ mode_filter_condition <- function(mode, user_specified_mode) {
9191# ' @export
9292# ' @keywords internal
9393# ' @rdname add_on_exports
94- spec_is_possible <- function (cls ,
95- engine , user_specified_engine ,
96- mode , user_specified_mode ) {
94+ spec_is_possible <- function (spec ,
95+ engine = spec $ engine ,
96+ user_specified_engine = spec $ user_specified_engine ,
97+ mode = spec $ mode ,
98+ user_specified_mode = spec $ user_specified_mode ) {
99+ cls <- class(spec )[[1 ]]
100+
97101 all_model_info <-
98102 dplyr :: full_join(
99103 read_model_info_table(),
@@ -119,9 +123,13 @@ spec_is_possible <- function(cls,
119123# ' @export
120124# ' @keywords internal
121125# ' @rdname add_on_exports
122- spec_is_loaded <- function (cls ,
123- engine , user_specified_engine ,
124- mode , user_specified_mode ) {
126+ spec_is_loaded <- function (spec ,
127+ engine = spec $ engine ,
128+ user_specified_engine = spec $ user_specified_engine ,
129+ mode = spec $ mode ,
130+ user_specified_mode = spec $ user_specified_mode ) {
131+ cls <- class(spec )[[1 ]]
132+
125133 engine_condition <- engine_filter_condition(engine , user_specified_engine )
126134 mode_condition <- mode_filter_condition(mode , user_specified_mode )
127135
@@ -143,9 +151,7 @@ spec_is_loaded <- function(cls,
143151
144152is_printable_spec <- function (x ) {
145153 ! is.null(x $ method $ fit $ args ) &&
146- spec_is_loaded(class(x )[1 ],
147- x $ engine , x $ user_specified_engine ,
148- x $ mode , x $ user_specified_mode )
154+ spec_is_loaded(x )
149155}
150156
151157# construct a message informing the user that there are no
@@ -158,10 +164,14 @@ is_printable_spec <- function(x) {
158164# ' @export
159165# ' @keywords internal
160166# ' @rdname add_on_exports
161- prompt_missing_implementation <- function (cls ,
162- engine , user_specified_engine ,
163- mode , user_specified_mode ,
167+ prompt_missing_implementation <- function (spec ,
168+ engine = spec $ engine ,
169+ user_specified_engine = spec $ user_specified_engine ,
170+ mode = spec $ mode ,
171+ user_specified_mode = spec $ user_specified_mode ,
164172 prompt , ... ) {
173+ cls <- class(spec )[[1 ]]
174+
165175 engine_condition <- engine_filter_condition(engine , user_specified_engine )
166176 mode_condition <- mode_filter_condition(mode , user_specified_mode )
167177
@@ -303,18 +313,17 @@ new_model_spec <- function(cls, args, eng_args, mode, user_specified_mode = TRUE
303313 # determine if the model specification could feasibly match any entry
304314 # in the union of the parsnip model environment and model_info_table.
305315 # if not, trigger an error based on the (possibly inferred) model spec slots.
306- if (! spec_is_possible(cls ,
307- engine , user_specified_engine ,
308- mode , user_specified_mode )) {
309- check_spec_mode_engine_val(cls , engine , mode )
310- }
311-
312316 out <- list (
313317 args = args , eng_args = eng_args ,
314318 mode = mode , user_specified_mode = user_specified_mode , method = method ,
315319 engine = engine , user_specified_engine = user_specified_engine
316320 )
317321 class(out ) <- make_classes(cls )
322+
323+ if (! spec_is_possible(spec = out )) {
324+ check_spec_mode_engine_val(cls , engine , mode )
325+ }
326+
318327 out
319328}
320329
0 commit comments