Skip to content

Commit 521f3f4

Browse files
authored
Merge pull request #8 from billdenney/7-cannot-add-guides
Allow addition of `guides()` objects
2 parents 073696f + 0a5b739 commit 521f3f4

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ S3method(print,gglist)
1212
S3method(vec_arith,gglist)
1313
S3method(vec_arith.gglist,gg)
1414
S3method(vec_arith.gglist,gglist)
15+
S3method(vec_arith.gglist,guides)
1516
S3method(vec_arith.gglist,labels)
1617
S3method(vec_arith.gglist,list)
1718
export(gglist)

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# ggtibble 1.0.0.9000
22

3+
* `guides()` can now be added to `gglist` objects.
34
* Labels created with the `labs` argument to `ggtibble()` will not longer all be
45
the same (#3)
56
* `new_gglist()` and `new_ggtibble()` are now exported making it easier to

R/gglist.R

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,10 @@ vec_arith.gglist.gg <- function(op, x, y, ...) {
9999
}
100100
#' @export
101101
#' @method vec_arith.gglist labels
102-
vec_arith.gglist.labels <- function(op, x, y, ...) {
103-
stopifnot(op == "+")
104-
new_gglist(
105-
lapply(FUN = "+", X = x, y, ...)
106-
)
107-
}
102+
vec_arith.gglist.labels <- vec_arith.gglist.gg
103+
#' @export
104+
#' @method vec_arith.gglist guides
105+
vec_arith.gglist.guides <- vec_arith.gglist.gg
108106

109107
#' @importFrom knitr knit_print
110108
#' @export

tests/testthat/test-gglist.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ test_that("vec_arith for gglists", {
2121
g1 + ggplot2::labs(x = "foo"),
2222
"gglist"
2323
)
24+
# add a guides object to a single gglist
25+
expect_s3_class(
26+
g1 + ggplot2::guides(colour = ggplot2::guide_legend(ncol = 1)),
27+
"gglist"
28+
)
2429
# add a list of items to a single gglist
2530
expect_s3_class(
2631
g1 + list(ggplot2::labs(x = "foo")),

0 commit comments

Comments
 (0)