diff --git a/DESCRIPTION b/DESCRIPTION index a66e5701..f67af709 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -63,6 +63,7 @@ Suggests: tibble, tidyr, tune, + withr, workflows, workflowsets, xgboost, diff --git a/README.Rmd b/README.Rmd index 687f0558..f8bbf23b 100644 --- a/README.Rmd +++ b/README.Rmd @@ -30,3 +30,33 @@ knitr::opts_chunk$set( * Whose run-time is not practical for individual packages. These tests are run on a cron job and are run for both CRAN versions and the current GitHub development versions. + + +## PR-pairs with package repos + +PRs on extratests typically are part of a PR pair since they test changes in package repositories. The following workflow ensures that the CI run triggered by the PR on extratests runs with the changes in the corresponding PR on the package repository. + +Normal development + +* [pkg repo] Make changes +* [extratests repo] Write tests + +Set version for the change + +* [pkg repo] Give it new dev version number in DESCRIPTION, e.g. `1.1.0.9001` instead of `1.1.0.9000` +* [extratests repo] Add `skip_if_not_installed()` to the tests with that dev version number as `minimum_version`. + +Open PRs and point GHA to the changes + +* [pkg repo] Make a PR +* [extratests repo] in `GH-R-CMD-check.yaml`, point GHA to the pkg PR by appending `#`, e.g. `try(pak::pkg_install("tidymodels/parsnip#991"))` + * Without pointing GHA to that branch, the tests will be skipped based on the version number. + * If the branch information is added to the DESCRIPTION via `Remotes:` instead, the "CRAN workflow" will also run the dev version. +* [extratests repo] Make a PR, link it to the pkg-PR in the PR description +* [extratests repo] Make a review comment to change remote back to main before merging + +Clean-up and merge (after PR review and approval) + +* [pkg repo] Merge PR +* [extratests repo] Point remote back to main +* [extratests repo] Merge PR diff --git a/README.md b/README.md index 0e4b6c53..977f28eb 100644 --- a/README.md +++ b/README.md @@ -15,11 +15,51 @@ Spark](https://github.com/tidymodels/extratests/workflows/spark-R-CMD-check/badg `extratests` is an internal package used for tests that - - Depend on multiple tidymodels packages +- Depend on multiple tidymodels packages - - Involve special/extra packages. +- Involve special/extra packages. - - Whose run-time is not practical for individual packages. +- Whose run-time is not practical for individual packages. These tests are run on a cron job and are run for both CRAN versions and the current GitHub development versions. + +## PR-pairs with package repos + +PRs on extratests typically are part of a PR pair since they test +changes in package repositories. The following workflow ensures that the +CI run triggered by the PR on extratests runs with the changes in the +corresponding PR on the package repository. + +Normal development + +- \[pkg repo\] Make changes +- \[extratests repo\] Write tests + +Set version for the change + +- \[pkg repo\] Give it new dev version number in DESCRIPTION, + e.g. `1.1.0.9001` instead of `1.1.0.9000` +- \[extratests repo\] Add `skip_if_not_installed()` to the tests with + that dev version number as `minimum_version`. + +Open PRs and point GHA to the changes + +- \[pkg repo\] Make a PR +- \[extratests repo\] in `GH-R-CMD-check.yaml`, point GHA to the pkg PR + by appending `#`, + e.g. `try(pak::pkg_install("tidymodels/parsnip#991"))` + - Without pointing GHA to that branch, the tests will be skipped based + on the version number. + - If the branch information is added to the DESCRIPTION via `Remotes:` + instead, the “CRAN workflow” will also run the dev version. +- \[extratests repo\] Make a PR, link it to the pkg-PR in the PR + description +- \[extratests repo\] Make a review comment to change remote back to + main before merging + +Clean-up and merge (after PR review and approval) + +- \[pkg repo\] Merge PR +- \[extratests repo\] Point remote back to main +- \[extratests repo\] Merge PR diff --git a/tests/testthat/_snaps/glmnet-linear.md b/tests/testthat/_snaps/glmnet-linear.md index 1a8e51df..93711d85 100644 --- a/tests/testthat/_snaps/glmnet-linear.md +++ b/tests/testthat/_snaps/glmnet-linear.md @@ -3,15 +3,17 @@ Code linear_reg(penalty = 0.01) %>% set_engine("glmnet") %>% fit(mpg ~ ., data = mtcars[ -(1:4), ]) %>% predict(mtcars[-(1:4), ], penalty = 0:1) - Error - `penalty` should be a single numeric value. `multi_predict()` can be used to get multiple predictions per row of data. + Condition + Error in `.check_glmnet_penalty_predict()`: + ! `penalty` should be a single numeric value. `multi_predict()` can be used to get multiple predictions per row of data. --- Code linear_reg() %>% set_engine("glmnet") %>% fit(mpg ~ ., data = mtcars[-(1:4), ]) - Error - For the glmnet engine, `penalty` must be a single number (or a value of `tune()`). + Condition + Error in `.check_glmnet_penalty_fit()`: + ! For the glmnet engine, `penalty` must be a single number (or a value of `tune()`). * There are 0 values for `penalty`. * To try multiple values for total regularization, use the tune package. * To predict multiple penalties, use `multi_predict()` @@ -21,6 +23,7 @@ Code linear_reg(penalty = 0.01) %>% set_engine("glmnet") %>% fit(mpg ~ ., data = mtcars) %>% multi_predict(mtcars, type = "class") - Error - For class predictions, the object should be a classification model. + Condition + Error in `check_pred_type()`: + ! For class predictions, the object should be a classification model. diff --git a/tests/testthat/_snaps/glmnet-logistic.md b/tests/testthat/_snaps/glmnet-logistic.md index 4ad1f02c..3f61094e 100644 --- a/tests/testthat/_snaps/glmnet-logistic.md +++ b/tests/testthat/_snaps/glmnet-logistic.md @@ -2,8 +2,9 @@ Code multi_predict(class_fit, newdata = wa_churn[1:4, vars], type = "prob") - Error - Please use `new_data` instead of `newdata`. + Condition + Error in `multi_predict()`: + ! Please use `new_data` instead of `newdata`. # error traps @@ -11,16 +12,18 @@ logistic_reg(penalty = 0.01) %>% set_engine("glmnet") %>% fit(Class ~ log( funded_amnt) + int_rate + term, data = lending_club) %>% predict(lending_club, penalty = 0:1) - Error - `penalty` should be a single numeric value. `multi_predict()` can be used to get multiple predictions per row of data. + Condition + Error in `.check_glmnet_penalty_predict()`: + ! `penalty` should be a single numeric value. `multi_predict()` can be used to get multiple predictions per row of data. --- Code logistic_reg() %>% set_engine("glmnet") %>% fit(Class ~ log(funded_amnt) + int_rate + term, data = lending_club) - Error - For the glmnet engine, `penalty` must be a single number (or a value of `tune()`). + Condition + Error in `.check_glmnet_penalty_fit()`: + ! For the glmnet engine, `penalty` must be a single number (or a value of `tune()`). * There are 0 values for `penalty`. * To try multiple values for total regularization, use the tune package. * To predict multiple penalties, use `multi_predict()` @@ -31,6 +34,7 @@ logistic_reg(penalty = 0.01) %>% set_engine("glmnet") %>% fit(Class ~ log( funded_amnt) + int_rate + term, data = lending_club) %>% multi_predict( lending_club, type = "time") - Error - For event time predictions, the object should be a censored regression. + Condition + Error in `check_pred_type()`: + ! For event time predictions, the object should be a censored regression. diff --git a/tests/testthat/_snaps/glmnet-multinom.md b/tests/testthat/_snaps/glmnet-multinom.md index df2d93b5..f4baadd6 100644 --- a/tests/testthat/_snaps/glmnet-multinom.md +++ b/tests/testthat/_snaps/glmnet-multinom.md @@ -2,23 +2,26 @@ Code multi_predict(xy_fit, newdata = hpc[rows, 1:4], penalty = c(0.1, 0.5)) - Error - Please use `new_data` instead of `newdata`. + Condition + Error in `multi_predict()`: + ! Please use `new_data` instead of `newdata`. # error traps Code multinom_reg(penalty = 0.01) %>% set_engine("glmnet") %>% fit(class ~ ., data = hpc_data) %>% predict(hpc_data, penalty = 0:1) - Error - `penalty` should be a single numeric value. `multi_predict()` can be used to get multiple predictions per row of data. + Condition + Error in `.check_glmnet_penalty_predict()`: + ! `penalty` should be a single numeric value. `multi_predict()` can be used to get multiple predictions per row of data. --- Code multinom_reg() %>% set_engine("glmnet") %>% fit(class ~ ., data = hpc_data) - Error - For the glmnet engine, `penalty` must be a single number (or a value of `tune()`). + Condition + Error in `.check_glmnet_penalty_fit()`: + ! For the glmnet engine, `penalty` must be a single number (or a value of `tune()`). * There are 0 values for `penalty`. * To try multiple values for total regularization, use the tune package. * To predict multiple penalties, use `multi_predict()` @@ -28,6 +31,7 @@ Code multinom_reg(penalty = 0.01) %>% set_engine("glmnet") %>% fit(class ~ ., data = hpc_data) %>% multi_predict(hpc_data, type = "numeric") - Error - For numeric predictions, the object should be a regression model. + Condition + Error in `check_pred_type()`: + ! For numeric predictions, the object should be a regression model. diff --git a/tests/testthat/_snaps/glmnet-poisson.md b/tests/testthat/_snaps/glmnet-poisson.md index 0ace70a6..a5054357 100644 --- a/tests/testthat/_snaps/glmnet-poisson.md +++ b/tests/testthat/_snaps/glmnet-poisson.md @@ -1,18 +1,20 @@ -# error traps - - Code - poisson_reg(penalty = 0.1) %>% set_engine("glmnet") %>% fit(mpg ~ ., data = mtcars[ - -(1:4), ]) %>% predict(mtcars[-(1:4), ], penalty = 0:1) - Error - `penalty` should be a single numeric value. `multi_predict()` can be used to get multiple predictions per row of data. - ---- +# model errors on missing penalty value Code poisson_reg() %>% set_engine("glmnet") %>% fit(mpg ~ ., data = mtcars[-(1:4), ]) - Error - For the glmnet engine, `penalty` must be a single number (or a value of `tune()`). + Condition + Error in `.check_glmnet_penalty_fit()`: + ! For the glmnet engine, `penalty` must be a single number (or a value of `tune()`). * There are 0 values for `penalty`. * To try multiple values for total regularization, use the tune package. * To predict multiple penalties, use `multi_predict()` +# predict() errors with multiple penalty values + + Code + poisson_reg(penalty = 0.1) %>% set_engine("glmnet") %>% fit(mpg ~ ., data = mtcars[ + -(1:4), ]) %>% predict(mtcars[-(1:4), ], penalty = 0:1) + Condition + Error in `.check_glmnet_penalty_predict()`: + ! `penalty` should be a single numeric value. `multi_predict()` can be used to get multiple predictions per row of data. + diff --git a/tests/testthat/_snaps/parsnip-extension-messaging.md b/tests/testthat/_snaps/parsnip-extension-messaging.md index 13cca5b9..62b0ab33 100644 --- a/tests/testthat/_snaps/parsnip-extension-messaging.md +++ b/tests/testthat/_snaps/parsnip-extension-messaging.md @@ -2,7 +2,7 @@ Code bag_tree() %>% set_engine("rpart") %>% set_mode("regression") - Message + Message ! parsnip could not locate an implementation for `bag_tree` regression model specifications using the `rpart` engine. i The parsnip extension package baguette implements support for this specification. i Please install (if needed) and load to continue. @@ -20,7 +20,7 @@ Code bag_tree() %>% set_mode("censored regression") - Message + Message ! parsnip could not locate an implementation for `bag_tree` censored regression model specifications. i The parsnip extension package censored implements support for this specification. i Please install (if needed) and load to continue. @@ -38,7 +38,7 @@ Code bag_tree() - Message + Message ! parsnip could not locate an implementation for `bag_tree` model specifications. i The parsnip extension packages censored and baguette implement support for this specification. i Please install (if needed) and load to continue. @@ -56,7 +56,7 @@ Code bag_tree() %>% set_engine("rpart") - Message + Message ! parsnip could not locate an implementation for `bag_tree` model specifications using the `rpart` engine. i The parsnip extension packages censored and baguette implement support for this specification. i Please install (if needed) and load to continue. @@ -102,7 +102,7 @@ Code bag_tree() %>% set_mode("regression") %>% set_engine("rpart") - Message + Message ! parsnip could not locate an implementation for `bag_tree` regression model specifications using the `rpart` engine. i The parsnip extension package baguette implements support for this specification. i Please install (if needed) and load to continue. @@ -120,7 +120,7 @@ Code bag_tree() %>% set_mode("classification") %>% set_engine("C5.0") - Message + Message ! parsnip could not locate an implementation for `bag_tree` classification model specifications using the `C5.0` engine. i The parsnip extension package baguette implements support for this specification. i Please install (if needed) and load to continue. @@ -182,7 +182,7 @@ Code decision_tree() %>% set_engine("partykit") %>% set_mode("regression") - Message + Message ! parsnip could not locate an implementation for `decision_tree` regression model specifications using the `partykit` engine. i The parsnip extension package bonsai implements support for this specification. i Please install (if needed) and load to continue. @@ -216,7 +216,7 @@ Code decision_tree() %>% set_mode("regression") %>% set_engine("partykit") - Message + Message ! parsnip could not locate an implementation for `decision_tree` regression model specifications using the `partykit` engine. i The parsnip extension package bonsai implements support for this specification. i Please install (if needed) and load to continue. diff --git a/tests/testthat/_snaps/parsnip-model-formula.md b/tests/testthat/_snaps/parsnip-model-formula.md new file mode 100644 index 00000000..9b9367f8 --- /dev/null +++ b/tests/testthat/_snaps/parsnip-model-formula.md @@ -0,0 +1,31 @@ +# error without model formula (workflow, no tune) + + Code + gam_fit <- gam_wflow %>% fit(mtcars) + Condition + Error: + ! When working with generalized additive models, please supply the model specification to `workflows::add_model()` along with a `formula` argument. + i See `?parsnip::model_formula()` to learn more. + +# error without model formula (workflow, with tune) + + Code + show_notes(gam_res) + Output + unique notes: + -------------------------------------------------------------------------------- + Error: + ! When working with generalized additive models, please supply the model specification to `workflows::add_model()` along with a `formula` argument. + i See `?parsnip::model_formula()` to learn more. + +# error without model formula (no workflow, with tune) + + Code + show_notes(gam_res) + Output + unique notes: + -------------------------------------------------------------------------------- + Error: + ! When working with generalized additive models, please supply the model specification to `workflows::add_model()` along with a `formula` argument. + i See `?parsnip::model_formula()` to learn more. + diff --git a/tests/testthat/_snaps/parsnip-survival-censoring-model.md b/tests/testthat/_snaps/parsnip-survival-censoring-model.md index 5b4e7500..0572e047 100644 --- a/tests/testthat/_snaps/parsnip-survival-censoring-model.md +++ b/tests/testthat/_snaps/parsnip-survival-censoring-model.md @@ -9,6 +9,7 @@ Code predict(alt_obj, time = 100) - Error - Don't know how to predict with a censoring model of type: reverse_km + Condition + Error in `predict()`: + ! Don't know how to predict with a censoring model of type: reverse_km diff --git a/tests/testthat/_snaps/parsnip-survival-censoring-weights.md b/tests/testthat/_snaps/parsnip-survival-censoring-weights.md index 7a94ac33..3e71cbb1 100644 --- a/tests/testthat/_snaps/parsnip-survival-censoring-weights.md +++ b/tests/testthat/_snaps/parsnip-survival-censoring-weights.md @@ -2,22 +2,25 @@ Code .censoring_weights_graf("nothing useful") - Error - There is no `.censoring_weights_graf()` method for objects with class(es): 'character' + Condition + Error in `.censoring_weights_graf()`: + ! There is no `.censoring_weights_graf()` method for objects with class(es): 'character' --- Code .censoring_weights_graf(workflows::workflow()) - Error - The workflow does not have a model fit object. + Condition + Error in `.censoring_weights_graf()`: + ! The workflow does not have a model fit object. --- Code .censoring_weights_graf(cox_model, lung) - Error - There should be a single column of class `Surv` + Condition + Error: + ! There should be a single column of class `Surv` --- @@ -25,21 +28,24 @@ lung_left <- lung[1, , drop = FALSE] lung_left$surv <- Surv(10, 0, type = "left") .censoring_weights_graf(cox_model, lung_left) - Error - For this usage, the allowed censoring type is: 'right' + Condition + Error in `.censoring_weights_graf()`: + ! For this usage, the allowed censoring type is: 'right' --- Code .censoring_weights_graf(cox_model, lung2) - Error - The input should have a list column called `.pred`. + Condition + Error: + ! The input should have a list column called `.pred`. --- Code .censoring_weights_graf(cox_model, preds, cens_predictors = "shouldn't be using this anyway!") - Warning + Condition + Warning: The 'cens_predictors' argument to the survival weighting function is not currently used. Output # A tibble: 3 x 2 @@ -53,6 +59,7 @@ Code .censoring_weights_graf(wrong_model, mtcars) - Error - The model needs to be for mode 'censored regression', not for mode 'regression'. + Condition + Error in `.check_censor_model()`: + ! The model needs to be for mode 'censored regression', not for mode 'regression'. diff --git a/tests/testthat/_snaps/parsnip-survival-standalone.md b/tests/testthat/_snaps/parsnip-survival-standalone.md index 7dacf779..8e941ebb 100644 --- a/tests/testthat/_snaps/parsnip-survival-standalone.md +++ b/tests/testthat/_snaps/parsnip-survival-standalone.md @@ -2,20 +2,23 @@ Code parsnip:::.is_surv(1) - Error - The object does not have class `Surv`. + Condition + Error: + ! The object does not have class `Surv`. # .check_cens_type() Code parsnip:::.check_cens_type(left_c, type = "right", fail = TRUE) - Error - For this usage, the allowed censoring type is: 'right' + Condition + Error: + ! For this usage, the allowed censoring type is: 'right' --- Code parsnip:::.check_cens_type(left_c, type = c("right", "interval"), fail = TRUE) - Error - For this usage, the allowed censoring types are: 'right' and 'interval' + Condition + Error: + ! For this usage, the allowed censoring types are: 'right' and 'interval' diff --git a/tests/testthat/_snaps/randomForest.md b/tests/testthat/_snaps/randomForest.md index 47a9ecf1..00b1400d 100644 --- a/tests/testthat/_snaps/randomForest.md +++ b/tests/testthat/_snaps/randomForest.md @@ -2,15 +2,19 @@ Code f_fit <- spec %>% fit(body_mass_g ~ ., data = penguins) - Warning + Condition + Warning: 1000 columns were requested but there were 6 predictors in the data. 6 will be used. + Warning: 1000 samples were requested but there were 333 rows in the data. 333 will be used. --- Code xy_fit <- spec %>% fit_xy(x = penguins[, -6], y = penguins$body_mass_g) - Warning + Condition + Warning: 1000 columns were requested but there were 6 predictors in the data. 6 will be used. + Warning: 1000 samples were requested but there were 333 rows in the data. 333 will be used. diff --git a/tests/testthat/_snaps/recipes1.0.8.9000/recipes-nnmf_sparse.md b/tests/testthat/_snaps/recipes1.0.8.9000/recipes-nnmf_sparse.md new file mode 100644 index 00000000..f47bed4c --- /dev/null +++ b/tests/testthat/_snaps/recipes1.0.8.9000/recipes-nnmf_sparse.md @@ -0,0 +1,36 @@ +# Correct values + + Code + print(rec) + Message + + -- Recipe ---------------------------------------------------------------------- + + -- Inputs + Number of variables by role + outcome: 1 + predictor: 4 + + -- Operations + * Non-negative matrix factorization for: all_predictors() + +# No NNF + + Code + print(rec) + Message + + -- Recipe ---------------------------------------------------------------------- + + -- Inputs + Number of variables by role + outcome: 1 + predictor: 4 + + -- Training information + Training data contained 150 data points and no incomplete rows. + + -- Operations + * No non-negative matrix factorization was extracted from: Sepal.Length, + Sepal.Width, Petal.Length, Petal.Width | Trained + diff --git a/tests/testthat/_snaps/recipes1.0.8/recipes-nnmf_sparse.md b/tests/testthat/_snaps/recipes1.0.8/recipes-nnmf_sparse.md new file mode 100644 index 00000000..f47bed4c --- /dev/null +++ b/tests/testthat/_snaps/recipes1.0.8/recipes-nnmf_sparse.md @@ -0,0 +1,36 @@ +# Correct values + + Code + print(rec) + Message + + -- Recipe ---------------------------------------------------------------------- + + -- Inputs + Number of variables by role + outcome: 1 + predictor: 4 + + -- Operations + * Non-negative matrix factorization for: all_predictors() + +# No NNF + + Code + print(rec) + Message + + -- Recipe ---------------------------------------------------------------------- + + -- Inputs + Number of variables by role + outcome: 1 + predictor: 4 + + -- Training information + Training data contained 150 data points and no incomplete rows. + + -- Operations + * No non-negative matrix factorization was extracted from: Sepal.Length, + Sepal.Width, Petal.Length, Petal.Width | Trained + diff --git a/tests/testthat/_snaps/sparse-glmnet.md b/tests/testthat/_snaps/sparse-glmnet.md index 579bea18..f2a2b8de 100644 --- a/tests/testthat/_snaps/sparse-glmnet.md +++ b/tests/testthat/_snaps/sparse-glmnet.md @@ -2,7 +2,8 @@ Code mold(rec, mlc_churn, blueprint = sparse_bp) - Error - `data` must only contain numeric columns. + Condition + Error in `recompose()`: + ! `data` must only contain numeric columns. i These columns aren't numeric: "international_plan". diff --git a/tests/testthat/_snaps/survival-augment.md b/tests/testthat/_snaps/survival-augment.md index 7bb8b9d0..1589605c 100644 --- a/tests/testthat/_snaps/survival-augment.md +++ b/tests/testthat/_snaps/survival-augment.md @@ -1,10 +1,8 @@ -# augmenting survival models +# augment() for survival models errors if eval_time is missing Code - augment(sr_fit, new_data = sim_tr) - Error - i In index: 1. - i With name: 1. - Caused by error in `.f()`: - ! argument "eval_time" is missing, with no default + augment(sr_fit, lung) + Condition + Error in `augment()`: + ! The `eval_time` argument is missing, with no default. diff --git a/tests/testthat/_snaps/survival-tune-sa.md b/tests/testthat/_snaps/survival-tune-sa.md index 8732060b..be423a92 100644 --- a/tests/testthat/_snaps/survival-tune-sa.md +++ b/tests/testthat/_snaps/survival-tune-sa.md @@ -1,4 +1,4 @@ -# sim annealing tuning survival models with dynamic metrics +# sim annealing tuning survival models with dynamic metric No evaluation time was set; a value of 10 was used. diff --git a/tests/testthat/test-glmnet-poisson.R b/tests/testthat/test-glmnet-poisson.R index aca9658f..aa425254 100644 --- a/tests/testthat/test-glmnet-poisson.R +++ b/tests/testthat/test-glmnet-poisson.R @@ -121,15 +121,9 @@ test_that("formula interface can deal with missing values", { expect_true(is.na(f_pred$.pred[1])) }) -test_that('error traps', { +test_that("model errors on missing penalty value", { skip_if_not_installed("glmnet") - expect_snapshot(error = TRUE, { - poisson_reg(penalty = 0.1) %>% - set_engine("glmnet") %>% - fit(mpg ~ ., data = mtcars[-(1:4), ]) %>% - predict(mtcars[-(1:4), ], penalty = 0:1) - }) skip_if_not_installed("parsnip", minimum_version = "1.0.3.9000") expect_snapshot(error = TRUE, { poisson_reg() %>% @@ -137,3 +131,15 @@ test_that('error traps', { fit(mpg ~ ., data = mtcars[-(1:4), ]) }) }) + +test_that("predict() errors with multiple penalty values", { + skip_if_not_installed("glmnet") + + skip_if_not_installed("poissonreg", minimum_version = "1.0.1.9000") + expect_snapshot(error = TRUE, { + poisson_reg(penalty = 0.1) %>% + set_engine("glmnet") %>% + fit(mpg ~ ., data = mtcars[-(1:4), ]) %>% + predict(mtcars[-(1:4), ], penalty = 0:1) + }) +}) diff --git a/tests/testthat/test-parsnip-case-weights.R b/tests/testthat/test-parsnip-case-weights.R index b490d127..b7532397 100644 --- a/tests/testthat/test-parsnip-case-weights.R +++ b/tests/testthat/test-parsnip-case-weights.R @@ -457,6 +457,8 @@ test_that('linear_reg - glmnet case weights', { test_that('linear_reg - stan_glmer case weights', { skip_if_not_installed("multilevelmod", "1.0.0") + skip_if_not_installed("Matrix", "1.6-2") + skip_if_not_installed("lme4", "1.1-35.1") dat <- make_msa_wts() @@ -481,6 +483,8 @@ test_that('linear_reg - stan_glmer case weights', { test_that('linear_reg - lme4::lmer case weights', { skip_if_not_installed("multilevelmod", "1.0.0") + skip_if_not_installed("Matrix", "1.6-2") + skip_if_not_installed("lme4", "1.1-35.1") dat <- make_msa_wts() @@ -609,6 +613,8 @@ test_that('logistic_reg - stan case weights', { test_that('logistic_reg - stan_glmer case weights', { skip_if_not_installed("multilevelmod", "1.0.0") + skip_if_not_installed("Matrix", "1.6-2") + skip_if_not_installed("lme4", "1.1-35.1") data("two_class_dat", package = "modeldata") @@ -638,6 +644,8 @@ test_that('logistic_reg - stan_glmer case weights', { test_that('logistic_reg - lme4::glmer case weights', { skip_if_not_installed("multilevelmod", "1.0.0") + skip_if_not_installed("Matrix", "1.6-2") + skip_if_not_installed("lme4", "1.1-35.1") data("two_class_dat", package = "modeldata") @@ -838,6 +846,8 @@ test_that('poisson_reg - glm case weights', { test_that('poisson_reg - stan_glmer case weights', { skip_if_not_installed("multilevelmod", "1.0.0") + skip_if_not_installed("Matrix", "1.6-2") + skip_if_not_installed("lme4", "1.1-35.1") data(bioChemists, package = "pscl", envir = rlang::current_env()) @@ -955,6 +965,8 @@ test_that('poisson_reg - stan case weights', { test_that('poisson_reg - lme4::glmer case weights', { skip_if_not_installed("multilevelmod", "1.0.0") + skip_if_not_installed("Matrix", "1.6-2") + skip_if_not_installed("lme4", "1.1-35.1") data(bioChemists, package = "pscl", envir = rlang::current_env()) diff --git a/tests/testthat/test-parsnip-model-formula.R b/tests/testthat/test-parsnip-model-formula.R new file mode 100644 index 00000000..1dd45eb9 --- /dev/null +++ b/tests/testthat/test-parsnip-model-formula.R @@ -0,0 +1,50 @@ +test_that('error without model formula (workflow, no tune)', { + skip_if_not_installed("parsnip", minimum_version = "1.1.1.9001") + + library(parsnip) + library(workflows) + + gam_wflow <- workflow() %>% + add_formula(mpg ~ .) %>% + add_model(gen_additive_mod("regression")) + + expect_snapshot( + error = TRUE, + gam_fit <- gam_wflow %>% fit(mtcars) + ) +}) + +test_that('error without model formula (workflow, with tune)', { + skip_if_not_installed("parsnip", minimum_version = "1.1.1.9001") + + library(parsnip) + library(workflows) + library(tune) + library(rsample) + + gam_wflow <- workflow() %>% + add_formula(mpg ~ .) %>% + add_model(gen_additive_mod("regression")) + + expect_warning( + gam_res <- gam_wflow %>% fit_resamples(bootstraps(mtcars)) + ) + + expect_snapshot(show_notes(gam_res)) +}) + +test_that('error without model formula (no workflow, with tune)', { + skip_if_not_installed("parsnip", minimum_version = "1.1.1.9001") + + library(parsnip) + library(tune) + library(rsample) + + gam_spec <- gen_additive_mod("regression") + + expect_warning( + gam_res <- gam_spec %>% fit_resamples(mpg ~ ., bootstraps(mtcars)) + ) + + expect_snapshot(show_notes(gam_res)) +}) diff --git a/tests/testthat/test-recipes-nnmf_sparse.R b/tests/testthat/test-recipes-nnmf_sparse.R index 87931515..cc7f0541 100644 --- a/tests/testthat/test-recipes-nnmf_sparse.R +++ b/tests/testthat/test-recipes-nnmf_sparse.R @@ -85,9 +85,10 @@ test_that('can prep recipes with no keep_original_cols', { rec$steps[[1]]$keep_original_cols <- NULL + skip_if_not_installed("recipes", minimum_version = "1.0.8.9000") expect_warning( nnmf_trained <- prep(rec, training = iris, verbose = FALSE), - "'keep_original_cols' was added to" + "`keep_original_cols` was added to" ) expect_error( diff --git a/tests/testthat/test-recipes-varying.R b/tests/testthat/test-recipes-varying.R index 37124791..498a61fc 100644 --- a/tests/testthat/test-recipes-varying.R +++ b/tests/testthat/test-recipes-varying.R @@ -1,6 +1,8 @@ library(testthat) library(tidymodels) +withr::local_options(lifecycle_verbosity = "quiet") + rec_1 <- recipe(mpg ~ ., mtcars) %>% step_center(all_predictors()) %>% step_impute_knn(all_predictors(), neighbors = varying()) %>% @@ -14,6 +16,7 @@ rec_2 <- recipe(mpg ~ ., mtcars) %>% rec_3 <- recipe(mpg ~ ., mtcars) test_that('recipe parameters', { + withr::local_options(lifecycle_verbosity = "quiet") # un-randomify the id names rec_1_id <- rec_1 @@ -57,6 +60,7 @@ test_that('recipe parameters', { }) test_that("recipe steps with non-varying args error if specified as varying()", { + withr::local_options(lifecycle_verbosity = "quiet") rec_bad_varying <- rec_1 rec_bad_varying$steps[[1]]$skip <- varying() @@ -68,6 +72,7 @@ test_that("recipe steps with non-varying args error if specified as varying()", }) test_that("`full = FALSE` returns only varying arguments", { + withr::local_options(lifecycle_verbosity = "quiet") x_spec <- rand_forest(min_n = varying()) %>% set_engine("ranger", sample.fraction = varying()) diff --git a/tests/testthat/test-survival-augment.R b/tests/testthat/test-survival-augment.R index 3cf51ee4..3bae7696 100644 --- a/tests/testthat/test-survival-augment.R +++ b/tests/testthat/test-survival-augment.R @@ -27,10 +27,6 @@ test_that('augmenting survival models ', { survival_reg() %>% fit(event_time ~ ., data = sim_tr) - expect_snapshot(error = TRUE, { - augment(sr_fit, new_data = sim_tr) - }) - sr_aug <- augment(sr_fit, new_data = sim_tr, eval_time = time_points) expect_equal(nrow(sr_aug), nrow(sim_tr)) expect_equal(names(sr_aug), c(".pred", ".pred_time", "event_time", "X1", "X2")) @@ -88,3 +84,14 @@ test_that("augment() for survival models skips unavailble prediction type", { ".weight_censored") ) }) + +test_that("augment() for survival models errors if eval_time is missing", { + skip_if_not_installed("parsnip", minimum_version = "1.1.0.9004") + + sr_fit <- survival_reg() %>% + fit(Surv(time, status) ~ ., data = lung) + + expect_snapshot(error = TRUE, { + augment(sr_fit, lung) + }) +})