diff --git a/NEWS.md b/NEWS.md index b7f4641b7..b46487f17 100644 --- a/NEWS.md +++ b/NEWS.md @@ -47,6 +47,8 @@ * The quantile regression prediction type was disabled for the deprecated `surv_reg()` model. +* `NULL` is no longer accepted as an engine (#1242). + # parsnip 1.2.1 diff --git a/R/engines.R b/R/engines.R index fceea94eb..86e3ffd87 100644 --- a/R/engines.R +++ b/R/engines.R @@ -111,7 +111,7 @@ set_engine <- function(object, engine, ...) { set_engine.model_spec <- function(object, engine, ...) { mod_type <- class(object)[1] - if (rlang::is_missing(engine)) { + if (rlang::is_missing(engine) || is.null(engine)) { stop_missing_engine(mod_type, call = caller_env(0)) } object$engine <- engine diff --git a/man/details_linear_reg_glmer.Rd b/man/details_linear_reg_glmer.Rd index 67d8745bb..d4da1c9a4 100644 --- a/man/details_linear_reg_glmer.Rd +++ b/man/details_linear_reg_glmer.Rd @@ -52,7 +52,7 @@ linear predictor (\verb{\eta}) for a random intercept: \if{html}{\out{
}}\preformatted{\eta_\{i\} = (\beta_0 + b_\{0i\}) + \beta_1x_\{i1\} }\if{html}{\out{
}} -where $i$ denotes the \code{i}th independent experimental unit +where \code{i} denotes the \code{i}th independent experimental unit (e.g. subject). When the model has seen subject \code{i}, it can use that subject’s data to adjust the \emph{population} intercept to be more specific to that subjects results. diff --git a/man/details_linear_reg_lmer.Rd b/man/details_linear_reg_lmer.Rd index 0441f464a..4e4b5a34d 100644 --- a/man/details_linear_reg_lmer.Rd +++ b/man/details_linear_reg_lmer.Rd @@ -44,7 +44,7 @@ linear predictor (\verb{\eta}) for a random intercept: \if{html}{\out{
}}\preformatted{\eta_\{i\} = (\beta_0 + b_\{0i\}) + \beta_1x_\{i1\} }\if{html}{\out{
}} -where $i$ denotes the \code{i}th independent experimental unit +where \code{i} denotes the \code{i}th independent experimental unit (e.g. subject). When the model has seen subject \code{i}, it can use that subject’s data to adjust the \emph{population} intercept to be more specific to that subjects results. diff --git a/man/details_linear_reg_stan_glmer.Rd b/man/details_linear_reg_stan_glmer.Rd index 3bcb67ddf..78132f4bb 100644 --- a/man/details_linear_reg_stan_glmer.Rd +++ b/man/details_linear_reg_stan_glmer.Rd @@ -64,7 +64,7 @@ linear predictor (\verb{\eta}) for a random intercept: \if{html}{\out{
}}\preformatted{\eta_\{i\} = (\beta_0 + b_\{0i\}) + \beta_1x_\{i1\} }\if{html}{\out{
}} -where $i$ denotes the \code{i}th independent experimental unit +where \code{i} denotes the \code{i}th independent experimental unit (e.g. subject). When the model has seen subject \code{i}, it can use that subject’s data to adjust the \emph{population} intercept to be more specific to that subjects results. diff --git a/man/details_logistic_reg_glmer.Rd b/man/details_logistic_reg_glmer.Rd index b848df19c..a87a9e9c6 100644 --- a/man/details_logistic_reg_glmer.Rd +++ b/man/details_logistic_reg_glmer.Rd @@ -44,7 +44,7 @@ linear predictor (\verb{\eta}) for a random intercept: \if{html}{\out{
}}\preformatted{\eta_\{i\} = (\beta_0 + b_\{0i\}) + \beta_1x_\{i1\} }\if{html}{\out{
}} -where $i$ denotes the \code{i}th independent experimental unit +where \code{i} denotes the \code{i}th independent experimental unit (e.g. subject). When the model has seen subject \code{i}, it can use that subject’s data to adjust the \emph{population} intercept to be more specific to that subjects results. diff --git a/man/details_logistic_reg_stan_glmer.Rd b/man/details_logistic_reg_stan_glmer.Rd index ce1281501..628702e45 100644 --- a/man/details_logistic_reg_stan_glmer.Rd +++ b/man/details_logistic_reg_stan_glmer.Rd @@ -63,7 +63,7 @@ linear predictor (\verb{\eta}) for a random intercept: \if{html}{\out{
}}\preformatted{\eta_\{i\} = (\beta_0 + b_\{0i\}) + \beta_1x_\{i1\} }\if{html}{\out{
}} -where $i$ denotes the \code{i}th independent experimental unit +where \code{i} denotes the \code{i}th independent experimental unit (e.g. subject). When the model has seen subject \code{i}, it can use that subject’s data to adjust the \emph{population} intercept to be more specific to that subjects results. diff --git a/man/details_poisson_reg_glmer.Rd b/man/details_poisson_reg_glmer.Rd index 5a32c17bd..520798925 100644 --- a/man/details_poisson_reg_glmer.Rd +++ b/man/details_poisson_reg_glmer.Rd @@ -44,7 +44,7 @@ linear predictor (\verb{\eta}) for a random intercept: \if{html}{\out{
}}\preformatted{\eta_\{i\} = (\beta_0 + b_\{0i\}) + \beta_1x_\{i1\} }\if{html}{\out{
}} -where $i$ denotes the \code{i}th independent experimental unit +where \code{i} denotes the \code{i}th independent experimental unit (e.g. subject). When the model has seen subject \code{i}, it can use that subject’s data to adjust the \emph{population} intercept to be more specific to that subjects results. diff --git a/man/details_poisson_reg_stan_glmer.Rd b/man/details_poisson_reg_stan_glmer.Rd index ef1065ada..e34078846 100644 --- a/man/details_poisson_reg_stan_glmer.Rd +++ b/man/details_poisson_reg_stan_glmer.Rd @@ -63,7 +63,7 @@ linear predictor (\verb{\eta}) for a random intercept: \if{html}{\out{
}}\preformatted{\eta_\{i\} = (\beta_0 + b_\{0i\}) + \beta_1x_\{i1\} }\if{html}{\out{
}} -where $i$ denotes the \code{i}th independent experimental unit +where \code{i} denotes the \code{i}th independent experimental unit (e.g. subject). When the model has seen subject \code{i}, it can use that subject’s data to adjust the \emph{population} intercept to be more specific to that subjects results. diff --git a/man/parsnip-package.Rd b/man/parsnip-package.Rd index 84b9a622d..2e074dc3b 100644 --- a/man/parsnip-package.Rd +++ b/man/parsnip-package.Rd @@ -30,7 +30,7 @@ Authors: Other contributors: \itemize{ \item Emil Hvitfeldt \email{emil.hvitfeldt@posit.co} [contributor] - \item Posit Software, PBC [copyright holder, funder] + \item Posit Software, PBC (03wc8by49) [copyright holder, funder] } } diff --git a/tests/testthat/_snaps/engines.md b/tests/testthat/_snaps/engines.md new file mode 100644 index 000000000..dd1342c9c --- /dev/null +++ b/tests/testthat/_snaps/engines.md @@ -0,0 +1,8 @@ +# NULL engines + + Code + set_engine(nearest_neighbor(), NULL) + Condition + Error in `set_engine()`: + ! Missing engine. Possible mode/engine combinations are: classification {kknn} and regression {kknn}. + diff --git a/tests/testthat/_snaps/mlp_keras.md b/tests/testthat/_snaps/mlp_keras.md index bf9652e57..02479ada2 100644 --- a/tests/testthat/_snaps/mlp_keras.md +++ b/tests/testthat/_snaps/mlp_keras.md @@ -14,5 +14,4 @@ Class ~ A + B, data = modeldata::two_class_dat) Condition Error in `parsnip::keras_mlp()`: - ! `activation` should be one of: elu, exponential, gelu, hardsigmoid, linear, relu, selu, sigmoid, softmax, softplus, softsign, swish, and tanh, not "invalid". - + ! `activation` should be one of: elu, exponential, gelu, hard_sigmoid, linear, relu, selu, sigmoid, softmax, softplus, softsign, swish, and tanh, not "invalid". \ No newline at end of file diff --git a/tests/testthat/_snaps/rand_forest.md b/tests/testthat/_snaps/rand_forest.md index fc233adc6..7265dcc6a 100644 --- a/tests/testthat/_snaps/rand_forest.md +++ b/tests/testthat/_snaps/rand_forest.md @@ -19,8 +19,9 @@ Code res <- translate(rand_forest(mode = "classification") %>% set_engine(NULL)) - Message - Used `engine = 'ranger'` for translation. + Condition + Error in `set_engine()`: + ! Missing engine. Possible mode/engine combinations are: classification {ranger, randomForest, spark} and regression {ranger, randomForest, spark}. --- diff --git a/tests/testthat/_snaps/surv_reg.md b/tests/testthat/_snaps/surv_reg.md index 66039a420..9a2ae9610 100644 --- a/tests/testthat/_snaps/surv_reg.md +++ b/tests/testthat/_snaps/surv_reg.md @@ -32,8 +32,9 @@ Code res <- translate(surv_reg() %>% set_engine(NULL)) - Message - Used `engine = 'survival'` for translation. + Condition + Error in `set_engine()`: + ! Missing engine. Possible mode/engine combinations are: regression {flexsurv, survival}. # deprecation warning diff --git a/tests/testthat/_snaps/svm_linear.md b/tests/testthat/_snaps/svm_linear.md index 10f05e864..7edcaf122 100644 --- a/tests/testthat/_snaps/svm_linear.md +++ b/tests/testthat/_snaps/svm_linear.md @@ -20,8 +20,8 @@ Code translate(svm_linear(mode = "regression") %>% set_engine(NULL)) Condition - Error in `translate.default()`: - ! Please set an engine. + Error in `set_engine()`: + ! Missing engine. Possible mode/engine combinations are: classification {LiblineaR, kernlab} and regression {LiblineaR, kernlab}. --- diff --git a/tests/testthat/_snaps/svm_poly.md b/tests/testthat/_snaps/svm_poly.md index be1508036..b2430e8c2 100644 --- a/tests/testthat/_snaps/svm_poly.md +++ b/tests/testthat/_snaps/svm_poly.md @@ -28,6 +28,6 @@ Code svm_poly() %>% set_engine(NULL) %>% translate() Condition - Error in `translate.default()`: - ! Please set an engine. + Error in `set_engine()`: + ! Missing engine. Possible mode/engine combinations are: classification {kernlab} and regression {kernlab}. diff --git a/tests/testthat/_snaps/svm_rbf.md b/tests/testthat/_snaps/svm_rbf.md index d7649eb3b..6ad5c97ac 100644 --- a/tests/testthat/_snaps/svm_rbf.md +++ b/tests/testthat/_snaps/svm_rbf.md @@ -48,6 +48,6 @@ Code translate(svm_rbf(mode = "regression") %>% set_engine(NULL)) Condition - Error in `translate.default()`: - ! Please set an engine. + Error in `set_engine()`: + ! Missing engine. Possible mode/engine combinations are: classification {kernlab, liquidSVM} and regression {kernlab, liquidSVM}. diff --git a/tests/testthat/test-engines.R b/tests/testthat/test-engines.R new file mode 100644 index 000000000..68b612c52 --- /dev/null +++ b/tests/testthat/test-engines.R @@ -0,0 +1,8 @@ +test_that("NULL engines", { + # See issue https://github.com/tidymodels/parsnip/issues/1242 + + expect_snapshot( + set_engine(nearest_neighbor(), NULL), + error = TRUE + ) +}) diff --git a/tests/testthat/test-mlp_keras.R b/tests/testthat/test-mlp_keras.R index 8581a2530..2b7ba2cc3 100644 --- a/tests/testthat/test-mlp_keras.R +++ b/tests/testthat/test-mlp_keras.R @@ -252,6 +252,7 @@ test_that('all keras activation functions', { skip_on_cran() skip_if_not_installed("keras") skip_if_not_installed("modeldata") + skip_if_not_installed("dials", minimum_version = "1.3.0.9000") skip_if(!is_tf_ok()) act <- parsnip:::keras_activations() diff --git a/tests/testthat/test-rand_forest.R b/tests/testthat/test-rand_forest.R index 242b14cba..647b06908 100644 --- a/tests/testthat/test-rand_forest.R +++ b/tests/testthat/test-rand_forest.R @@ -8,7 +8,10 @@ test_that('updating', { }) test_that('bad input', { - expect_snapshot(res <- translate(rand_forest(mode = "classification") %>% set_engine(NULL))) + expect_snapshot(res <- + translate(rand_forest(mode = "classification") %>% + set_engine(NULL)), + error = TRUE) expect_snapshot(error = TRUE, rand_forest(mode = "time series")) expect_snapshot(error = TRUE, translate(rand_forest(mode = "classification") %>% set_engine("wat?"))) }) diff --git a/tests/testthat/test-surv_reg.R b/tests/testthat/test-surv_reg.R index 8a0d34582..366a8e898 100644 --- a/tests/testthat/test-surv_reg.R +++ b/tests/testthat/test-surv_reg.R @@ -13,7 +13,7 @@ test_that('bad input', { expect_snapshot(error = TRUE, surv_reg(mode = ", classification")) expect_snapshot(error = TRUE, translate(surv_reg() %>% set_engine("wat"))) - expect_snapshot(res <- translate(surv_reg() %>% set_engine(NULL))) + expect_snapshot(res <- translate(surv_reg() %>% set_engine(NULL)), error = TRUE) }) test_that("deprecation warning", {