Skip to content

Commit e15eae0

Browse files
committed
Fix example, add test
1 parent cd87b37 commit e15eae0

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
* Labels created with the `labs` argument to `ggtibble()` will not longer all be
44
the same (#3)
5-
* `new_gglist()` is now exported making it easier to create a gglist object
5+
* `new_gglist()` and `new_ggtibble()` are now exported making it easier to
6+
create objects.

R/ggtibble.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,14 @@ ggtibble.data.frame <- function(data, mapping = ggplot2::aes(), ..., outercols =
7474
#' @returns The object with a ggtibble class
7575
#' @family New ggtibble objects
7676
#' @examples
77-
#' new_ggtibble(list(NULL, ggplot2::ggplot(data = data.frame())))
77+
#' new_ggtibble(tibble::tibble(figure = list(ggplot2::ggplot()), caption = ""))
7878
#' @export
7979
new_ggtibble <- function(x) {
8080
stopifnot(is.data.frame(x))
8181
stopifnot(c("figure", "caption") %in% names(x))
82-
stopifnot(inherits(x$figure, "gglist"))
82+
if (!inherits(x$figure, "gglist")) {
83+
x$figure <- new_gglist(x$figure)
84+
}
8385
class(x) <- unique(c("ggtibble", class(x)))
8486
x
8587
}

tests/testthat/test-ggtibble.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,10 @@ test_that("labels are not always the same (#3)", {
141141

142142
expect_true(fig1$labels$x != fig2$labels$x)
143143
})
144+
145+
test_that("new_ggtibble() works", {
146+
expect_s3_class(
147+
new_ggtibble(tibble::tibble(figure = list(ggplot2::ggplot()), caption = "")),
148+
"ggtibble"
149+
)
150+
})

0 commit comments

Comments
 (0)