Skip to content

Commit

Permalink
Optionally skip tests relying on Suggests deps (#1337)
Browse files Browse the repository at this point in the history
* Optionally skip tests relying on Suggests deps

* Update test_misc.R

---------

Co-authored-by: topepo <[email protected]>
  • Loading branch information
MichaelChirico and topepo authored Nov 25, 2024
1 parent 5d71315 commit 21d34a5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 23 deletions.
3 changes: 3 additions & 0 deletions pkg/caret/tests/testthat/test_misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ test_that("R2 and RMSE are calculating correctly", {


test_that("auc calculation is > .5 when Xs provide prediction", {
skip_if_not_installed("MLmetrics")
skip_if_not_installed("earth")
skip_if_not_installed("mda")

trCntlListMulti <-
trainControl(
Expand Down
2 changes: 2 additions & 0 deletions pkg/caret/tests/testthat/test_multiclassSummary.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
context('multiClassSummary')

test_that("multiClassSummary presenting warnings from train", {
skip_if_not_installed("MLmetrics")
skip_if_not_installed("ModelMetrics", "1.2.2.2")
library(caret)
N = 1000
Expand Down Expand Up @@ -38,6 +39,7 @@ test_that("multiClassSummary presenting warnings from train", {
})

test_that("multiClassSummary ROC values", {
skip_if_not_installed("MLmetrics")

lvls <- levels(iris$Species)
set.seed(46337)
Expand Down
9 changes: 2 additions & 7 deletions pkg/caret/tests/testthat/test_preProcess_methods.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
library(caret)
library(fastICA)
library(testthat)
library(MASS)

context('preProcess/methods')

###################################################################
Expand Down Expand Up @@ -186,6 +181,7 @@ test_that('issue #825 for pca threshold choice', {
## test ica

test_that('ICA trans', {
skip_if_not_installed("fastICA")
skip_on_cran()
set.seed(1)
ica_dat1 <- twoClassSim(30)[, 1:5]
Expand All @@ -202,8 +198,7 @@ test_that('ICA trans', {
ica_dat2_scaled[,i] <- (ica_dat2_scaled[,i]-ica_dat1_means[i])/ica_dat1_sds[i]

set.seed(1)
ic_obj <- fastICA(scale(ica_dat1, center = TRUE, scale = TRUE),
n.comp = 3)
ic_obj <- fastICA::fastICA(scale(ica_dat1, center = TRUE, scale = TRUE), n.comp = 3)
ica_dat2_exp <- as.matrix(ica_dat2_scaled) %*% ic_obj$K %*% ic_obj$W
colnames(ica_dat2_exp) <- paste("ICA", 1:ncol(ic_obj$W), sep = "")
expect_equal(as.data.frame(ica_dat2_exp, stringsAsFactors = TRUE), ica_dat2_ica, tolerance = .00001)
Expand Down
23 changes: 7 additions & 16 deletions pkg/caret/tests/testthat/test_recipe_upsample.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@

library(testthat)
library(caret)
library(themis)

context('upsampling with recipes')

# ------------------------------------------------------------------------------

set.seed(2542)
dat <- twoClassSim(200, intercept = 6)

# ------------------------------------------------------------------------------

rec <-
recipe(Class ~ TwoFactor1 + TwoFactor2 + Linear01, data = dat) %>%
themis::step_upsample(Class, seed = 534)
test_that("model test", {
skip_if_not_installed("themis")
withr::local_seed(2542)
dat <- twoClassSim(200, intercept = 6)

rec <-
recipe(Class ~ TwoFactor1 + TwoFactor2 + Linear01, data = dat) %>%
themis::step_upsample(Class, seed = 534)

test_that("model test", {
mod <- train(rec, dat, method = "knn", trControl = trainControl(method = "cv"))
expect_equivalent(
rep(max(table(dat$Class)), 2),
Expand Down

0 comments on commit 21d34a5

Please sign in to comment.