From b9febd6baa565fc4910454b29824d08503b3a314 Mon Sep 17 00:00:00 2001 From: Hannah Frick Date: Wed, 24 Jan 2024 15:40:33 +0000 Subject: [PATCH] also check without suggested packages (#306) * also check without suggested packages * skips for suggested pkgs * examples only when engine pkgs available --- .github/workflows/R-CMD-check-hard.yaml | 57 +++++++++++++++++++ R/bag_tree-rpart.R | 4 +- R/boost_tree-mboost.R | 6 +- R/decision_tree-rpart.R | 2 +- R/partykit.R | 2 +- R/proportional_hazards-glmnet.R | 6 +- R/rand_forest-aorsf.R | 2 +- README.Rmd | 1 + README.md | 1 + man/aorsf_internal.Rd | 2 + man/blackboost_train.Rd | 2 + man/coxnet_train.Rd | 2 + man/survival_prob_coxnet.Rd | 2 + man/survival_prob_mboost.Rd | 2 + man/survival_prob_partykit.Rd | 2 + man/survival_prob_pecRpart.Rd | 2 + man/survival_prob_survbagg.Rd | 2 + man/survival_time_coxnet.Rd | 2 + man/survival_time_mboost.Rd | 2 + man/survival_time_survbagg.Rd | 2 + tests/testthat/test-bag_tree-rpart.R | 1 + .../test-proportional_hazards-survival.R | 1 + 22 files changed, 94 insertions(+), 11 deletions(-) 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..1c899169 --- /dev/null +++ b/.github/workflows/R-CMD-check-hard.yaml @@ -0,0 +1,57 @@ +# 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: R-CMD-check-hard + +jobs: + R-CMD-check: + 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@v3 + + - 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 diff --git a/R/bag_tree-rpart.R b/R/bag_tree-rpart.R index 7ff61632..a035920c 100644 --- a/R/bag_tree-rpart.R +++ b/R/bag_tree-rpart.R @@ -4,7 +4,7 @@ #' @return A vector. #' @keywords internal #' @export -#' @examples +#' @examplesIf rlang::is_installed("ipred") #' bagged_tree <- bag_tree() %>% #' set_engine("rpart") %>% #' set_mode("censored regression") %>% @@ -61,7 +61,7 @@ get_missings_survbagg <- function(object, new_data) { #' @return A vctrs list of tibbles. #' @keywords internal #' @export -#' @examples +#' @examplesIf rlang::is_installed("ipred") #' bagged_tree <- bag_tree() %>% #' set_engine("rpart") %>% #' set_mode("censored regression") %>% diff --git a/R/boost_tree-mboost.R b/R/boost_tree-mboost.R index ef8e9c2f..b432555e 100644 --- a/R/boost_tree-mboost.R +++ b/R/boost_tree-mboost.R @@ -31,7 +31,7 @@ #' @return A fitted blackboost model. #' @keywords internal #' @export -#' @examples +#' @examplesIf rlang::is_installed("mboost") #' blackboost_train(Surv(time, status) ~ age + ph.ecog, #' data = lung[-14, ], family = mboost::CoxPH() #' ) @@ -111,7 +111,7 @@ predict_linear_pred._blackboost <- function(object, #' @return A tibble with a list column of nested tibbles. #' @keywords internal #' @export -#' @examples +#' @examplesIf rlang::is_installed("mboost") #' mod <- boost_tree() %>% #' set_engine("mboost") %>% #' set_mode("censored regression") %>% @@ -176,7 +176,7 @@ survival_curve_to_prob <- function(eval_time, event_times, survival_prob) { #' @return A tibble. #' @keywords internal #' @export -#' @examples +#' @examplesIf rlang::is_installed("mboost") #' boosted_tree <- boost_tree() %>% #' set_engine("mboost") %>% #' set_mode("censored regression") %>% diff --git a/R/decision_tree-rpart.R b/R/decision_tree-rpart.R index a44bcc36..f45321d4 100644 --- a/R/decision_tree-rpart.R +++ b/R/decision_tree-rpart.R @@ -5,7 +5,7 @@ #' @return A tibble with a list column of nested tibbles. #' @keywords internal #' @export -#' @examples +#' @examplesIf rlang::is_installed("pec") #' mod <- decision_tree() %>% #' set_mode("censored regression") %>% #' set_engine("rpart") %>% diff --git a/R/partykit.R b/R/partykit.R index e4898dde..75230229 100644 --- a/R/partykit.R +++ b/R/partykit.R @@ -9,7 +9,7 @@ #' @return A tibble with a list column of nested tibbles. #' @export #' @keywords internal -#' @examples +#' @examplesIf rlang::is_installed(c("partykit", "coin")) #' tree <- decision_tree() %>% #' set_mode("censored regression") %>% #' set_engine("partykit") %>% diff --git a/R/proportional_hazards-glmnet.R b/R/proportional_hazards-glmnet.R index 484ecd88..ae5a2e81 100644 --- a/R/proportional_hazards-glmnet.R +++ b/R/proportional_hazards-glmnet.R @@ -23,7 +23,7 @@ #' @return A fitted `glmnet` model. #' @export #' @keywords internal -#' @examples +#' @examplesIf rlang::is_installed("glmnet") #' coxnet_mod <- coxnet_train(Surv(time, status) ~ age + sex, data = lung) coxnet_train <- function(formula, data, @@ -471,7 +471,7 @@ multi_predict_coxnet_linear_pred <- function(object, new_data, opts, penalty) { #' @return A vector. #' @keywords internal #' @export -#' @examples +#' @examplesIf rlang::is_installed("glmnet") #' cox_mod <- proportional_hazards(penalty = 0.1) %>% #' set_engine("glmnet") %>% #' fit(Surv(time, status) ~ ., data = lung) @@ -596,7 +596,7 @@ get_missings_coxnet <- function(new_x, new_strata) { #' @return A tibble with a list column of nested tibbles. #' @keywords internal #' @export -#' @examples +#' @examplesIf rlang::is_installed("glmnet") #' cox_mod <- proportional_hazards(penalty = 0.1) %>% #' set_engine("glmnet") %>% #' fit(Surv(time, status) ~ ., data = lung) diff --git a/R/rand_forest-aorsf.R b/R/rand_forest-aorsf.R index bad4b1bd..cf2df297 100644 --- a/R/rand_forest-aorsf.R +++ b/R/rand_forest-aorsf.R @@ -8,7 +8,7 @@ #' @export #' @keywords internal #' @name aorsf_internal -#' @examples +#' @examplesIf rlang::is_installed("aorsf") #' mod <- rand_forest() %>% #' set_engine("aorsf") %>% #' set_mode("censored regression") %>% diff --git a/README.Rmd b/README.Rmd index 7fb14ed7..53ba3cba 100644 --- a/README.Rmd +++ b/README.Rmd @@ -19,6 +19,7 @@ knitr::opts_chunk$set( [![R-CMD-check](https://github.com/tidymodels/censored/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/tidymodels/censored/actions/workflows/R-CMD-check.yaml) [![Codecov test coverage](https://codecov.io/gh/tidymodels/censored/branch/main/graph/badge.svg)](https://app.codecov.io/gh/tidymodels/censored?branch=main) [![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html) +[![R-CMD-check-hard](https://github.com/tidymodels/censored/actions/workflows/R-CMD-check-hard.yaml/badge.svg)](https://github.com/tidymodels/censored/actions/workflows/R-CMD-check-hard.yaml) `censored` is a [parsnip](https://parsnip.tidymodels.org) extension package which provides engines for various models for censored regression and survival analysis. diff --git a/README.md b/README.md index 21b53ddd..ed5fd07e 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ coverage](https://codecov.io/gh/tidymodels/censored/branch/main/graph/badge.svg)](https://app.codecov.io/gh/tidymodels/censored?branch=main) [![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html) +[![R-CMD-check-hard](https://github.com/tidymodels/censored/actions/workflows/R-CMD-check-hard.yaml/badge.svg)](https://github.com/tidymodels/censored/actions/workflows/R-CMD-check-hard.yaml) `censored` is a [parsnip](https://parsnip.tidymodels.org) extension diff --git a/man/aorsf_internal.Rd b/man/aorsf_internal.Rd index 5fe4fc29..41df6734 100644 --- a/man/aorsf_internal.Rd +++ b/man/aorsf_internal.Rd @@ -24,10 +24,12 @@ A tibble with a list column of nested tibbles. Internal helper function for aorsf objects } \examples{ +\dontshow{if (rlang::is_installed("aorsf")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} mod <- rand_forest() \%>\% set_engine("aorsf") \%>\% set_mode("censored regression") \%>\% fit(Surv(time, status) ~ age + ph.ecog, data = na.omit(lung)) preds <- survival_prob_orsf(mod, lung[1:3, ], eval_time = c(250, 100)) +\dontshow{\}) # examplesIf} } \keyword{internal} diff --git a/man/blackboost_train.Rd b/man/blackboost_train.Rd index cccc71c4..fd8ebd2a 100644 --- a/man/blackboost_train.Rd +++ b/man/blackboost_train.Rd @@ -63,8 +63,10 @@ A fitted blackboost model. where all of the model arguments are in the main function. } \examples{ +\dontshow{if (rlang::is_installed("mboost")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} blackboost_train(Surv(time, status) ~ age + ph.ecog, data = lung[-14, ], family = mboost::CoxPH() ) +\dontshow{\}) # examplesIf} } \keyword{internal} diff --git a/man/coxnet_train.Rd b/man/coxnet_train.Rd index ce669c9b..6c0f1fa7 100644 --- a/man/coxnet_train.Rd +++ b/man/coxnet_train.Rd @@ -59,6 +59,8 @@ The wrapper retains the original formula and the pre-processing elements including the training data to allow for predictions from the fitted model. } \examples{ +\dontshow{if (rlang::is_installed("glmnet")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} coxnet_mod <- coxnet_train(Surv(time, status) ~ age + sex, data = lung) +\dontshow{\}) # examplesIf} } \keyword{internal} diff --git a/man/survival_prob_coxnet.Rd b/man/survival_prob_coxnet.Rd index 8a51779f..58396fa8 100644 --- a/man/survival_prob_coxnet.Rd +++ b/man/survival_prob_coxnet.Rd @@ -40,9 +40,11 @@ A tibble with a list column of nested tibbles. A wrapper for survival probabilities with coxnet models } \examples{ +\dontshow{if (rlang::is_installed("glmnet")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cox_mod <- proportional_hazards(penalty = 0.1) \%>\% set_engine("glmnet") \%>\% fit(Surv(time, status) ~ ., data = lung) survival_prob_coxnet(cox_mod, new_data = lung[1:3, ], eval_time = 300) +\dontshow{\}) # examplesIf} } \keyword{internal} diff --git a/man/survival_prob_mboost.Rd b/man/survival_prob_mboost.Rd index b3d137e3..fcdfb7a8 100644 --- a/man/survival_prob_mboost.Rd +++ b/man/survival_prob_mboost.Rd @@ -22,10 +22,12 @@ A tibble with a list column of nested tibbles. A wrapper for survival probabilities with mboost models } \examples{ +\dontshow{if (rlang::is_installed("mboost")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} mod <- boost_tree() \%>\% set_engine("mboost") \%>\% set_mode("censored regression") \%>\% fit(Surv(time, status) ~ ., data = lung) survival_prob_mboost(mod, new_data = lung[1:3, ], eval_time = 300) +\dontshow{\}) # examplesIf} } \keyword{internal} diff --git a/man/survival_prob_partykit.Rd b/man/survival_prob_partykit.Rd index 50edfe77..9f122286 100644 --- a/man/survival_prob_partykit.Rd +++ b/man/survival_prob_partykit.Rd @@ -32,6 +32,7 @@ A tibble with a list column of nested tibbles. A wrapper for survival probabilities with partykit models } \examples{ +\dontshow{if (rlang::is_installed(c("partykit", "coin"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} tree <- decision_tree() \%>\% set_mode("censored regression") \%>\% set_engine("partykit") \%>\% @@ -42,5 +43,6 @@ forest <- rand_forest() \%>\% set_engine("partykit") \%>\% fit(Surv(time, status) ~ age + ph.ecog, data = lung) survival_prob_partykit(forest, lung[1:3, ], eval_time = 100) +\dontshow{\}) # examplesIf} } \keyword{internal} diff --git a/man/survival_prob_pecRpart.Rd b/man/survival_prob_pecRpart.Rd index f15e2fc7..18a3483c 100644 --- a/man/survival_prob_pecRpart.Rd +++ b/man/survival_prob_pecRpart.Rd @@ -20,10 +20,12 @@ A tibble with a list column of nested tibbles. A wrapper for survival probabilities with pecRpart models } \examples{ +\dontshow{if (rlang::is_installed("pec")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} mod <- decision_tree() \%>\% set_mode("censored regression") \%>\% set_engine("rpart") \%>\% fit(Surv(time, status) ~ ., data = lung) survival_prob_pecRpart(mod, new_data = lung[1:3, ], eval_time = 300) +\dontshow{\}) # examplesIf} } \keyword{internal} diff --git a/man/survival_prob_survbagg.Rd b/man/survival_prob_survbagg.Rd index 6c478c61..5a906f14 100644 --- a/man/survival_prob_survbagg.Rd +++ b/man/survival_prob_survbagg.Rd @@ -22,10 +22,12 @@ A vctrs list of tibbles. A wrapper for survival probabilities with \code{survbagg} models } \examples{ +\dontshow{if (rlang::is_installed("ipred")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} bagged_tree <- bag_tree() \%>\% set_engine("rpart") \%>\% set_mode("censored regression") \%>\% fit(Surv(time, status) ~ age + ph.ecog, data = lung) survival_prob_survbagg(bagged_tree, lung[1:3, ], eval_time = 100) +\dontshow{\}) # examplesIf} } \keyword{internal} diff --git a/man/survival_time_coxnet.Rd b/man/survival_time_coxnet.Rd index 1e8cd6d8..8611f575 100644 --- a/man/survival_time_coxnet.Rd +++ b/man/survival_time_coxnet.Rd @@ -25,9 +25,11 @@ A vector. A wrapper for survival times with coxnet models } \examples{ +\dontshow{if (rlang::is_installed("glmnet")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cox_mod <- proportional_hazards(penalty = 0.1) \%>\% set_engine("glmnet") \%>\% fit(Surv(time, status) ~ ., data = lung) survival_time_coxnet(cox_mod, new_data = lung[1:3, ], penalty = 0.1) +\dontshow{\}) # examplesIf} } \keyword{internal} diff --git a/man/survival_time_mboost.Rd b/man/survival_time_mboost.Rd index 119f5f5e..fb4126de 100644 --- a/man/survival_time_mboost.Rd +++ b/man/survival_time_mboost.Rd @@ -18,10 +18,12 @@ A tibble. A wrapper for mean survival times with \code{mboost} models } \examples{ +\dontshow{if (rlang::is_installed("mboost")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} boosted_tree <- boost_tree() \%>\% set_engine("mboost") \%>\% set_mode("censored regression") \%>\% fit(Surv(time, status) ~ age + ph.ecog, data = lung[-14, ]) survival_time_mboost(boosted_tree, new_data = lung[1:3, ]) +\dontshow{\}) # examplesIf} } \keyword{internal} diff --git a/man/survival_time_survbagg.Rd b/man/survival_time_survbagg.Rd index 02237cd0..8713b5a6 100644 --- a/man/survival_time_survbagg.Rd +++ b/man/survival_time_survbagg.Rd @@ -18,10 +18,12 @@ A vector. A wrapper for survival times with \code{survbagg} models } \examples{ +\dontshow{if (rlang::is_installed("ipred")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} bagged_tree <- bag_tree() \%>\% set_engine("rpart") \%>\% set_mode("censored regression") \%>\% fit(Surv(time, status) ~ age + ph.ecog, data = lung) survival_time_survbagg(bagged_tree, lung[1:3, ]) +\dontshow{\}) # examplesIf} } \keyword{internal} diff --git a/tests/testthat/test-bag_tree-rpart.R b/tests/testthat/test-bag_tree-rpart.R index a7e6aef3..963f19d5 100644 --- a/tests/testthat/test-bag_tree-rpart.R +++ b/tests/testthat/test-bag_tree-rpart.R @@ -87,6 +87,7 @@ test_that("time predictions without surrogate splits for NA", { }) test_that("survival_time_survbagg() throws an informative error with an engine object", { + skip_if_not_installed("ipred") mod <- ipred::bagging(Surv(time, status) ~ age + ph.ecog, data = lung) expect_snapshot(error = TRUE, { survival_time_survbagg(mod) diff --git a/tests/testthat/test-proportional_hazards-survival.R b/tests/testthat/test-proportional_hazards-survival.R index c8d0944f..67f0b423 100644 --- a/tests/testthat/test-proportional_hazards-survival.R +++ b/tests/testthat/test-proportional_hazards-survival.R @@ -156,6 +156,7 @@ test_that("prediction from stratified models require strata variables in new_dat # prediction: survival ---------------------------------------------------- test_that("survival predictions without strata", { + skip_if_not_installed("pec") # due to pec: skip_if_not_installed("Matrix", minimum_version = "1.4.2")