@@ -3,6 +3,10 @@ context("add_sf")
3
3
nc <- sf :: st_read(system.file(" shape/nc.shp" , package = " sf" ), quiet = TRUE )
4
4
storms <- sf :: st_read(system.file(" shape/storms_xyz.shp" , package = " sf" ), quiet = TRUE )
5
5
6
+ has_mapbox <- function () {
7
+ ! is.null(tryNULL(mapbox_token()))
8
+ }
9
+
6
10
test_that(" add_sf() is optional" , {
7
11
skip_if_not_installed(" sf" )
8
12
@@ -44,6 +48,7 @@ test_that("plot_geo() lat/lon range is set", {
44
48
45
49
test_that(" plot_mapbox() fitbounds is set" , {
46
50
skip_if_not_installed(" sf" )
51
+ skip_if_not(has_mapbox())
47
52
48
53
p <- plotly_build(plot_mapbox(nc ))
49
54
expect_equal(
@@ -56,6 +61,7 @@ test_that("plot_mapbox() fitbounds is set", {
56
61
57
62
test_that(" sf defaults can be overriden" , {
58
63
skip_if_not_installed(" sf" )
64
+ skip_if_not(has_mapbox())
59
65
60
66
# when applied to fillcolor, alpha defaults to 0.5
61
67
p <- plotly_build(plot_mapbox(nc , color = I(" red" )))
@@ -115,6 +121,7 @@ test_that("plot_ly() defaults to blank axes", {
115
121
116
122
test_that(" discrete color informs fillcolor" , {
117
123
skip_if_not_installed(" sf" )
124
+ skip_if_not(has_mapbox())
118
125
119
126
res <- unique(res_mn $ INDRESNAME )
120
127
cols <- viridisLite :: magma(length(res ))
@@ -136,6 +143,7 @@ test_that("discrete color informs fillcolor", {
136
143
137
144
test_that(" discrete color informs fillcolor" , {
138
145
skip_if_not_installed(" sf" )
146
+ skip_if_not(has_mapbox())
139
147
140
148
res <- unique(res_mn $ INDRESNAME )
141
149
cols <- viridisLite :: magma(length(res ))
@@ -171,6 +179,7 @@ test_that("discrete color informs fillcolor", {
171
179
172
180
test_that(" numeric color informs fillcolor" , {
173
181
skip_if_not_installed(" sf" )
182
+ skip_if_not(has_mapbox())
174
183
175
184
p <- plot_mapbox(res_mn , color = ~ AREA )
176
185
expect_warning(plotly_build(p ), " Only one fillcolor per trace allowed" )
@@ -214,6 +223,7 @@ test_that("numeric color informs fillcolor", {
214
223
215
224
test_that(" sizing constants" , {
216
225
skip_if_not_installed(" sf" )
226
+ skip_if_not(has_mapbox())
217
227
218
228
# span controls 'stroke-size'
219
229
p <- plot_mapbox(res_mn , span = I(5 )) %> % plotly_build()
@@ -259,6 +269,7 @@ test_that("sizing constants", {
259
269
260
270
test_that(" size mappings" , {
261
271
skip_if_not_installed(" sf" )
272
+ skip_if_not(has_mapbox())
262
273
263
274
expect_warning(
264
275
plotly_build(plot_mapbox(res_mn , span = ~ PERIMETER )),
@@ -294,6 +305,7 @@ test_that("size mappings", {
294
305
295
306
test_that(" altogether now" , {
296
307
skip_if_not_installed(" sf" )
308
+ skip_if_not(has_mapbox())
297
309
298
310
s <- subplot(plot_ly(nc ), plot_geo(nc ), plot_mapbox(nc ), nrows = 3 ) %> % plotly_build()
299
311
d <- s $ x $ data
@@ -328,6 +340,7 @@ test_that("altogether now", {
328
340
329
341
test_that(" color and stroke scales can be set independently" , {
330
342
skip_if_not_installed(" sf" )
343
+ skip_if_not(has_mapbox())
331
344
332
345
n <- length(unique(res_mn $ INDRESNAME ))
333
346
p <- plot_mapbox(res_mn , split = ~ INDRESNAME , color = ~ AREA , stroke = ~ PERIMETER , span = I(2 )) %> %
0 commit comments