diff --git a/.github/workflows/check-no-suggests.yaml b/.github/workflows/check-no-suggests.yaml new file mode 100644 index 00000000..27340b00 --- /dev/null +++ b/.github/workflows/check-no-suggests.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/DESCRIPTION b/DESCRIPTION index d95787ec..100aa2d9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -41,6 +41,7 @@ Suggests: Matrix, methods, modeldata (>= 1.0.0), + probably, recipes (>= 1.0.10.9000), rmarkdown, testthat (>= 3.0.0) @@ -56,6 +57,7 @@ Remotes: tidymodels/dials, tidymodels/recipes, tidymodels/parsnip, + tidymodels/probably, tidymodels/tailor, r-lib/sparsevctrs Config/testthat/edition: 3 diff --git a/R/broom.R b/R/broom.R index 8a887b59..018349d0 100644 --- a/R/broom.R +++ b/R/broom.R @@ -55,7 +55,7 @@ tidy.workflow <- function(x, what = "model", ...) { #' #' @export #' @examples -#' if (rlang::is_installed("broom")) { +#' if (rlang::is_installed(c("broom", "modeldata"))) { #' #' library(parsnip) #' library(magrittr) diff --git a/R/extract.R b/R/extract.R index 99ab341e..67ff555e 100644 --- a/R/extract.R +++ b/R/extract.R @@ -68,7 +68,7 @@ #' section. #' #' @name extract-workflow -#' @examples +#' @examplesIf rlang::is_installed("recipes") #' library(parsnip) #' library(recipes) #' library(magrittr) diff --git a/R/fit.R b/R/fit.R index 80916c63..13d13151 100644 --- a/R/fit.R +++ b/R/fit.R @@ -32,7 +32,7 @@ #' #' @name fit-workflow #' @export -#' @examples +#' @examplesIf rlang::is_installed("recipes") #' library(parsnip) #' library(recipes) #' library(magrittr) @@ -66,7 +66,7 @@ fit.workflow <- function(object, data, ..., calibration = NULL, control = contro if (is_sparse_matrix(data)) { data <- sparsevctrs::coerce_to_sparse_tibble( - data, + data, call = rlang::caller_env(0) ) } @@ -125,7 +125,7 @@ fit.workflow <- function(object, data, ..., calibration = NULL, control = contro #' @name workflows-internals #' @keywords internal #' @export -#' @examples +#' @examplesIf rlang::is_installed("recipes") #' library(parsnip) #' library(recipes) #' library(magrittr) diff --git a/R/post-action-tailor.R b/R/post-action-tailor.R index c04075e0..eb6ca189 100644 --- a/R/post-action-tailor.R +++ b/R/post-action-tailor.R @@ -69,7 +69,7 @@ #' `x`, updated with either a new or removed tailor postprocessor. #' #' @export -#' @examples +#' @examplesIf rlang::is_installed(c("tailor", "probably")) #' library(tailor) #' library(magrittr) #' diff --git a/R/pre-action-recipe.R b/R/pre-action-recipe.R index 2d57de3a..71957534 100644 --- a/R/pre-action-recipe.R +++ b/R/pre-action-recipe.R @@ -36,7 +36,7 @@ #' `x`, updated with either a new or removed recipe preprocessor. #' #' @export -#' @examples +#' @examplesIf rlang::is_installed("recipes") #' library(recipes) #' library(magrittr) #' diff --git a/R/predict.R b/R/predict.R index 417e2c9e..5ed95026 100644 --- a/R/predict.R +++ b/R/predict.R @@ -25,7 +25,7 @@ #' #' @name predict-workflow #' @export -#' @examples +#' @examplesIf rlang::is_installed("recipes") #' library(parsnip) #' library(recipes) #' library(magrittr) @@ -61,7 +61,7 @@ predict.workflow <- function(object, new_data, type = NULL, opts = list(), ...) if (is_sparse_matrix(new_data)) { new_data <- sparsevctrs::coerce_to_sparse_tibble( - new_data, + new_data, call = rlang::caller_env(0) ) } diff --git a/R/pull.R b/R/pull.R index 6ed49486..0fe2f7a5 100644 --- a/R/pull.R +++ b/R/pull.R @@ -32,7 +32,7 @@ #' #' @name workflow-extractors #' @keywords internal -#' @examples +#' @examplesIf rlang::is_installed("recipes") #' library(parsnip) #' library(recipes) #' library(magrittr) diff --git a/R/workflow.R b/R/workflow.R index 61260a5a..6ca86ac6 100644 --- a/R/workflow.R +++ b/R/workflow.R @@ -31,7 +31,7 @@ #' #' @includeRmd man/rmd/indicators.Rmd details #' -#' @examples +#' @examplesIf rlang::is_installed(c("recipes", "modeldata")) #' library(parsnip) #' library(recipes) #' library(magrittr) @@ -166,7 +166,7 @@ is_workflow <- function(x) { #' @return A single logical indicating if the workflow has been trained or not. #' #' @export -#' @examples +#' @examplesIf rlang::is_installed("recipes") #' library(parsnip) #' library(recipes) #' library(magrittr) diff --git a/man/add_recipe.Rd b/man/add_recipe.Rd index 9c08fe27..c56db45c 100644 --- a/man/add_recipe.Rd +++ b/man/add_recipe.Rd @@ -49,6 +49,7 @@ To fit a workflow, exactly one of \code{\link[=add_formula]{add_formula()}}, \co \code{\link[=add_variables]{add_variables()}} \emph{must} be specified. } \examples{ +\dontshow{if (rlang::is_installed("recipes")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(recipes) library(magrittr) @@ -63,4 +64,5 @@ workflow remove_recipe(workflow) update_recipe(workflow, recipe(mpg ~ cyl, mtcars)) +\dontshow{\}) # examplesIf} } diff --git a/man/add_tailor.Rd b/man/add_tailor.Rd index 76b07bba..e82e8c49 100644 --- a/man/add_tailor.Rd +++ b/man/add_tailor.Rd @@ -83,6 +83,7 @@ training are passed to the tune package, this is handled internally. } \examples{ +\dontshow{if (rlang::is_installed(c("tailor", "probably"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(tailor) library(magrittr) @@ -97,4 +98,5 @@ workflow remove_tailor(workflow) update_tailor(workflow, adjust_probability_threshold(tailor, .2)) +\dontshow{\}) # examplesIf} } diff --git a/man/extract-workflow.Rd b/man/extract-workflow.Rd index 8424f2ed..e75bc4f1 100644 --- a/man/extract-workflow.Rd +++ b/man/extract-workflow.Rd @@ -99,6 +99,7 @@ workflow_fit \%>\% extract_fit_parsnip() \%>\% predict(new_data) }\if{html}{\out{}} } \examples{ +\dontshow{if (rlang::is_installed("recipes")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(parsnip) library(recipes) library(magrittr) @@ -144,4 +145,5 @@ identical( extract_mold(fit_recipe_wf)$blueprint$recipe, extract_recipe(fit_recipe_wf) ) +\dontshow{\}) # examplesIf} } diff --git a/man/fit-workflow.Rd b/man/fit-workflow.Rd index 3c2a0a04..955bd08a 100644 --- a/man/fit-workflow.Rd +++ b/man/fit-workflow.Rd @@ -153,6 +153,7 @@ behavior from the model’s computational engine. } \examples{ +\dontshow{if (rlang::is_installed("recipes")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(parsnip) library(recipes) library(magrittr) @@ -175,4 +176,5 @@ recipe_wf <- base_wf \%>\% add_recipe(recipe) fit(recipe_wf, mtcars) +\dontshow{\}) # examplesIf} } diff --git a/man/glance.workflow.Rd b/man/glance.workflow.Rd index 7758113a..a9ef0673 100644 --- a/man/glance.workflow.Rd +++ b/man/glance.workflow.Rd @@ -19,7 +19,7 @@ the underlying parsnip model. \code{glance()} at. } \examples{ -if (rlang::is_installed("broom")) { +if (rlang::is_installed(c("broom", "modeldata"))) { library(parsnip) library(magrittr) diff --git a/man/is_trained_workflow.Rd b/man/is_trained_workflow.Rd index d14ce001..4a5262ff 100644 --- a/man/is_trained_workflow.Rd +++ b/man/is_trained_workflow.Rd @@ -17,6 +17,7 @@ A trained workflow is one that has gone through \code{\link[=fit.workflow]{fit() which preprocesses the underlying data, and fits the parsnip model. } \examples{ +\dontshow{if (rlang::is_installed("recipes")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(parsnip) library(recipes) library(magrittr) @@ -37,4 +38,5 @@ wf <- fit(wf, mtcars) # After all preprocessing and model fitting is_trained_workflow(wf) +\dontshow{\}) # examplesIf} } diff --git a/man/predict-workflow.Rd b/man/predict-workflow.Rd index 9bf50b21..e5938b12 100644 --- a/man/predict-workflow.Rd +++ b/man/predict-workflow.Rd @@ -61,6 +61,7 @@ parsnip model. } } \examples{ +\dontshow{if (rlang::is_installed("recipes")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(parsnip) library(recipes) library(magrittr) @@ -84,4 +85,5 @@ fit_workflow <- fit(workflow, training) # This will automatically `bake()` the recipe on `testing`, # applying the log step to `disp`, and then fit the regression. predict(fit_workflow, testing) +\dontshow{\}) # examplesIf} } diff --git a/man/workflow-extractors.Rd b/man/workflow-extractors.Rd index 3d7a3a27..b87ed223 100644 --- a/man/workflow-extractors.Rd +++ b/man/workflow-extractors.Rd @@ -47,6 +47,7 @@ extracted from the mold object returned from \code{pull_workflow_mold()}. } } \examples{ +\dontshow{if (rlang::is_installed("recipes")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(parsnip) library(recipes) library(magrittr) @@ -91,5 +92,6 @@ identical( pull_workflow_mold(fit_recipe_wf)$blueprint$recipe, pull_workflow_prepped_recipe(fit_recipe_wf) ) +\dontshow{\}) # examplesIf} } \keyword{internal} diff --git a/man/workflow.Rd b/man/workflow.Rd index f204e0ba..c3ea4976 100644 --- a/man/workflow.Rd +++ b/man/workflow.Rd @@ -156,6 +156,7 @@ behavior from the model’s computational engine. } \examples{ +\dontshow{if (rlang::is_installed(c("recipes", "modeldata"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(parsnip) library(recipes) library(magrittr) @@ -188,4 +189,5 @@ variables <- workflow_variables( wf_variables <- workflow(variables, model) fit(wf_variables, attrition) +\dontshow{\}) # examplesIf} } diff --git a/man/workflows-internals.Rd b/man/workflows-internals.Rd index 3a234423..a6162f25 100644 --- a/man/workflows-internals.Rd +++ b/man/workflows-internals.Rd @@ -42,6 +42,7 @@ for usage by the tuning package, \href{https://github.com/tidymodels/tune}{tune} and the general user should never need to worry about them. } \examples{ +\dontshow{if (rlang::is_installed("recipes")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(parsnip) library(recipes) library(magrittr) @@ -68,5 +69,6 @@ wf_fit try(predict(wf_fit_model, mtcars)) predict(wf_fit, mtcars) +\dontshow{\}) # examplesIf} } \keyword{internal} diff --git a/tests/testthat/helper-sparsevctrs.R b/tests/testthat/helper-sparsevctrs.R index becc6315..8090b751 100644 --- a/tests/testthat/helper-sparsevctrs.R +++ b/tests/testthat/helper-sparsevctrs.R @@ -2,6 +2,10 @@ # For sparse tibble testing sparse_hotel_rates <- function(tibble = FALSE) { + if (!rlang::is_installed("modeldata")) { + return() + } + # 99.2 sparsity hotel_rates <- modeldata::hotel_rates diff --git a/tests/testthat/test-broom.R b/tests/testthat/test-broom.R index fe98bc23..c75de616 100644 --- a/tests/testthat/test-broom.R +++ b/tests/testthat/test-broom.R @@ -1,3 +1,5 @@ +skip_if_not_installed("recipes") + # ------------------------------------------------------------------------------ # tidy() diff --git a/tests/testthat/test-butcher.R b/tests/testthat/test-butcher.R index 999d875f..a03c1382 100644 --- a/tests/testthat/test-butcher.R +++ b/tests/testthat/test-butcher.R @@ -1,3 +1,5 @@ +skip_if_not_installed("recipes") + test_that("attaches the butcher class", { skip_if_not_installed("butcher") diff --git a/tests/testthat/test-extract.R b/tests/testthat/test-extract.R index 4955ae66..79dff6d7 100644 --- a/tests/testthat/test-extract.R +++ b/tests/testthat/test-extract.R @@ -1,3 +1,8 @@ +skip_if_not_installed("recipes") +skip_if_not_installed("modeldata") +skip_if_not_installed("probably") +skip_if_not_installed("tailor") + data(Chicago, package = "modeldata") # ------------------------------------------------------------------------------ diff --git a/tests/testthat/test-fit-action-model.R b/tests/testthat/test-fit-action-model.R index c87543ac..5ac9df7c 100644 --- a/tests/testthat/test-fit-action-model.R +++ b/tests/testthat/test-fit-action-model.R @@ -32,6 +32,8 @@ test_that("prompt on spec without a loaded implementation (#174)", { expect_snapshot(error = TRUE, workflow(spec = mod)) }) +skip_if_not_installed("recipes") + test_that("cannot add two models", { mod <- parsnip::linear_reg() mod <- parsnip::set_engine(mod, "lm") diff --git a/tests/testthat/test-fit.R b/tests/testthat/test-fit.R index 127d7dd9..32511895 100644 --- a/tests/testthat/test-fit.R +++ b/tests/testthat/test-fit.R @@ -1,3 +1,5 @@ +skip_if_not_installed("recipes") + data("hardhat-example-data", package = "hardhat") test_that("can `fit()` a workflow with a recipe", { @@ -87,6 +89,7 @@ test_that("cannot fit without a fit stage", { test_that("fit.workflow confirms compatibility of object and calibration", { skip_if_not_installed("tailor") + skip_if_not_installed("probably") mod <- parsnip::linear_reg() mod <- parsnip::set_engine(mod, "lm") @@ -199,6 +202,7 @@ test_that("`.fit_pre()` doesn't modify user supplied recipe blueprint", { # .fit_post() test_that(".workflow_includes_calibration works", { skip_if_not_installed("tailor") + skip_if_not_installed("probably") expect_false(.workflow_includes_calibration(workflow())) expect_false(.workflow_includes_calibration(workflow() %>% add_model(parsnip::linear_reg()))) diff --git a/tests/testthat/test-generics.R b/tests/testthat/test-generics.R index 4ff3483e..ff5c73ae 100644 --- a/tests/testthat/test-generics.R +++ b/tests/testthat/test-generics.R @@ -1,3 +1,5 @@ +skip_if_not_installed("recipes") + test_that("can compute required packages of a workflow - formula", { mod <- parsnip::linear_reg() mod <- parsnip::set_engine(mod, "lm") diff --git a/tests/testthat/test-post-action-tailor.R b/tests/testthat/test-post-action-tailor.R index ce5a0db4..28cfa09b 100644 --- a/tests/testthat/test-post-action-tailor.R +++ b/tests/testthat/test-post-action-tailor.R @@ -1,3 +1,6 @@ +skip_if_not_installed("probably") +skip_if_not_installed("tailor") + test_that("can add a postprocessor to a workflow", { post <- tailor::tailor() diff --git a/tests/testthat/test-pre-action-case-weights.R b/tests/testthat/test-pre-action-case-weights.R index 3b88f8f5..9ae39cb0 100644 --- a/tests/testthat/test-pre-action-case-weights.R +++ b/tests/testthat/test-pre-action-case-weights.R @@ -1,3 +1,5 @@ +skip_if_not_installed("recipes") + # ------------------------------------------------------------------------------ # add_case_weights() diff --git a/tests/testthat/test-pre-action-formula.R b/tests/testthat/test-pre-action-formula.R index b50fcbc0..8d513fdb 100644 --- a/tests/testthat/test-pre-action-formula.R +++ b/tests/testthat/test-pre-action-formula.R @@ -1,3 +1,5 @@ +skip_if_not_installed("recipes") + test_that("can add a formula to a workflow", { workflow <- workflow() workflow <- add_formula(workflow, mpg ~ cyl) diff --git a/tests/testthat/test-pre-action-recipe.R b/tests/testthat/test-pre-action-recipe.R index 2808af42..7f0e9280 100644 --- a/tests/testthat/test-pre-action-recipe.R +++ b/tests/testthat/test-pre-action-recipe.R @@ -1,3 +1,5 @@ +skip_if_not_installed("recipes") + test_that("can add a recipe to a workflow", { rec <- recipes::recipe(mpg ~ cyl, mtcars) diff --git a/tests/testthat/test-pre-action-variables.R b/tests/testthat/test-pre-action-variables.R index 495f6a26..227a4c15 100644 --- a/tests/testthat/test-pre-action-variables.R +++ b/tests/testthat/test-pre-action-variables.R @@ -1,3 +1,5 @@ +skip_if_not_installed("recipes") + test_that("can add variables to a workflow", { wf <- workflow() wf <- add_variables(wf, y, c(x1, x2)) diff --git a/tests/testthat/test-predict.R b/tests/testthat/test-predict.R index f548d8a5..5e9718c1 100644 --- a/tests/testthat/test-predict.R +++ b/tests/testthat/test-predict.R @@ -1,3 +1,5 @@ +skip_if_not_installed("recipes") + test_that("can predict from a workflow", { mod <- parsnip::linear_reg() mod <- parsnip::set_engine(mod, "lm") diff --git a/tests/testthat/test-printing.R b/tests/testthat/test-printing.R index e4d2f967..9ddc6ecd 100644 --- a/tests/testthat/test-printing.R +++ b/tests/testthat/test-printing.R @@ -1,3 +1,5 @@ +skip_if_not_installed("recipes") + test_that("can print empty workflow", { expect_snapshot(workflow()) }) diff --git a/tests/testthat/test-pull.R b/tests/testthat/test-pull.R index c8c949a3..a6bf4b33 100644 --- a/tests/testthat/test-pull.R +++ b/tests/testthat/test-pull.R @@ -1,3 +1,5 @@ +skip_if_not_installed("recipes") + # ------------------------------------------------------------------------------ # pull_workflow_preprocessor() diff --git a/tests/testthat/test-sparsevctrs.R b/tests/testthat/test-sparsevctrs.R index 671715c2..11161180 100644 --- a/tests/testthat/test-sparsevctrs.R +++ b/tests/testthat/test-sparsevctrs.R @@ -1,3 +1,5 @@ +skip_if_not_installed("recipes") + test_that("sparse tibble can be passed to `fit() - recipe", { skip_if_not_installed("glmnet") # Make materialization of sparse vectors throw an error @@ -140,7 +142,7 @@ test_that("sparse tibble can be passed to `predict()`", { add_model(spec) wf_fit <- fit(wf_spec, hotel_data) - + expect_no_error(predict(wf_fit, hotel_data)) }) @@ -166,7 +168,7 @@ test_that("sparse matrix can be passed to `predict()`", { suppressWarnings( wf_fit <- fit(wf_spec, hotel_data) ) - + expect_no_warning(predict(wf_fit, hotel_data)) }) diff --git a/tests/testthat/test-workflow.R b/tests/testthat/test-workflow.R index d9eaf6dc..56cc3646 100644 --- a/tests/testthat/test-workflow.R +++ b/tests/testthat/test-workflow.R @@ -1,3 +1,5 @@ +skip_if_not_installed("recipes") + # ------------------------------------------------------------------------------ # workflow()