From 93cce4fc06cdc5b509ed2e188860b3c8632d48ce Mon Sep 17 00:00:00 2001 From: olivroy Date: Tue, 5 Aug 2025 09:46:31 -0400 Subject: [PATCH] Add sp to suggests since leaflet will no longer import it by default. + add skips if not installed --- DESCRIPTION | 1 + tests/testthat/test-leafgl-addGlPolygons.R | 18 ++++++------ tests/testthat/test-leafgl-popup.R | 33 +++++++++++----------- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index d16e92e..600b3e6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -39,6 +39,7 @@ Imports: grDevices Suggests: colourvalues, + sp, shiny, testthat (>= 2.1.0) URL: https://github.com/r-spatial/leafgl, https://r-spatial.github.io/leafgl/ diff --git a/tests/testthat/test-leafgl-addGlPolygons.R b/tests/testthat/test-leafgl-addGlPolygons.R index c203ea3..3ee7983 100644 --- a/tests/testthat/test-leafgl-addGlPolygons.R +++ b/tests/testthat/test-leafgl-addGlPolygons.R @@ -22,7 +22,16 @@ test_that("addGlPolygons works", { addGlPolygons(data = single_poly, group = NULL, src = TRUE, digits = 5) expect_is(m, "leaflet") + ## Multi ######### + expect_error( + leaflet() %>% + addGlPolygons(data = gadm, digits = 5)) + expect_error( + leaflet() %>% + addGlPolygons(data = gadm, src = TRUE, digits = 5)) + ## Spatial Data ######### + skip_if_not_installed("sp") spatialdf <- as(single_poly, "Spatial") m = leaflet() %>% addGlPolygons(data = spatialdf, digits = 5) @@ -31,13 +40,4 @@ test_that("addGlPolygons works", { m = leaflet() %>% addGlPolygons(data = spatialdf, src = TRUE, digits = 5) expect_is(m, "leaflet") - - ## Multi ######### - expect_error( - leaflet() %>% - addGlPolygons(data = gadm, digits = 5)) - expect_error( - leaflet() %>% - addGlPolygons(data = gadm, src = TRUE, digits = 5)) - }) diff --git a/tests/testthat/test-leafgl-popup.R b/tests/testthat/test-leafgl-popup.R index e70fc7a..5014ce3 100644 --- a/tests/testthat/test-leafgl-popup.R +++ b/tests/testthat/test-leafgl-popup.R @@ -504,22 +504,23 @@ test_that("popup-lines-table", { }) test_that("popup-lines-spatial", { - popups <- suppressWarnings(sf::as_Spatial(storms)) - ## SpatialLinesDataFrame ############## + ## Simple Feature ############## + library(sf) m <- leaflet() %>% addTiles() %>% addGlPolylines(data = storms, - popup = popups, + popup = storms, opacity = 1) + expect_is(m, "leaflet") expect_true(yyjsonr::validate_json_str(m$x$calls[[2]]$args[[3]])) - ## Simple Feature ############## - library(sf) + skip_if_not_installed("sp") + popups <- suppressWarnings(sf::as_Spatial(storms)) + ## SpatialLinesDataFrame ############## m <- leaflet() %>% addTiles() %>% addGlPolylines(data = storms, - popup = storms, + popup = popups, opacity = 1) - expect_is(m, "leaflet") expect_true(yyjsonr::validate_json_str(m$x$calls[[2]]$args[[3]])) }) @@ -717,22 +718,22 @@ test_that("popup-polygon-table", { }) test_that("popup-polygon-spatial", { - ## SpatialPolygonsDataFrame ############## - popups <- suppressWarnings(sf::as_Spatial(gadm)) + ## Simple Feature ############## + library(sf) m <- leaflet() %>% addTiles() %>% addGlPolygons(data = gadm, - popup = popups, - opacity = 1) + popup = gadm, + opacity = 1) + expect_is(m, "leaflet") expect_true(yyjsonr::validate_json_str(m$x$calls[[2]]$args[[3]])) - - ## Simple Feature ############## - library(sf) + ## SpatialPolygonsDataFrame ############## + skip_if_not_installed("sp") + popups <- suppressWarnings(sf::as_Spatial(gadm)) m <- leaflet() %>% addTiles() %>% addGlPolygons(data = gadm, - popup = gadm, + popup = popups, opacity = 1) - expect_is(m, "leaflet") expect_true(yyjsonr::validate_json_str(m$x$calls[[2]]$args[[3]])) })