Skip to content

Commit

Permalink
Skip s2-requiring-tests if no s2 (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemahoney218 authored Jan 4, 2023
1 parent 6e844ff commit 1173ebd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions tests/testthat/test-autoplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ skip_if_not_installed("vdiffr")
data(ames, package = "modeldata")

test_that("autoplot is stable", {
skip_if_not(sf::sf_use_s2())

ames_sf <- sf::st_as_sf(ames, coords = c("Longitude", "Latitude"), crs = 4326)
set.seed(123)
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-spatial_block_cv.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ test_that("random assignment", {
})

test_that("repeated", {
skip_if_not(sf::sf_use_s2())
set.seed(11)
rs2 <- spatial_block_cv(ames_sf, repeats = 2)

Expand Down Expand Up @@ -173,6 +174,7 @@ test_that("systematic assignment -- continuous", {
})

test_that("polygons are only assigned one fold", {
skip_if_not(sf::sf_use_s2())
set.seed(11)

rs1 <- spatial_block_cv(boston_canopy, method = "continuous")
Expand Down Expand Up @@ -209,6 +211,7 @@ test_that("polygons are only assigned one fold", {
})

test_that("blocks are filtered based on centroids", {
skip_if_not(sf::sf_use_s2())
set.seed(123)
rs1 <- spatial_block_cv(boston_canopy, v = 18, cellsize = 15000)
expect_true(
Expand Down
9 changes: 8 additions & 1 deletion tests/testthat/test-spatial_clustering_cv.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Smithsonian_sf <- sf::st_as_sf(
)

test_that("repeats", {
skip_if_not(sf::sf_use_s2())
set.seed(11)
rs1 <- spatial_clustering_cv(
Smithsonian_sf,
Expand Down Expand Up @@ -38,6 +39,7 @@ test_that("repeats", {
})

test_that("using hclust", {
skip_if_not(sf::sf_use_s2())
set.seed(11)
rs1 <- spatial_clustering_cv(
Smithsonian_sf,
Expand Down Expand Up @@ -94,6 +96,7 @@ test_that("bad args", {
})

test_that("can pass the dots to kmeans", {
skip_if_not(sf::sf_use_s2())
expect_error(
spatial_clustering_cv(
Smithsonian_sf,
Expand All @@ -105,7 +108,7 @@ test_that("can pass the dots to kmeans", {
})

test_that("using sf", {

skip_if_not(sf::sf_use_s2())
set.seed(11)
rs1 <- spatial_clustering_cv(
Smithsonian_sf,
Expand Down Expand Up @@ -152,6 +155,7 @@ test_that("using sf", {
})

test_that("using custom functions", {
skip_if_not(sf::sf_use_s2())
custom_cluster <- function(dists, v, ...) {
clusters <- kmeans(dists, centers = v, ...)
letters[clusters$cluster]
Expand Down Expand Up @@ -182,6 +186,7 @@ test_that("using custom functions", {
})

test_that("polygons are only assigned one fold", {
skip_if_not(sf::sf_use_s2())
set.seed(11)

rs1 <- spatial_clustering_cv(boston_canopy, cluster_function = "hclust")
Expand Down Expand Up @@ -211,6 +216,7 @@ test_that("polygons are only assigned one fold", {
})

test_that("printing", {
skip_if_not(sf::sf_use_s2())
# The default RNG changed in 3.6.0
skip_if_not(getRversion() >= numeric_version("3.6.0"))
set.seed(123)
Expand All @@ -223,6 +229,7 @@ test_that("printing", {
})

test_that("rsplit labels", {
skip_if_not(sf::sf_use_s2())
rs <- spatial_clustering_cv(Smithsonian_sf, v = 2)
all_labs <- map_df(rs$splits, labels)
original_id <- rs[, grepl("^id", names(rs))]
Expand Down

0 comments on commit 1173ebd

Please sign in to comment.