From f437cf10892ba521e2c1a2d836c6c4c1d86d7bc4 Mon Sep 17 00:00:00 2001 From: Hannah Frick Date: Mon, 21 Oct 2024 15:53:57 +0100 Subject: [PATCH 1/4] add R CMD check hard --- .github/workflows/R-CMD-check-hard.yaml | 60 +++++++++++++++++++++++++ README.Rmd | 1 + README.md | 1 + 3 files changed, 62 insertions(+) create mode 100644 .github/workflows/R-CMD-check-hard.yaml diff --git a/.github/workflows/R-CMD-check-hard.yaml b/.github/workflows/R-CMD-check-hard.yaml new file mode 100644 index 00000000..27340b00 --- /dev/null +++ b/.github/workflows/R-CMD-check-hard.yaml @@ -0,0 +1,60 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +# +# NOTE: This workflow only directly installs "hard" dependencies, i.e. Depends, +# Imports, and LinkingTo dependencies. Notably, Suggests dependencies are never +# installed, with the exception of testthat, knitr, and rmarkdown. The cache is +# never used to avoid accidentally restoring a cache containing a suggested +# dependency. +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +name: check-no-suggests.yaml + +permissions: read-all + +jobs: + check-no-suggests: + runs-on: ${{ matrix.config.os }} + + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + + strategy: + fail-fast: false + matrix: + config: + - {os: ubuntu-latest, r: 'release'} + + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + r-version: ${{ matrix.config.r }} + http-user-agent: ${{ matrix.config.http-user-agent }} + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + dependencies: '"hard"' + cache: false + extra-packages: | + any::rcmdcheck + any::testthat + any::knitr + any::rmarkdown + needs: check + + - uses: r-lib/actions/check-r-package@v2 + with: + upload-snapshots: true + build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")' diff --git a/README.Rmd b/README.Rmd index de584d12..c5050357 100644 --- a/README.Rmd +++ b/README.Rmd @@ -23,6 +23,7 @@ options(rlang__backtrace_on_error = "reminder") [![Codecov test coverage](https://codecov.io/gh/tidymodels/hardhat/branch/main/graph/badge.svg)](https://app.codecov.io/gh/tidymodels/hardhat?branch=main) [![R-CMD-check](https://github.com/tidymodels/hardhat/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/tidymodels/hardhat/actions/workflows/R-CMD-check.yaml) +[![R-CMD-check-hard](https://github.com/tidymodels/hardhat/actions/workflows/R-CMD-check-hard.yaml/badge.svg)](https://github.com/tidymodels/hardhat/actions/workflows/R-CMD-check-hard.yaml) ## Introduction diff --git a/README.md b/README.md index c25b59ae..a769000b 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ [![Codecov test coverage](https://codecov.io/gh/tidymodels/hardhat/branch/main/graph/badge.svg)](https://app.codecov.io/gh/tidymodels/hardhat?branch=main) [![R-CMD-check](https://github.com/tidymodels/hardhat/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/tidymodels/hardhat/actions/workflows/R-CMD-check.yaml) +[![R-CMD-check-hard](https://github.com/tidymodels/hardhat/actions/workflows/R-CMD-check-hard.yaml/badge.svg)](https://github.com/tidymodels/hardhat/actions/workflows/R-CMD-check-hard.yaml) ## Introduction From ed9518cb9211841398583fca61137a035eddc8a3 Mon Sep 17 00:00:00 2001 From: Max Kuhn Date: Tue, 22 Oct 2024 13:04:58 -0400 Subject: [PATCH 2/4] Update .github/workflows/R-CMD-check-hard.yaml --- .github/workflows/R-CMD-check-hard.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/R-CMD-check-hard.yaml b/.github/workflows/R-CMD-check-hard.yaml index 27340b00..c06bf8f9 100644 --- a/.github/workflows/R-CMD-check-hard.yaml +++ b/.github/workflows/R-CMD-check-hard.yaml @@ -12,7 +12,7 @@ on: pull_request: branches: [main, master] -name: check-no-suggests.yaml +name: R-CMD-check-no-suggests.yaml permissions: read-all From 91128017133c916ff4e4d49119af7fedcbd5ed51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98topepo=E2=80=99?= Date: Tue, 22 Oct 2024 13:49:36 -0400 Subject: [PATCH 3/4] allow vignette compilation without suggsts --- vignettes/forge.Rmd | 9 ++++++++- vignettes/mold.Rmd | 9 ++++++++- vignettes/package.Rmd | 9 ++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/vignettes/forge.Rmd b/vignettes/forge.Rmd index c5dbc5fa..ed9a5369 100644 --- a/vignettes/forge.Rmd +++ b/vignettes/forge.Rmd @@ -10,9 +10,16 @@ editor_options: --- ```{r, include = FALSE} +if (rlang::is_installed(c("modeldata", "recipes", "Matrix"))) { + run <- TRUE +} else { + run <- FALSE +} + knitr::opts_chunk$set( collapse = TRUE, - comment = "#>" + comment = "#>", + eval = run ) options(rlang_backtrace_on_error = "none") diff --git a/vignettes/mold.Rmd b/vignettes/mold.Rmd index baa7adcc..ac38cbf9 100644 --- a/vignettes/mold.Rmd +++ b/vignettes/mold.Rmd @@ -10,9 +10,16 @@ editor_options: --- ```{r, include = FALSE} +if (rlang::is_installed(c("modeldata", "recipes", "Matrix"))) { + run <- TRUE +} else { + run <- FALSE +} + knitr::opts_chunk$set( collapse = TRUE, - comment = "#>" + comment = "#>", + eval = run ) options(rlang_backtrace_on_error = "none") diff --git a/vignettes/package.Rmd b/vignettes/package.Rmd index 1a3b87c5..50200afc 100644 --- a/vignettes/package.Rmd +++ b/vignettes/package.Rmd @@ -10,9 +10,16 @@ editor_options: --- ```{r, include = FALSE} +if (rlang::is_installed(c("modeldata", "recipes", "Matrix"))) { + run <- TRUE +} else { + run <- FALSE +} + knitr::opts_chunk$set( collapse = TRUE, - comment = "#>" + comment = "#>", + eval = run ) options(rlang_backtrace_on_error = "none") From c3ba770aa10902bad6b57c0931dd94bfa2e68487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98topepo=E2=80=99?= Date: Tue, 22 Oct 2024 14:11:50 -0400 Subject: [PATCH 4/4] protect tests and examples from missing suggested packages --- R/blueprint-recipe-default.R | 4 +- R/mold.R | 2 +- R/tune.R | 2 +- man/default_recipe_blueprint.Rd | 4 ++ man/mold.Rd | 2 + man/tune.Rd | 2 + tests/testthat/test-forge-recipe.R | 67 ++++++++++++++++++++++++++++++ tests/testthat/test-mold-recipe.R | 46 ++++++++++++++++++++ tests/testthat/test-print.R | 2 + tests/testthat/test-use.R | 6 +++ 10 files changed, 134 insertions(+), 3 deletions(-) diff --git a/R/blueprint-recipe-default.R b/R/blueprint-recipe-default.R index 79dc807f..09cb2a6c 100644 --- a/R/blueprint-recipe-default.R +++ b/R/blueprint-recipe-default.R @@ -45,7 +45,9 @@ #' - It adds an intercept column onto `new_data` if `intercept = TRUE`. #' #' @export -#' @examples +#' @examplesIf rlang::is_installed(c("recipes")) +#' # example code +#' #' library(recipes) #' #' # --------------------------------------------------------------------------- diff --git a/R/mold.R b/R/mold.R index 256cb7b8..4e2a1729 100644 --- a/R/mold.R +++ b/R/mold.R @@ -38,7 +38,7 @@ #' - `extras`: Either `NULL` if the blueprint returns no extra information, #' or a named list containing the extra information. #' -#' @examples +#' @examplesIf rlang::is_installed(c("recipes")) #' # See the method specific documentation linked in Description #' # for the details of each blueprint, and more examples. #' diff --git a/R/tune.R b/R/tune.R index 8ec2fb8d..e248ea35 100644 --- a/R/tune.R +++ b/R/tune.R @@ -13,7 +13,7 @@ #' #' @export #' -#' @examples +#' @examplesIf rlang::is_installed(c("recipes")) #' tune() #' tune("your name here") #' diff --git a/man/default_recipe_blueprint.Rd b/man/default_recipe_blueprint.Rd index fe55f600..e4b51789 100644 --- a/man/default_recipe_blueprint.Rd +++ b/man/default_recipe_blueprint.Rd @@ -79,6 +79,9 @@ used during training. } \examples{ +\dontshow{if (rlang::is_installed(c("recipes"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +# example code + library(recipes) # --------------------------------------------------------------------------- @@ -169,4 +172,5 @@ try(forge(test2, processed_roles$blueprint)) rec_roles <- update_role_requirements(rec_roles, "important", bake = FALSE) processed_roles <- mold(rec_roles, train) forge(test2, processed_roles$blueprint) +\dontshow{\}) # examplesIf} } diff --git a/man/mold.Rd b/man/mold.Rd index 72f49d80..262d19b9 100644 --- a/man/mold.Rd +++ b/man/mold.Rd @@ -41,6 +41,7 @@ how to use each one in conjunction with \code{mold()}. } } \examples{ +\dontshow{if (rlang::is_installed(c("recipes"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # See the method specific documentation linked in Description # for the details of each blueprint, and more examples. @@ -53,4 +54,5 @@ mold(Species ~ Sepal.Width, iris) # Recipe library(recipes) mold(recipe(Species ~ Sepal.Width, iris), iris) +\dontshow{\}) # examplesIf} } diff --git a/man/tune.Rd b/man/tune.Rd index 1fd55830..6ee3b45e 100644 --- a/man/tune.Rd +++ b/man/tune.Rd @@ -19,6 +19,7 @@ A call object that echos the user's input. tune packages. It marks recipes step and parsnip model arguments for tuning. } \examples{ +\dontshow{if (rlang::is_installed(c("recipes"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} tune() tune("your name here") @@ -29,6 +30,7 @@ library(recipes) recipe(mpg ~ ., data = mtcars) \%>\% step_normalize(all_numeric_predictors()) \%>\% step_pca(all_numeric_predictors, num_comp = tune()) +\dontshow{\}) # examplesIf} } \seealso{ \code{tune::tune_grid()}, \code{tune::tune_bayes()} diff --git a/tests/testthat/test-forge-recipe.R b/tests/testthat/test-forge-recipe.R index 576c3374..aa16eead 100644 --- a/tests/testthat/test-forge-recipe.R +++ b/tests/testthat/test-forge-recipe.R @@ -1,4 +1,7 @@ test_that("simple forge works", { + skip_if_not_installed("recipes") + skip_if_not_installed("Matrix") + sparse_bp <- default_recipe_blueprint(composition = "dgCMatrix") matrix_bp <- default_recipe_blueprint(composition = "matrix") @@ -53,6 +56,9 @@ test_that("simple forge works", { }) test_that("asking for the outcome works", { + skip_if_not_installed("recipes") + skip_if_not_installed("Matrix") + sparse_bp <- default_recipe_blueprint(composition = "dgCMatrix") matrix_bp <- default_recipe_blueprint(composition = "matrix") @@ -82,6 +88,8 @@ test_that("asking for the outcome works", { }) test_that("asking for the outcome when it isn't there fails", { + skip_if_not_installed("recipes") + skip_if_not_installed("Matrix") sparse_bp <- default_recipe_blueprint(composition = "dgCMatrix") rec <- recipes::recipe(Species ~ Sepal.Length, data = iris) x1 <- mold(rec, iris) @@ -102,6 +110,9 @@ test_that("asking for the outcome when it isn't there fails", { }) test_that("outcomes steps get processed", { + skip_if_not_installed("recipes") + skip_if_not_installed("Matrix") + sparse_bp <- default_recipe_blueprint(composition = "dgCMatrix") rec <- recipes::recipe(Sepal.Width ~ Sepal.Length, data = iris) rec <- recipes::step_log(rec, Sepal.Width) @@ -123,6 +134,8 @@ test_that("outcomes steps get processed", { }) test_that("missing predictor columns fail appropriately", { + skip_if_not_installed("recipes") + x <- mold( recipes::recipe(Species ~ Sepal.Length + Sepal.Width, data = iris), iris @@ -140,6 +153,8 @@ test_that("missing predictor columns fail appropriately", { }) test_that("novel predictor levels are caught", { + skip_if_not_installed("recipes") + skip_if_not_installed("Matrix") sparse_bp <- default_recipe_blueprint(composition = "dgCMatrix") dat <- data.frame( @@ -174,6 +189,9 @@ test_that("novel predictor levels are caught", { }) test_that("novel predictor levels can be ignored and handled by recipes", { + skip_if_not_installed("recipes") + skip_if_not_installed("Matrix") + dat <- data.frame( y = 1:4, f = factor(letters[1:4]) @@ -227,6 +245,9 @@ test_that("novel predictor levels can be ignored and handled by recipes", { }) test_that("novel predictor levels without any data are silently removed", { + skip_if_not_installed("recipes") + skip_if_not_installed("Matrix") + sparse_bp <- default_recipe_blueprint(composition = "dgCMatrix") dat <- data.frame( @@ -268,6 +289,9 @@ test_that("novel predictor levels without any data are silently removed", { }) test_that("novel outcome levels are caught", { + skip_if_not_installed("recipes") + skip_if_not_installed("Matrix") + sparse_bp <- default_recipe_blueprint(composition = "dgCMatrix") dat <- data.frame( @@ -305,6 +329,9 @@ test_that("novel outcome levels are caught", { }) test_that("original predictor and outcome classes / names are recorded", { + skip_if_not_installed("recipes") + skip_if_not_installed("Matrix") + sparse_bp <- default_recipe_blueprint(composition = "dgCMatrix") rec <- recipes::recipe(Sepal.Length ~ Species, data = iris) @@ -351,6 +378,9 @@ test_that("original predictor and outcome classes / names are recorded", { }) test_that("new data classes are caught", { + skip_if_not_installed("recipes") + skip_if_not_installed("Matrix") + sparse_bp <- default_recipe_blueprint(composition = "dgCMatrix") iris2 <- iris iris2$Species <- as.character(iris2$Species) @@ -401,6 +431,9 @@ test_that("new data classes are caught", { }) test_that("new data classes can interchange integer/numeric", { + skip_if_not_installed("recipes") + skip_if_not_installed("Matrix") + sparse_bp <- default_recipe_blueprint(composition = "dgCMatrix") iris2 <- iris iris2$Sepal.Length <- as.integer(iris2$Sepal.Length) @@ -432,6 +465,9 @@ test_that("new data classes can interchange integer/numeric", { }) test_that("an `extras` slot exists for `roles`", { + skip_if_not_installed("recipes") + skip_if_not_installed("Matrix") + sparse_bp <- default_recipe_blueprint(composition = "dgCMatrix") rec <- recipes::recipe(Species ~ Sepal.Length, data = iris) x1 <- mold(rec, iris) @@ -451,6 +487,8 @@ test_that("an `extras` slot exists for `roles`", { }) test_that("non-standard roles generated in the recipe are returned by both `mold()` and `forge()`", { + skip_if_not_installed("recipes") + # This is a convention we follow to have consistency between `mold()` and `forge()`. # Both should have the same `.$extras$roles$` slot names. @@ -474,6 +512,8 @@ test_that("non-standard roles generated in the recipe are returned by both `mold }) test_that("`forge()` returns a slot for non standard roles that aren't required at `bake()` time", { + skip_if_not_installed("recipes") + # This is a convention we follow to have consistency between `mold()` and `forge()`. # Both should have the same `.$extras$roles$` slot names, even if there # wasn't any data there at `forge()` time (because it wasn't a required role). @@ -512,6 +552,8 @@ test_that("`forge()` returns a slot for non standard roles that aren't required }) test_that("required non standard roles can be dropped during the baking process", { + skip_if_not_installed("recipes") + rec <- recipes::recipe(Species ~ ., iris) rec <- recipes::update_role(rec, Sepal.Width, new_role = "dummy1") rec <- recipes::update_role(rec, Sepal.Length, new_role = "dummy2") @@ -543,6 +585,8 @@ test_that("required non standard roles can be dropped during the baking process" }) test_that("`forge()` will error if required non standard roles are missing", { + skip_if_not_installed("recipes") + rec <- recipes::recipe(Species ~ ., iris) rec <- recipes::update_role(rec, Sepal.Width, new_role = "dummy1") @@ -556,6 +600,8 @@ test_that("`forge()` will error if required non standard roles are missing", { }) test_that("recipes will error if the role is declared as not required, but really was", { + skip_if_not_installed("recipes") + rec <- recipes::recipe(Species ~ ., iris) rec <- recipes::update_role(rec, Sepal.Width, new_role = "dummy1") rec <- recipes::update_role_requirements(rec, "dummy1", bake = FALSE) @@ -568,6 +614,8 @@ test_that("recipes will error if the role is declared as not required, but reall }) test_that("`NA` roles are treated as extra roles that are required at `forge()` time", { + skip_if_not_installed("recipes") + # `Petal.Length`, `Petal.Width` have `NA` roles rec <- recipes::recipe(iris) rec <- recipes::update_role(rec, Sepal.Length, new_role = "predictor") @@ -592,6 +640,8 @@ test_that("`NA` roles are treated as extra roles that are required at `forge()` }) test_that("`NA` roles can be declared as not required at `forge()` time", { + skip_if_not_installed("recipes") + # Petal.Length, Petal.Width have `NA` roles rec <- recipes::recipe(iris) rec <- recipes::update_role(rec, Sepal.Length, new_role = "predictor") @@ -614,6 +664,8 @@ test_that("`NA` roles can be declared as not required at `forge()` time", { }) test_that("`extras` only hold roles that actually exist in the data", { + skip_if_not_installed("recipes") + df <- tibble(y = 1, x = 1, z = 2) rec <- recipes::recipe(y ~ ., df) @@ -628,6 +680,9 @@ test_that("`extras` only hold roles that actually exist in the data", { }) test_that("Missing y value still returns `NULL` if no outcomes are asked for", { + skip_if_not_installed("recipes") + skip_if_not_installed("Matrix") + sparse_bp <- default_recipe_blueprint(composition = "dgCMatrix") rec <- recipes::recipe(~Sepal.Width, data = iris) x1 <- mold(rec, iris) @@ -637,6 +692,9 @@ test_that("Missing y value still returns `NULL` if no outcomes are asked for", { }) test_that("Missing y value returns 0 column tibble if outcomes are asked for", { + skip_if_not_installed("recipes") + skip_if_not_installed("Matrix") + sparse_bp <- default_recipe_blueprint(composition = "dgCMatrix") rec <- recipes::recipe(~Sepal.Width, data = iris) x1 <- mold(rec, iris) @@ -652,6 +710,9 @@ test_that("Missing y value returns 0 column tibble if outcomes are asked for", { }) test_that("Predictors with multiple roles are only included once before baking (#120)", { + skip_if_not_installed("recipes") + skip_if_not_installed("Matrix") + rec <- recipes::recipe(Species ~ ., iris) # Implicit "predictor" role too rec <- recipes::add_role(rec, Sepal.Length, new_role = "test1") rec <- recipes::add_role(rec, Sepal.Length, new_role = "test2") @@ -673,6 +734,8 @@ test_that("Predictors with multiple roles are only included once before baking ( }) test_that("`strings_as_factors` is used at `bake()` time", { + skip_if_not_installed("recipes") + df <- tibble(y = "a", x = "b") rec <- recipes::recipe(y ~ x, data = df) @@ -689,6 +752,8 @@ test_that("`strings_as_factors` is used at `bake()` time", { }) test_that("`forge()` is compatible with hardhat 0.2.0 molded blueprints with a basic recipe", { + skip_if_not_installed("recipes") + path <- test_path("data", "hardhat-0.2.0-post-mold-recipe.rds") object <- readRDS(path) @@ -710,6 +775,8 @@ test_that("`forge()` is compatible with hardhat 0.2.0 molded blueprints with a b }) test_that("`forge()` is compatible with hardhat 0.2.0 molded blueprints with a recipe with a nonstandard role", { + skip_if_not_installed("recipes") + path <- test_path("data", "hardhat-0.2.0-post-mold-recipe-nonstandard-role.rds") object <- readRDS(path) diff --git a/tests/testthat/test-mold-recipe.R b/tests/testthat/test-mold-recipe.R index c0764ffe..ee5a3777 100644 --- a/tests/testthat/test-mold-recipe.R +++ b/tests/testthat/test-mold-recipe.R @@ -1,4 +1,7 @@ test_that("can mold recipes", { + skip_if_not_installed("recipes") + skip_if_not_installed("Matrix") + sparse_bp <- default_recipe_blueprint(composition = "dgCMatrix") matrix_bp <- default_recipe_blueprint(composition = "matrix") @@ -26,6 +29,9 @@ test_that("can mold recipes", { }) test_that("can mold recipes with intercepts", { + skip_if_not_installed("recipes") + skip_if_not_installed("Matrix") + rec <- recipes::recipe(Species ~ Sepal.Length, data = iris) x1 <- mold( @@ -53,6 +59,9 @@ test_that("can mold recipes with intercepts", { }) test_that("can pass `fresh` through to `prep()`", { + skip_if_not_installed("recipes") + skip_if_not_installed("Matrix") + sparse_bp <- default_recipe_blueprint(composition = "dgCMatrix") iris1 <- iris[1:50, ] @@ -85,6 +94,9 @@ test_that("can pass `fresh` through to `prep()`", { }) test_that("`fresh` defaults to `TRUE`", { + skip_if_not_installed("recipes") + skip_if_not_installed("Matrix") + sparse_bp <- default_recipe_blueprint(composition = "dgCMatrix") iris1 <- iris[1:50, ] @@ -109,6 +121,8 @@ test_that("`fresh` defaults to `TRUE`", { }) test_that("can pass `strings_as_factors` through to `prep()`", { + skip_if_not_installed("recipes") + df <- tibble(y = 1, x = "a") rec <- recipes::recipe(y ~ x, data = df) @@ -121,6 +135,8 @@ test_that("can pass `strings_as_factors` through to `prep()`", { }) test_that("`data` is validated", { + skip_if_not_installed("recipes") + expect_error( mold(recipes::recipe(Species ~ Sepal.Length, data = iris), 1), "`data` must be a data.frame or a matrix" @@ -128,6 +144,9 @@ test_that("`data` is validated", { }) test_that("`extras` holds a slot for `roles`", { + skip_if_not_installed("recipes") + skip_if_not_installed("Matrix") + sparse_bp <- default_recipe_blueprint(composition = "dgCMatrix") matrix_bp <- default_recipe_blueprint(composition = "matrix") @@ -146,6 +165,8 @@ test_that("`extras` holds a slot for `roles`", { }) test_that("non-standard roles ptypes are stored by default", { + skip_if_not_installed("recipes") + rec <- recipes::recipe(Species ~ ., iris) rec <- recipes::update_role(rec, Sepal.Width, new_role = "dummy") @@ -163,6 +184,8 @@ test_that("non-standard roles ptypes are stored by default", { }) test_that("case weights is not considered a required extra role by default", { + skip_if_not_installed("recipes") + iris$weight <- frequency_weights(seq_len(nrow(iris))) rec <- recipes::recipe(Species ~ ., iris) @@ -186,6 +209,8 @@ test_that("case weights is not considered a required extra role by default", { }) test_that("case weights can be updated to be a required extra role", { + skip_if_not_installed("recipes") + iris$weight <- frequency_weights(seq_len(nrow(iris))) rec <- recipes::recipe(Species ~ ., iris) @@ -214,6 +239,9 @@ test_that("case weights can be updated to be a required extra role", { }) test_that("only original non-standard columns are in the extra roles ptype", { + skip_if_not_installed("recipes") + skip_if_not_installed("Matrix") + sparse_bp <- default_recipe_blueprint(composition = "dgCMatrix") # same custom role, but note step_bs() columns aren't original columns @@ -246,6 +274,8 @@ test_that("only original non-standard columns are in the extra roles ptype", { }) test_that("`extra_role_ptypes` and `extras` only hold roles that actually exist in the data", { + skip_if_not_installed("recipes") + df <- tibble(y = 1, x = 1, z = 2) rec <- recipes::recipe(y ~ ., df) @@ -260,6 +290,9 @@ test_that("`extra_role_ptypes` and `extras` only hold roles that actually exist }) test_that("multiple extra roles types can be stored", { + skip_if_not_installed("recipes") + skip_if_not_installed("Matrix") + sparse_bp <- default_recipe_blueprint(composition = "dgCMatrix") rec <- recipes::recipe(Species ~ ., iris) @@ -291,6 +324,9 @@ test_that("multiple extra roles types can be stored", { }) test_that("`NA` roles are treated as extra roles", { + skip_if_not_installed("recipes") + skip_if_not_installed("Matrix") + sparse_bp <- default_recipe_blueprint(composition = "dgCMatrix") rec <- recipes::recipe(iris) @@ -375,6 +411,8 @@ test_that("`NA` roles are treated as extra roles", { }) test_that("roles that aren't required are not retained as `extra_role_ptypes`, but are in the mold result", { + skip_if_not_installed("recipes") + rec <- recipes::recipe(Species ~ ., iris) rec <- recipes::update_role(rec, Sepal.Width, new_role = "dummy1") rec <- recipes::update_role(rec, Sepal.Length, new_role = "dummy2") @@ -398,6 +436,9 @@ test_that("roles that aren't required are not retained as `extra_role_ptypes`, b }) test_that("Missing y value returns a 0 column tibble for `outcomes`", { + skip_if_not_installed("recipes") + skip_if_not_installed("Matrix") + sparse_bp <- default_recipe_blueprint(composition = "dgCMatrix") rec <- recipes::recipe(~Sepal.Width, data = iris) x1 <- mold(rec, iris) @@ -409,6 +450,9 @@ test_that("Missing y value returns a 0 column tibble for `outcomes`", { }) test_that("Missing y value returns a 0 column / 0 row tibble for `ptype`", { + skip_if_not_installed("recipes") + skip_if_not_installed("Matrix") + sparse_bp <- default_recipe_blueprint(composition = "dgCMatrix") rec <- recipes::recipe(~Sepal.Width, data = iris) x1 <- mold(rec, iris) @@ -418,6 +462,8 @@ test_that("Missing y value returns a 0 column / 0 row tibble for `ptype`", { }) test_that("`mold()` is compatible with hardhat 0.2.0 blueprints", { + skip_if_not_installed("recipes") + path <- test_path("data", "hardhat-0.2.0-pre-mold-recipe.rds") object <- readRDS(path) diff --git a/tests/testthat/test-print.R b/tests/testthat/test-print.R index 2ee774e5..9612e955 100644 --- a/tests/testthat/test-print.R +++ b/tests/testthat/test-print.R @@ -12,6 +12,8 @@ test_that("print - default", { }) test_that("print - recipe", { + skip_if_not_installed("recipes") + expect_snapshot({ mold(recipes::recipe(Species ~ Sepal.Length, iris), iris)$blueprint }) diff --git a/tests/testthat/test-use.R b/tests/testthat/test-use.R index 10aea0aa..3bbacbf5 100644 --- a/tests/testthat/test-use.R +++ b/tests/testthat/test-use.R @@ -1,5 +1,7 @@ test_that("can create a modeling package", { skip_on_cran() + skip_if_not_installed("recipes") + local_options(usethis.quiet = TRUE) dir <- withr::local_tempdir("model") @@ -27,6 +29,8 @@ test_that("can create a modeling package", { test_that("can add a second model to a modeling package", { skip_on_cran() + skip_if_not_installed("recipes") + local_options(usethis.quiet = TRUE) dir <- withr::local_tempdir("model") @@ -62,6 +66,8 @@ test_that("no `path` aborts normally", { }) test_that("`model` can only be a single string", { + skip_if_not_installed("recipes") + expect_snapshot(error = TRUE, create_modeling_package(path = "my/path", model = c("model1", "model2"))) expect_snapshot(error = TRUE, create_modeling_package(path = "my/path", model = 1)) expect_snapshot(error = TRUE, create_modeling_package(path = "my/path", model = "model with space"))