diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index 9310591f5..e990395f6 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -1,5 +1,4 @@ # for graph learner tests -loadNamespace("mlr3pipelines") loadNamespace("mlr3") # Create 6x6 point grid with 1m distance between points @@ -203,6 +202,8 @@ test_graph_learner = function(task, resampling, learner = "classif.featureless", measure = "classif.ce") { + loadNamespace("mlr3pipelines") + if (!is.null(time_var)) { task$set_col_roles(time_var, "time") task$set_col_roles(space_var, "space") diff --git a/tests/testthat/test-1-autoplot.R b/tests/testthat/test-1-autoplot.R index 35aed8079..f689ecb9c 100644 --- a/tests/testthat/test-1-autoplot.R +++ b/tests/testthat/test-1-autoplot.R @@ -1,6 +1,9 @@ # generic tests test_that("errors are thrown for non-valid argument settings", { + skip_if_not_installed("sf") + skip_if_not_installed("patchwork") + skip_if_not_installed("ggtext") task = test_make_twoclass_task() # type does not matter here rsp = rsmp("spcv_coords") @@ -454,6 +457,9 @@ test_that("plot() works for 'repeated_spcv_cstf'", { }) test_that("autoplot time + space", { + skip_if_not_installed("sf") + skip_if_not_installed("patchwork") + skip_if_not_installed("ggtext") # special data with five temporal levels data = cookfarm_sample b = mlr3::as_data_backend(data) diff --git a/tests/testthat/test-ResamplingRepeatedSpCVDisc.R b/tests/testthat/test-ResamplingRepeatedSpCVDisc.R index 8a9620ba1..37937a5f0 100644 --- a/tests/testthat/test-ResamplingRepeatedSpCVDisc.R +++ b/tests/testthat/test-ResamplingRepeatedSpCVDisc.R @@ -29,6 +29,7 @@ test_that("resampling iterations equals folds * repeats", { }) test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - radius + buffer", { + skip_if_not_installed("sperrorest") task = tsk("ecuador") set.seed(42) rsp = rsmp("repeated_spcv_disc", @@ -55,6 +56,7 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - radius + buffer" }) test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - radius", { + skip_if_not_installed("sperrorest") task = tsk("ecuador") set.seed(42) rsp = rsmp("repeated_spcv_disc", @@ -80,6 +82,7 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - radius", { }) test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - replace", { + skip_if_not_installed("sperrorest") task = tsk("ecuador") set.seed(42) rsp = rsmp("repeated_spcv_disc", diff --git a/tests/testthat/test-ResamplingRepeatedSpCVTiles.R b/tests/testthat/test-ResamplingRepeatedSpCVTiles.R index a68d66a9b..d70464dc6 100644 --- a/tests/testthat/test-ResamplingRepeatedSpCVTiles.R +++ b/tests/testthat/test-ResamplingRepeatedSpCVTiles.R @@ -1,4 +1,5 @@ test_that("folds can be printed", { + skip_if_not_installed("sperrorest") task = tsk("ecuador") rsp = rsmp("repeated_spcv_tiles", repeats = 2, nsplit = c(4L, 3L), reassign = FALSE) @@ -8,6 +9,7 @@ test_that("folds can be printed", { }) test_that("reps can be printed", { + skip_if_not_installed("sperrorest") task = tsk("ecuador") rsp = rsmp("repeated_spcv_tiles", repeats = 5, nsplit = c(4L, 3L), reassign = FALSE) @@ -17,6 +19,7 @@ test_that("reps can be printed", { }) test_that("resampling iterations equals folds * repeats", { + skip_if_not_installed("sperrorest") task = tsk("ecuador") rsp = rsmp("repeated_spcv_tiles", repeats = 2, reassign = FALSE, nsplit = c(4L, 3L)) @@ -26,6 +29,7 @@ test_that("resampling iterations equals folds * repeats", { }) test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - nsplit + dsplit", { + skip_if_not_installed("sperrorest") task = tsk("ecuador") set.seed(42) rsp = rsmp("repeated_spcv_tiles", @@ -50,6 +54,7 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - nsplit + dsplit" }) test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - reassign", { + skip_if_not_installed("sperrorest") task = tsk("ecuador") set.seed(42) rsp = rsmp("repeated_spcv_tiles", @@ -73,6 +78,7 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - reassign", { }) test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - user_rotation", { + skip_if_not_installed("sperrorest") task = tsk("ecuador") set.seed(42) rsp = rsmp("repeated_spcv_tiles", @@ -98,6 +104,7 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - user_rotation", }) test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - random rotation", { + skip_if_not_installed("sperrorest") task = tsk("ecuador") set.seed(42) rsp = rsmp("repeated_spcv_tiles", @@ -123,6 +130,7 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - random rotation" }) test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - random offset", { + skip_if_not_installed("sperrorest") task = tsk("ecuador") set.seed(42) rsp = rsmp("repeated_spcv_tiles", @@ -148,6 +156,7 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - random offset", }) test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - user offset", { + skip_if_not_installed("sperrorest") task = tsk("ecuador") set.seed(42) rsp = rsmp("repeated_spcv_tiles", diff --git a/tests/testthat/test-ResamplingSpCVBlock.R b/tests/testthat/test-ResamplingSpCVBlock.R index af7991ddc..976b7ec21 100644 --- a/tests/testthat/test-ResamplingSpCVBlock.R +++ b/tests/testthat/test-ResamplingSpCVBlock.R @@ -73,6 +73,7 @@ test_that("mlr3spatiotempcv indices are the same as blockCV indices: selection = }) test_that("mlr3spatiotempcv indices are the same as blockCV indices: cols and rows", { + skip_if_not_installed("sf") task = test_make_blockCV_test_task() sf::sf_use_s2(use_s2 = FALSE) @@ -102,6 +103,7 @@ test_that("mlr3spatiotempcv indices are the same as blockCV indices: cols and ro }) test_that("mlr3spatiotempcv indices are the same as blockCV indices: rasterLayer", { + skip_if_not_installed("sf") # cran test failure (Error: no arguments in initialization list) testthat::skip_on_os("solaris") @@ -140,6 +142,7 @@ test_that("mlr3spatiotempcv indices are the same as blockCV indices: rasterLayer }) test_that("Error when selection = checkboard and folds > 2", { + skip_if_not_installed("sf") task = test_make_blockCV_test_task() expect_error(rsmp("spcv_block", range = 10000L, selection = "checkerboard", folds = 5)$instantiate(task)) diff --git a/tests/testthat/test-ResamplingSpCVDisc.R b/tests/testthat/test-ResamplingSpCVDisc.R index a995ad002..6991b0e80 100644 --- a/tests/testthat/test-ResamplingSpCVDisc.R +++ b/tests/testthat/test-ResamplingSpCVDisc.R @@ -1,4 +1,5 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated)", { + skip_if_not_installed("sperrorest") task = tsk("ecuador") set.seed(42) rsp = rsmp("spcv_disc", folds = 3L, radius = 200L, buffer = 200L) diff --git a/tests/testthat/test-ResamplingSpCVTiles.R b/tests/testthat/test-ResamplingSpCVTiles.R index 48872cbe9..0b0660974 100644 --- a/tests/testthat/test-ResamplingSpCVTiles.R +++ b/tests/testthat/test-ResamplingSpCVTiles.R @@ -1,4 +1,5 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated)", { + skip_if_not_installed("sperrorest") task = tsk("ecuador") set.seed(42) rsp = rsmp("spcv_tiles", reassign = FALSE, nsplit = c(4L, 3L)) @@ -21,6 +22,7 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated)", { }) test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - nsplit + dsplit", { + skip_if_not_installed("sperrorest") task = tsk("ecuador") set.seed(42) rsp = rsmp("spcv_tiles", @@ -44,6 +46,7 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - nsplit + dsplit" }) test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - reassign", { + skip_if_not_installed("sperrorest") task = tsk("ecuador") set.seed(42) rsp = rsmp("spcv_tiles", @@ -67,6 +70,7 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - reassign", { }) test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - user_rotation", { + skip_if_not_installed("sperrorest") task = tsk("ecuador") set.seed(42) rsp = rsmp("spcv_tiles", @@ -92,6 +96,7 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - user_rotation", }) test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - random rotation", { + skip_if_not_installed("sperrorest") task = tsk("ecuador") set.seed(42) rsp = rsmp("spcv_tiles", @@ -117,6 +122,7 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - random rotation" }) test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - random offset", { + skip_if_not_installed("sperrorest") task = tsk("ecuador") set.seed(42) rsp = rsmp("spcv_tiles", @@ -142,6 +148,7 @@ test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - random offset", }) test_that("mlr3spatiotempcv is equal to sperrorest (repeated) - user offset", { + skip_if_not_installed("sperrorest") task = tsk("ecuador") set.seed(42) rsp = rsmp("spcv_tiles", diff --git a/tests/testthat/test-TaskClassifST.R b/tests/testthat/test-TaskClassifST.R index 182794d2c..6a52fb777 100644 --- a/tests/testthat/test-TaskClassifST.R +++ b/tests/testthat/test-TaskClassifST.R @@ -25,6 +25,7 @@ test_that("coordinates can be used as features", { }) test_that("sf objects can be used for task creation", { + skip_if_not_installed("sf") task = test_make_sf_twoclass_task() expect_output(print(task)) @@ -33,6 +34,7 @@ test_that("sf objects can be used for task creation", { }) test_that("sf objects can be used for task creation", { + skip_if_not_installed("sf") task = test_make_sf_regr_task() expect_output(print(task)) @@ -42,6 +44,7 @@ test_that("sf objects can be used for task creation", { # https://github.com/mlr-org/mlr3spatiotempcv/issues/151 test_that("tasks created from sf objects do not duplicate rows", { + skip_if_not_installed("sf") data = test_make_sf_twoclass_df() task = TaskClassifST$new( diff --git a/tests/testthat/test-as_task.R b/tests/testthat/test-as_task.R index 1f7b59ae5..75fca4c8a 100644 --- a/tests/testthat/test-as_task.R +++ b/tests/testthat/test-as_task.R @@ -18,6 +18,7 @@ test_that("as_task_classif_st.data.rame works", { }) test_that("as_task_classif_st.sf works", { + skip_if_not_installed("sf") data("ecuador", package = "mlr3spatiotempcv") ecuador_sf = sf::st_as_sf(ecuador, coords = c("x", "y"), crs = "epsg:32717") new_task = as_task_classif_st(ecuador_sf, target = "slides", positive = "TRUE") @@ -48,6 +49,7 @@ test_that("as_task_regr_st.data.rame works", { }) test_that("as_task_regr_st.sf works", { + skip_if_not_installed("sf") data("cookfarm_sample", package = "mlr3spatiotempcv") cookfarm_sf = sf::st_as_sf(cookfarm_sample, coords = c("x", "y"), crs = 26911) new_task = as_task_regr_st(cookfarm_sf, target = "PHIHOX") diff --git a/tests/testthat/test-autotuner.R b/tests/testthat/test-autotuner.R index e59a3808f..fe8795a96 100644 --- a/tests/testthat/test-autotuner.R +++ b/tests/testthat/test-autotuner.R @@ -1,4 +1,8 @@ test_that("AutoTuner works with sptcv methods", { + + skip_if_not_installed("mlr3tuning") + skip_if_not_installed("paradox") + library("paradox") library("mlr3tuning") library("mlr3spatiotempcv") diff --git a/tests/testthat/test-helper-DataBackend.R b/tests/testthat/test-helper-DataBackend.R index 0844075b0..f0da469a4 100644 --- a/tests/testthat/test-helper-DataBackend.R +++ b/tests/testthat/test-helper-DataBackend.R @@ -1,6 +1,7 @@ test_that("get_coordinates function works", { skip_if_not_installed("mlr3spatial") + skip_if_not_installed("sf") requireNamespace("mlr3spatial", quietly = TRUE) task_1 = tsk("ecuador") @@ -15,6 +16,7 @@ test_that("get_coordinates function works", { test_that("get_crs function works", { skip_if_not_installed("mlr3spatial") + skip_if_not_installed("sf") requireNamespace("mlr3spatial", quietly = TRUE) task_1 = tsk("ecuador") @@ -30,6 +32,7 @@ test_that("get_crs function works", { test_that("assert_spatial_task function works", { skip_if_not_installed("mlr3spatial") + skip_if_not_installed("sf") requireNamespace("mlr3spatial", quietly = TRUE) task_1 = tsk("ecuador") diff --git a/tests/testthat/test-mlr_sptcv_generic.R b/tests/testthat/test-mlr_sptcv_generic.R index 99e17db98..fb107512b 100644 --- a/tests/testthat/test-mlr_sptcv_generic.R +++ b/tests/testthat/test-mlr_sptcv_generic.R @@ -1,6 +1,8 @@ library(mlr3) test_that("no duplicated ids", { + skip_if_not_installed("blockCV") + skip_if_not_installed("sf") spcv_rsp = mlr_resamplings$mget( as.data.table(mlr_resamplings)[map_lgl(key, grepl, pattern = "spcv"), key] ) @@ -17,6 +19,8 @@ test_that("no duplicated ids", { }) test_that("grouping throws errors when 'groups' is set", { + skip_if_not_installed("blockCV") + skip_if_not_installed("sf") task = test_make_twoclass_task(group = TRUE) spcv_rsp = rsmps(c("spcv_coords", "spcv_env"), folds = 2) @@ -31,6 +35,8 @@ test_that("grouping throws errors when 'groups' is set", { }) test_that("train and test set getter functions are working", { + skip_if_not_installed("blockCV") + skip_if_not_installed("sf") task = test_make_twoclass_task() spcv_rsp = rsmps(c("spcv_coords", "spcv_env"), folds = 2) @@ -45,6 +51,8 @@ test_that("train and test set getter functions are working", { }) test_that("train and test set getter functions are working", { + skip_if_not_installed("blockCV") + skip_if_not_installed("sf") task = test_make_twoclass_task() spcv_rsp = rsmps(c("repeated_spcv_coords", "repeated_spcv_env"), folds = 2)