From 6fd8e507f95c138c83d0a41cbd7c3bddd7cb2dc2 Mon Sep 17 00:00:00 2001 From: Melkiades Date: Thu, 10 Nov 2022 11:47:38 +0100 Subject: [PATCH 1/8] fixing warning qplot --- tests/testthat/test-decorate_grob.R | 32 ++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/tests/testthat/test-decorate_grob.R b/tests/testthat/test-decorate_grob.R index a203d3fb12..1715d35f2b 100644 --- a/tests/testthat/test-decorate_grob.R +++ b/tests/testthat/test-decorate_grob.R @@ -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( From a40d31cc04ce675947b58282f100c58e385fa41f Mon Sep 17 00:00:00 2001 From: Melkiades Date: Thu, 10 Nov 2022 11:55:15 +0100 Subject: [PATCH 2/8] better warning --- R/wrap_text.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/wrap_text.R b/R/wrap_text.R index 333a22867a..efa2a09c6d 100644 --- a/R/wrap_text.R +++ b/R/wrap_text.R @@ -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) } From a3328c784adbf05b85e979eadda3de014f938f83 Mon Sep 17 00:00:00 2001 From: Melkiades Date: Thu, 10 Nov 2022 11:56:35 +0100 Subject: [PATCH 3/8] fix new deprecated warning --- tests/testthat/test-wrap_text.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-wrap_text.R b/tests/testthat/test-wrap_text.R index 367d945027..3568eb93e9 100644 --- a/tests/testthat/test-wrap_text.R +++ b/tests/testthat/test-wrap_text.R @@ -1,6 +1,8 @@ testthat::test_that("wrap_text works with default settings", { text <- "This is a test with many words and more" - result <- wrap_text(txt = text, width = grid::unit(4, "cm"), collapse = "\n") + result <- testthat::expect_warning( + wrap_text(txt = text, width = grid::unit(4, "cm"), collapse = "\n") + ) expected <- "This is a test with\nmany words and\nmore" testthat::expect_identical(result, expected) }) From 55f3d0f3c3bbb09a208ebc93b44bd00f5d5f250a Mon Sep 17 00:00:00 2001 From: Melkiades Date: Thu, 10 Nov 2022 12:30:44 +0100 Subject: [PATCH 4/8] fixing warnings and error --- R/kaplan_meier_plot.R | 2 +- tests/testthat/test-g_km.R | 42 +++++++++++++++++++------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/R/kaplan_meier_plot.R b/R/kaplan_meier_plot.R index d071780d0b..d6fb0cfa5a 100644 --- a/R/kaplan_meier_plot.R +++ b/R/kaplan_meier_plot.R @@ -681,7 +681,7 @@ h_ggkm <- function(data, gg + ggplot2::theme( legend.position = "bottom", legend.title = ggplot2::element_blank(), - panel.grid.major.x = ggplot2::element_line(size = 2) + panel.grid.major.x = ggplot2::element_line(linewidth = 2) ) } diff --git a/tests/testthat/test-g_km.R b/tests/testthat/test-g_km.R index 30b61fb9cc..bc645838fe 100644 --- a/tests/testthat/test-g_km.R +++ b/tests/testthat/test-g_km.R @@ -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", { @@ -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", { @@ -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)) }) From 8699282d871346c5ea375267c7617aa414d4bb0a Mon Sep 17 00:00:00 2001 From: Melkiades Date: Thu, 10 Nov 2022 12:41:24 +0100 Subject: [PATCH 5/8] removing qplots --- R/decorate_grob.R | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/R/decorate_grob.R b/R/decorate_grob.R index 7a6c6f6ed0..2f0d143c68 100644 --- a/R/decorate_grob.R +++ b/R/decorate_grob.R @@ -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() @@ -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 = "") From 21d1b3055f326272f90fe7ebc07e4c06e31f28ad Mon Sep 17 00:00:00 2001 From: Melkiades Date: Thu, 10 Nov 2022 12:46:29 +0100 Subject: [PATCH 6/8] roxygenizationing --- man/decorate_grob.Rd | 3 ++- man/decorate_grob_set.Rd | 32 +++++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/man/decorate_grob.Rd b/man/decorate_grob.Rd index 7a526870c1..4e535481cb 100644 --- a/man/decorate_grob.Rd +++ b/man/decorate_grob.Rd @@ -139,7 +139,8 @@ grid.draw( ## 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() diff --git a/man/decorate_grob_set.Rd b/man/decorate_grob_set.Rd index d772267bfa..edbcd00635 100644 --- a/man/decorate_grob_set.Rd +++ b/man/decorate_grob_set.Rd @@ -18,14 +18,32 @@ Note that this uses the \code{decorate_grob_factory} function. } \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 = "") From 1a5eb64638c01385c3827830d5422b285d77abbd Mon Sep 17 00:00:00 2001 From: Melkiades Date: Thu, 10 Nov 2022 14:07:14 +0100 Subject: [PATCH 7/8] wrong geom_line --- R/kaplan_meier_plot.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/kaplan_meier_plot.R b/R/kaplan_meier_plot.R index d6fb0cfa5a..d071780d0b 100644 --- a/R/kaplan_meier_plot.R +++ b/R/kaplan_meier_plot.R @@ -681,7 +681,7 @@ h_ggkm <- function(data, gg + ggplot2::theme( legend.position = "bottom", legend.title = ggplot2::element_blank(), - panel.grid.major.x = ggplot2::element_line(linewidth = 2) + panel.grid.major.x = ggplot2::element_line(size = 2) ) } From 5a41ebfcdc1cc61a628f79a7e86a915d595160cf Mon Sep 17 00:00:00 2001 From: Melkiades Date: Thu, 10 Nov 2022 15:45:04 +0100 Subject: [PATCH 8/8] another (safer) way to deal with dep warn --- tests/testthat/test-wrap_text.R | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-wrap_text.R b/tests/testthat/test-wrap_text.R index 3568eb93e9..2455f10c5a 100644 --- a/tests/testthat/test-wrap_text.R +++ b/tests/testthat/test-wrap_text.R @@ -1,8 +1,7 @@ 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 <- testthat::expect_warning( - wrap_text(txt = text, width = grid::unit(4, "cm"), collapse = "\n") - ) + result <- wrap_text(txt = text, width = grid::unit(4, "cm"), collapse = "\n") expected <- "This is a test with\nmany words and\nmore" testthat::expect_identical(result, expected) })