Skip to content

Commit

Permalink
740 qplot warning failure@main (#741)
Browse files Browse the repository at this point in the history
  • Loading branch information
Melkiades authored Nov 11, 2022
1 parent 83216af commit aa5ff16
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 45 deletions.
35 changes: 27 additions & 8 deletions R/decorate_grob.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@
#' ## with \code{ggplot2}
#' library(ggplot2)
#'
#' p_gg <- with(iris, qplot(Sepal.Length, Petal.Length, col = Species))
#' p_gg <- ggplot2::ggplot(iris, aes(Sepal.Length, Sepal.Width, col = Species)) +
#' ggplot2::geom_point()
#' p_gg
#' p <- ggplotGrob(p_gg)
#' grid.newpage()
Expand Down Expand Up @@ -493,14 +494,32 @@ decorate_grob_factory <- function(npages, ...) {
#'
#' @examples
#' library(ggplot2)
#' g <- with(iris, {
#' g <- with(data = iris, {
#' list(
#' ggplotGrob(qplot(Sepal.Length, Sepal.Width, col = Species)),
#' ggplotGrob(qplot(Sepal.Length, Petal.Length, col = Species)),
#' ggplotGrob(qplot(Sepal.Length, Petal.Width, col = Species)),
#' ggplotGrob(qplot(Sepal.Width, Petal.Length, col = Species)),
#' ggplotGrob(qplot(Sepal.Width, Petal.Width, col = Species)),
#' ggplotGrob(qplot(Petal.Length, Petal.Width, col = Species))
#' ggplot2::ggplotGrob(
#' ggplot2::ggplot(mapping = aes(Sepal.Length, Sepal.Width, col = Species)) +
#' ggplot2::geom_point()
#' ),
#' ggplot2::ggplotGrob(
#' ggplot2::ggplot(mapping = aes(Sepal.Length, Petal.Length, col = Species)) +
#' ggplot2::geom_point()
#' ),
#' ggplot2::ggplotGrob(
#' ggplot2::ggplot(mapping = aes(Sepal.Length, Petal.Width, col = Species)) +
#' ggplot2::geom_point()
#' ),
#' ggplot2::ggplotGrob(
#' ggplot2::ggplot(mapping = aes(Sepal.Width, Petal.Length, col = Species)) +
#' ggplot2::geom_point()
#' ),
#' ggplot2::ggplotGrob(
#' ggplot2::ggplot(mapping = aes(Sepal.Width, Petal.Width, col = Species)) +
#' ggplot2::geom_point()
#' ),
#' ggplot2::ggplotGrob(
#' ggplot2::ggplot(mapping = aes(Petal.Length, Petal.Width, col = Species)) +
#' ggplot2::geom_point()
#' )
#' )
#' })
#' lg <- decorate_grob_set(grobs = g, titles = "Hello\nOne\nTwo\nThree", footnotes = "")
Expand Down
4 changes: 3 additions & 1 deletion R/wrap_text.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ wrap_text <- function(txt, # nolint
width = grid::convertWidth(grid::unit(1, "npc"), "inch", TRUE),
gp = grid::gpar(),
collapse = NULL) {
warning("This is a deprecated function as there is a current implementation in rtables, not based on grid::")
dep_msg <- "Please use current implementation in rtables, not based on grid::"
lifecycle::deprecate_warn("0.7.10", "wrap_test()", details = dep_msg)

if (grid::is.unit(width)) {
width <- grid::convertWidth(width, "inch", TRUE)
}
Expand Down
3 changes: 2 additions & 1 deletion man/decorate_grob.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 25 additions & 7 deletions man/decorate_grob_set.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 25 additions & 7 deletions tests/testthat/test-decorate_grob.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,32 @@ testthat::test_that("decorate_grob_factory returns page warning correctly", {
})

testthat::test_that("decorate_grob_set returns no warnings when creating a non-empty plot", {
g <- with(iris, {
g <- with(data = iris, {
list(
ggplot2::ggplotGrob(ggplot2::qplot(Sepal.Length, Sepal.Width, col = Species)),
ggplot2::ggplotGrob(ggplot2::qplot(Sepal.Length, Petal.Length, col = Species)),
ggplot2::ggplotGrob(ggplot2::qplot(Sepal.Length, Petal.Width, col = Species)),
ggplot2::ggplotGrob(ggplot2::qplot(Sepal.Width, Petal.Length, col = Species)),
ggplot2::ggplotGrob(ggplot2::qplot(Sepal.Width, Petal.Width, col = Species)),
ggplot2::ggplotGrob(ggplot2::qplot(Petal.Length, Petal.Width, col = Species))
ggplot2::ggplotGrob(
ggplot2::ggplot(mapping = aes(Sepal.Length, Sepal.Width, col = Species)) +
ggplot2::geom_point()
),
ggplot2::ggplotGrob(
ggplot2::ggplot(mapping = aes(Sepal.Length, Petal.Length, col = Species)) +
ggplot2::geom_point()
),
ggplot2::ggplotGrob(
ggplot2::ggplot(mapping = aes(Sepal.Length, Petal.Width, col = Species)) +
ggplot2::geom_point()
),
ggplot2::ggplotGrob(
ggplot2::ggplot(mapping = aes(Sepal.Width, Petal.Length, col = Species)) +
ggplot2::geom_point()
),
ggplot2::ggplotGrob(
ggplot2::ggplot(mapping = aes(Sepal.Width, Petal.Width, col = Species)) +
ggplot2::geom_point()
),
ggplot2::ggplotGrob(
ggplot2::ggplot(mapping = aes(Petal.Length, Petal.Width, col = Species)) +
ggplot2::geom_point()
)
)
})
lg <- testthat::expect_silent(
Expand Down
42 changes: 21 additions & 21 deletions tests/testthat/test-g_km.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ testthat::test_that("g_km default plot works", {

variables <- list(tte = "AVAL", is_event = "is_event", arm = "ARMCD")

result <- testthat::expect_silent(
g_km(
df = df,
variables = variables,
ci_ribbon = FALSE,
draw = FALSE
)
grob_tmp <- g_km(
df = df,
variables = variables,
ci_ribbon = FALSE,
draw = FALSE
)

testthat::expect_true(grid::is.grob(grob_tmp))
})

testthat::test_that("g_km default plot witch ci_ribbon = TRUE works", {
Expand All @@ -22,14 +22,14 @@ testthat::test_that("g_km default plot witch ci_ribbon = TRUE works", {

variables <- list(tte = "AVAL", is_event = "is_event", arm = "ARMCD")

result <- testthat::expect_silent(
g_km(
df = df,
variables = variables,
ci_ribbon = TRUE,
draw = FALSE
)
grob_tmp <- g_km(
df = df,
variables = variables,
ci_ribbon = TRUE,
draw = FALSE
)

testthat::expect_true(grid::is.grob(grob_tmp))
})

testthat::test_that("g_km plot with < = > in group labels works", {
Expand All @@ -43,12 +43,12 @@ testthat::test_that("g_km plot with < = > in group labels works", {

variables <- list(tte = "AVAL", is_event = "is_event", arm = "group")

result <- testthat::expect_silent(
g_km(
df = df,
variables = variables,
annot_surv_med = FALSE,
draw = FALSE
)
grob_tmp <- g_km(
df = df,
variables = variables,
annot_surv_med = FALSE,
draw = FALSE
)

testthat::expect_true(grid::is.grob(grob_tmp))
})
1 change: 1 addition & 0 deletions tests/testthat/test-wrap_text.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
testthat::test_that("wrap_text works with default settings", {
rlang::local_options(lifecycle_verbosity = "quiet")
text <- "This is a test with many words and more"
result <- wrap_text(txt = text, width = grid::unit(4, "cm"), collapse = "\n")
expected <- "This is a test with\nmany words and\nmore"
Expand Down

0 comments on commit aa5ff16

Please sign in to comment.