Skip to content

Commit df59328

Browse files
committed
adapt tests
1 parent 30da1cd commit df59328

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

tests/testthat/test-guides.R

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,21 @@ test_that("Colorbar respects show.legend in layer", {
5151
df <- data_frame(x = 1:3, y = 1)
5252
p <- ggplot(df, aes(x = x, y = y, color = x)) +
5353
geom_point(size = 20, shape = 21, show.legend = FALSE)
54-
expect_false("guide-box" %in% ggplotGrob(p)$layout$name)
54+
expect_false(any(grepl("guide-box", ggplotGrob(p)$layout$name)))
5555
p <- ggplot(df, aes(x = x, y = y, color = x)) +
5656
geom_point(size = 20, shape = 21, show.legend = TRUE)
57-
expect_true("guide-box" %in% ggplotGrob(p)$layout$name)
57+
expect_true(any(grepl("guide-box", ggplotGrob(p)$layout$name)))
5858
})
5959

6060
test_that("show.legend handles named vectors", {
6161
n_legends <- function(p) {
6262
g <- ggplotGrob(p)
63-
gb <- which(g$layout$name == "guide-box")
64-
if (length(gb) > 0) {
65-
n <- length(g$grobs[[gb]]) - 1
66-
} else {
67-
n <- 0
68-
}
69-
n
63+
gb <- grep("guide-box", g$layout$name)
64+
n <- vapply(g$grobs[gb], function(x) {
65+
if (is.zero(x)) return(0)
66+
length(x$grobs) - 1
67+
}, numeric(1))
68+
sum(n)
7069
}
7170

7271
df <- data_frame(x = 1:3, y = 20:22)

0 commit comments

Comments
 (0)