Skip to content

Commit 2f886a3

Browse files
authored
return early when possible in spec checking (#931)
1 parent c874231 commit 2f886a3

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

R/aaa_models.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,16 @@ check_spec_mode_engine_val <- function(cls, eng, mode, call = caller_env()) {
220220

221221
model_info <- rlang::env_get(get_model_env(), cls)
222222

223+
# Initially, check if the specification is well-defined in the current model
224+
# parsnip model environment. If so, return early.
225+
# If not, troubleshoot more precisely and raise a relevant error.
226+
model_env_match <-
227+
vctrs::vec_slice(model_info, model_info$engine == eng & model_info$mode == mode)
228+
229+
if (vctrs::vec_size(model_env_match) == 1) {
230+
return(invisible(NULL))
231+
}
232+
223233
# Cases where the model definition is in parsnip but all of the engines
224234
# are contained in a different package
225235
model_info_parsnip_only <-

0 commit comments

Comments
 (0)