Skip to content

Commit aa750b0

Browse files
committed
shouldn't assume sf is installed
1 parent 8f1950b commit aa750b0

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

R/add.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ add_polygons <- function(p, x = NULL, y = NULL, ...,
228228
#' plot_ly() %>% add_sf(data = nc)
229229
#' }
230230
add_sf <- function(p, ..., x = ~x, y = ~y, data = NULL, inherit = TRUE) {
231+
try_library("sf", "add_sf")
231232
dat <- plotly_data(add_data(p, data))
232233
if (!is_sf(dat)) {
233234
stop(

tests/testthat/test-plotly-sf.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ test_that("plot_ly() defaults to blank axes", {
113113
})
114114

115115
test_that("discrete color informs fillcolor", {
116+
skip_if_not_installed("sf")
117+
116118
res <- unique(res_mn$INDRESNAME)
117119
cols <- viridisLite::magma(length(res))
118120

@@ -132,6 +134,8 @@ test_that("discrete color informs fillcolor", {
132134

133135

134136
test_that("discrete color informs fillcolor", {
137+
skip_if_not_installed("sf")
138+
135139
res <- unique(res_mn$INDRESNAME)
136140
cols <- viridisLite::magma(length(res))
137141

@@ -166,6 +170,7 @@ test_that("discrete color informs fillcolor", {
166170

167171

168172
test_that("numeric color informs fillcolor", {
173+
skip_if_not_installed("sf")
169174

170175
p <- plot_mapbox(res_mn, color = ~AREA)
171176
expect_warning(plotly_build(p), "Only one fillcolor per trace allowed")
@@ -209,6 +214,7 @@ test_that("numeric color informs fillcolor", {
209214

210215

211216
test_that("sizing constants", {
217+
skip_if_not_installed("sf")
212218

213219
# span controls 'stroke-size'
214220
p <- plot_mapbox(res_mn, span = I(5)) %>% plotly_build()
@@ -253,6 +259,7 @@ test_that("sizing constants", {
253259

254260

255261
test_that("size mappings", {
262+
skip_if_not_installed("sf")
256263

257264
expect_warning(
258265
plotly_build(plot_mapbox(res_mn, span = ~PERIMETER)),
@@ -287,6 +294,7 @@ test_that("size mappings", {
287294

288295

289296
test_that("altogether now", {
297+
skip_if_not_installed("sf")
290298

291299
s <- subplot(plot_ly(nc), plot_geo(nc), plot_mapbox(nc), nrows = 3) %>% plotly_build()
292300
d <- s$x$data
@@ -320,6 +328,7 @@ test_that("altogether now", {
320328

321329

322330
test_that("color and stroke scales can be set independently", {
331+
skip_if_not_installed("sf")
323332

324333
n <- length(unique(res_mn$INDRESNAME))
325334
p <- plot_mapbox(res_mn, split = ~INDRESNAME, color = ~AREA, stroke = ~PERIMETER, span = I(2)) %>%

0 commit comments

Comments
 (0)