Skip to content

Commit f788ddd

Browse files
committed
be more careful about using suggested packages in tests
1 parent 756400a commit f788ddd

File tree

7 files changed

+31
-21
lines changed

7 files changed

+31
-21
lines changed

tests/testthat/test-ggplot-annotation_.R

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ p <- ggplot(mtcars, aes(mpg, wt)) +
99

1010

1111
test_that("Basic annotation_raster() example works", {
12+
# annotations require this package
13+
skip_if_not_installed("png")
1214

1315
l <- plotly_build(p)$x
1416

@@ -38,16 +40,16 @@ test_that("Basic annotation_raster() example works", {
3840
})
3941

4042

41-
42-
usamap <- map_data("state")
43-
seal.sub <- subset(seals, long > -130 & lat < 45 & lat > 40)
44-
p <- ggplot(seal.sub, aes(x = long, y = lat)) +
45-
annotation_map(usamap, fill = "NA", colour = "grey50") +
46-
geom_segment(aes(xend = long + delta_long, yend = lat + delta_lat))
47-
48-
4943
test_that("Basic annotation_map() example works", {
5044

45+
skip_if_not_installed("maps")
46+
47+
usamap <- map_data("state")
48+
seal.sub <- subset(seals, long > -130 & lat < 45 & lat > 40)
49+
p <- ggplot(seal.sub, aes(x = long, y = lat)) +
50+
annotation_map(usamap, fill = "NA", colour = "grey50") +
51+
geom_segment(aes(xend = long + delta_long, yend = lat + delta_lat))
52+
5153
l <- plotly_build(p)$x
5254

5355
expect_equivalent(l$data[[1]]$type, "scatter")

tests/testthat/test-ggplot-map.R

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
context("maps")
22

3-
crimes <- data.frame(state = tolower(rownames(USArrests)), USArrests)
4-
crimesm <- tidyr::gather(crimes, variable, value, -state)
5-
states_map <- map_data("state")
6-
g <- ggplot(crimesm, aes(map_id = state)) +
7-
geom_map(aes(fill = value), map = states_map) +
8-
expand_limits(x = states_map$long, y = states_map$lat) +
9-
facet_wrap( ~ variable)
10-
113

124
test_that("basic geom_map works", {
5+
skip_if_not_installed("maps")
6+
7+
crimes <- data.frame(state = tolower(rownames(USArrests)), USArrests)
8+
crimesm <- tidyr::gather(crimes, variable, value, -state)
9+
states_map <- map_data("state")
10+
g <- ggplot(crimesm, aes(map_id = state)) +
11+
geom_map(aes(fill = value), map = states_map) +
12+
expand_limits(x = states_map$long, y = states_map$lat) +
13+
facet_wrap( ~ variable)
14+
1315
l <- expect_doppelganger_built(g, "map-facet")
1416
expect_true(length(l$data) > 1)
1517
})

tests/testthat/test-ggplot-polygons.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ test_that("geom_polygon(aes(size), fill, colour)", {
141141
})
142142

143143
test_that("borders become one trace with NA", {
144+
skip_if_not_installed("maps")
145+
144146
gg <- ggplot(maps::canada.cities, aes(long, lat)) +
145147
borders(regions = "canada")
146148
info <- expect_doppelganger_built(gg, "polygons-canada-borders")

tests/testthat/test-ggplot-sf.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
context("geom_sf")
22

3-
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
4-
53
test_that("geom_sf() basic polygons.", {
64
skip_if_not_installed("sf")
75

6+
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
7+
88
p <- ggplot(nc) + geom_sf()
99

1010
l <- expect_doppelganger_built(p, "sf")

tests/testthat/test-plotly-partial-bundles.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ context("partial-bundles")
22

33
test_that("Can reduce saved file size with an basic (auto) partial bundle by half", {
44
skip_on_cran()
5+
skip_if_not(Sys.which("pandoc") != "", "pandoc needed for this test")
56

67
p1 <- plot_ly(x = 1:10, y = 1:10) %>% add_markers()
78
p2 <- partial_bundle(p1)

tests/testthat/test-plotly-sf.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
context("add_sf")
22

3-
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
4-
storms <- sf::st_read(system.file("shape/storms_xyz.shp", package = "sf"), quiet = TRUE)
5-
63
has_mapbox <- function() {
74
!is.null(tryNULL(mapbox_token()))
85
}
96

107
test_that("add_sf() is optional", {
118
skip_if_not_installed("sf")
129

10+
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
11+
storms <- sf::st_read(system.file("shape/storms_xyz.shp", package = "sf"), quiet = TRUE)
12+
1313
p1 <- plotly_build(plot_ly(nc))
1414
p2 <- plotly_build(plot_ly() %>% add_sf(data = nc))
1515

tests/testthat/test-plotly-subplot.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ test_that("subplot accepts a list of plots", {
136136

137137
# Ignore for now https://github.com/ggobi/ggally/issues/264
138138
test_that("ggplotly understands ggmatrix", {
139+
skip_if_not_installed("GGally")
139140
L <- expect_doppelganger_built(GGally::ggpairs(iris), "plotly-subplot-ggmatrix")
140141
})
141142

@@ -167,6 +168,7 @@ test_that("annotation xref/yref are bumped correctly", {
167168
})
168169

169170
test_that("images accumulate and paper coordinates are repositioned", {
171+
skip_if_not_installed("png")
170172

171173
r <- as.raster(matrix(hcl(0, 80, seq(50, 80, 10)), nrow = 4, ncol = 5))
172174

@@ -200,6 +202,7 @@ test_that("images accumulate and paper coordinates are repositioned", {
200202
})
201203

202204
test_that("images axis references are remapped", {
205+
skip_if_not_installed("png")
203206

204207
r <- as.raster(matrix(hcl(0, 80, seq(50, 80, 10)), nrow = 4, ncol = 5))
205208

0 commit comments

Comments
 (0)