From 5d78ad6544c647914efe724a2af70e2d8c382737 Mon Sep 17 00:00:00 2001 From: Emil Hvitfeldt Date: Fri, 15 Aug 2025 11:49:39 -0700 Subject: [PATCH 1/2] use skip_if_not_installed() --- tests/testthat/test-parsnip-extension-messaging.R | 10 +++++----- tests/testthat/test-recipes-nnmf_sparse.R | 12 ++++++------ tests/testthat/test-stacks-columns.R | 2 +- tests/testthat/test-stacks-tuning.R | 12 ++++++------ 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/testthat/test-parsnip-extension-messaging.R b/tests/testthat/test-parsnip-extension-messaging.R index 13068345..81450fc0 100644 --- a/tests/testthat/test-parsnip-extension-messaging.R +++ b/tests/testthat/test-parsnip-extension-messaging.R @@ -1,5 +1,5 @@ test_that('messaging with unknown implementation (bag tree, tidymodels/parsnip#793)', { - skip_if(utils::packageVersion("parsnip") < "1.0.2") + skip_if_not_installed("parsnip", "1.0.2") library(parsnip) @@ -68,7 +68,7 @@ test_that('messaging with unknown implementation (bag tree, tidymodels/parsnip#7 }) test_that('messaging with unknown implementation (decision tree, tidymodels/parsnip#793)', { - skip_if(utils::packageVersion("parsnip") < "1.0.2") + skip_if_not_installed("parsnip", "1.0.2") library(parsnip) @@ -136,7 +136,7 @@ test_that('missing implementation checks prompt conservatively with old objects # extension packages, as well as model specs generated before parsnip 1.0.2, # will not have this slot. ensure that these messages/errors aren't # erroneously introduced when that's the case - skip_if(utils::packageVersion("parsnip") < "1.0.2") + skip_if_not_installed("parsnip", "1.0.2") library(parsnip) @@ -159,7 +159,7 @@ test_that('missing implementation checks prompt conservatively with old objects test_that('missing implementation checks prompt conservatively with old objects (decision_tree)', { # see comment in above chunk - skip_if(utils::packageVersion("parsnip") < "1.0.2") + skip_if_not_installed("parsnip", "1.0.2") library(parsnip) @@ -190,7 +190,7 @@ test_that('missing implementation checks prompt conservatively with old objects test_that('missing implementation checks prompt conservatively with external objects (arima_boost)', { # see comment in above chunk - skip_if(utils::packageVersion("parsnip") < "1.0.2") + skip_if_not_installed("parsnip", "1.0.2") library(modeltime) diff --git a/tests/testthat/test-recipes-nnmf_sparse.R b/tests/testthat/test-recipes-nnmf_sparse.R index 5553e25d..cecab528 100644 --- a/tests/testthat/test-recipes-nnmf_sparse.R +++ b/tests/testthat/test-recipes-nnmf_sparse.R @@ -3,7 +3,7 @@ library(recipes) suppressPackageStartupMessages(library(Matrix)) # Waiting for fix in RcppML test_that('Correct values', { - skip_if(utils::packageVersion("recipes") < "0.1.17.9001") + skip_if_not_installed("recipes", "0.1.17.9001") rec <- recipe(Species ~ ., data = iris) %>% step_nnmf_sparse(all_predictors(), seed = 2432) @@ -27,7 +27,7 @@ test_that('Correct values', { test_that('No NNF', { - skip_if(utils::packageVersion("recipes") < "0.1.17.9001") + skip_if_not_installed("recipes", "0.1.17.9001") rec <- recipe(Species ~ ., data = iris) %>% step_nnmf_sparse(all_predictors(), seed = 2432, num_comp = 0) %>% @@ -43,7 +43,7 @@ test_that('No NNF', { }) test_that('tunable', { - skip_if(utils::packageVersion("recipes") < "0.1.17.9001") + skip_if_not_installed("recipes", "0.1.17.9001") rec <- recipe(~ ., data = iris) %>% step_nnmf_sparse(all_predictors()) @@ -59,7 +59,7 @@ test_that('tunable', { }) test_that('keep_original_cols works', { - skip_if(utils::packageVersion("recipes") < "0.1.17.9001") + skip_if_not_installed("recipes", "0.1.17.9001") rec <- recipe(Species ~ ., data = iris) %>% step_nnmf_sparse(all_predictors(), seed = 2432, keep_original_cols = TRUE) @@ -76,7 +76,7 @@ test_that('keep_original_cols works', { }) test_that('can prep recipes with no keep_original_cols', { - skip_if(utils::packageVersion("recipes") < "0.1.17.9001") + skip_if_not_installed("recipes", "0.1.17.9001") rec <- recipe(Species ~ ., data = iris) %>% step_nnmf_sparse(all_predictors(), seed = 2432) @@ -96,7 +96,7 @@ test_that('can prep recipes with no keep_original_cols', { }) test_that('tidy method', { - skip_if(utils::packageVersion("recipes") < "1.0.6.9000") + skip_if_not_installed("recipes", "1.0.6.9000") set.seed(1) rec <- recipe(~ ., data = mtcars) %>% diff --git a/tests/testthat/test-stacks-columns.R b/tests/testthat/test-stacks-columns.R index 5f3f68e7..7fee982d 100644 --- a/tests/testthat/test-stacks-columns.R +++ b/tests/testthat/test-stacks-columns.R @@ -15,7 +15,7 @@ library(dplyr) test_that("stacks can accommodate outcome levels that are not valid colnames", { # skip on pre-0.2.4 - skip_if(utils::packageVersion("stacks") < "0.2.3.9001") + skip_if_not_installed("stacks", "0.2.3.9001") skip_if_not_installed("tune", "1.3.0.9006") data("penguins") diff --git a/tests/testthat/test-stacks-tuning.R b/tests/testthat/test-stacks-tuning.R index eb8837f0..c10eabaf 100644 --- a/tests/testthat/test-stacks-tuning.R +++ b/tests/testthat/test-stacks-tuning.R @@ -67,7 +67,7 @@ wf_set <- # tests ------------------------------------------------------------------ test_that("stacking with grid search works", { - skip_if(utils::packageVersion("stacks") < "1.0.0.9000") + skip_if_not_installed("stacks", "1.0.0.9000") wf_set_grid <- workflow_map( @@ -112,7 +112,7 @@ test_that("stacking with grid search works", { }) test_that("stacking with Bayesian tuning works", { - skip_if(utils::packageVersion("stacks") < "1.0.0.9000") + skip_if_not_installed("stacks", "1.0.0.9000") wf_set_bayes <- workflow_map( @@ -158,7 +158,7 @@ test_that("stacking with Bayesian tuning works", { }) test_that("stacking with finetune works (anova)", { - skip_if(utils::packageVersion("stacks") < "1.0.0.9000") + skip_if_not_installed("stacks", "1.0.0.9000") wf_set_anova <- workflow_map( @@ -224,8 +224,8 @@ test_that("stacking with finetune works (anova)", { }) test_that("stacking with finetune works (sim_anneal)", { - skip_if(utils::packageVersion("stacks") < "1.0.0.9000") - skip_if(utils::packageVersion("finetune") < "1.1.0.9001") + skip_if_not_installed("stacks", "1.0.0.9000") + skip_if_not_installed("finetune", "1.1.0.9001") wf_set_sim_anneal <- workflow_map( @@ -286,7 +286,7 @@ test_that("stacking with finetune works (sim_anneal)", { }) test_that("stacking with finetune works (win_loss)", { - skip_if(utils::packageVersion("stacks") < "1.0.0.9000") + skip_if_not_installed("stacks", "1.0.0.9000") wf_set_win_loss <- workflow_map( From 3e3fe66cf4e7c6243c63be35d655226f6d74fc0b Mon Sep 17 00:00:00 2001 From: Emil Hvitfeldt Date: Fri, 15 Aug 2025 11:50:50 -0700 Subject: [PATCH 2/2] one more --- tests/testthat/test-butcher-recipes.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-butcher-recipes.R b/tests/testthat/test-butcher-recipes.R index a217c803..54268821 100644 --- a/tests/testthat/test-butcher-recipes.R +++ b/tests/testthat/test-butcher-recipes.R @@ -13,7 +13,7 @@ terms_empty_env <- function(axed, step_number) { } test_that("recipe + step_nnmf_sparse + axe_env() works", { - skip_if(utils::packageVersion("recipes") < "0.1.17.9001") + skip_if_not_installed("recipes", "0.1.17.9001") rec <- recipe(HHV ~ ., data = biomass_tr) %>% step_nnmf_sparse(all_numeric_predictors(), num_comp = 2, seed = 473) x <- axe_env(rec) @@ -21,7 +21,7 @@ test_that("recipe + step_nnmf_sparse + axe_env() works", { }) test_that("recipe + step_nnmf_sparse + bake() works", { - skip_if(utils::packageVersion("recipes") < "0.1.17.9001") + skip_if_not_installed("recipes", "0.1.17.9001") rec <- recipe(HHV ~ ., data = biomass_tr) %>% step_nnmf_sparse(all_numeric_predictors(), num_comp = 2, seed = 473) %>% prep()