diff --git a/DESCRIPTION b/DESCRIPTION index b1049136fd..fa5fa91b61 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -150,4 +150,3 @@ Collate: 'utils_factor.R' 'utils_grid.R' 'utils_rtables.R' - 'wrap_text.R' diff --git a/NEWS.md b/NEWS.md index 53b87b62c2..0f7d335e81 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,7 +6,6 @@ function to speed up data set loading in tests/examples. * Updated all tests to use `rcd_2022_06_27` version of cached data. * Added more tests to increase code coverage. -* Deprecated badge and warning for `wrap_txt` and its file. * Added legend to `g_step`. * Added formatting functions `format_fraction_fixed_dp` and `format_count_fraction_fixed_dp` with fixed single decimal place in percentages. @@ -51,6 +50,8 @@ * Created separate `.R` files for logistic regression and cox regression helper functions. * Removed all template tests from `tern`. These tests are in internal repo `scda.test`. * Replaced deprecated function `forcats::fct_explicit_na` with `forcats::fct_na_value_to_level`. +* Removal of deprecated `wrap_text` and related files. +* Deprecation cycle started for `footnotes` functions. # tern 0.7.10 diff --git a/R/footnotes.R b/R/footnotes.R index 83d1df23ea..41a93a1b9a 100644 --- a/R/footnotes.R +++ b/R/footnotes.R @@ -1,6 +1,6 @@ #' Assign Footnotes #' -#' @description `r lifecycle::badge("stable")` +#' @description `r lifecycle::badge("deprecated")` #' #' Assign value to attribute footnote of object `x`. #' @@ -12,14 +12,15 @@ #' footnotes(x) <- "Species are equally distributed" #' attributes(x) `footnotes<-` <- function(x, value = NULL) { # nolint + dep_msg <- 'Please use current implementation in rtables or directly attr(x, "footnote")' + lifecycle::deprecate_warn("0.7.11", "footnotes()", details = dep_msg) attr(x, "footnote") <- value x } - #' Retrieve Footnotes #' -#' @description `r lifecycle::badge("stable")` +#' @description `r lifecycle::badge("deprecated")` #' #' Retrieve value from attribute `footnote` of object `x`. #' @@ -30,12 +31,14 @@ #' footnotes(x) <- "Species are equally distributed" #' footnotes(x) footnotes <- function(x) { + dep_msg <- 'Please use current implementation in rtables or directly attr(x, "footnote")' + lifecycle::deprecate_warn("0.7.11", "footnotes()", details = dep_msg) attr(x, "footnote") } #' Add Footnotes #' -#' @description `r lifecycle::badge("stable")` +#' @description `r lifecycle::badge("deprecated")` #' #' This adds more footnotes. #' @@ -49,6 +52,8 @@ footnotes <- function(x) { #' add_footnotes(x) <- "Add more footnotes" #' footnotes(x) `add_footnotes<-` <- function(x, value) { # nolint + dep_msg <- 'Please use current implementation in rtables or directly attr(x, "footnote")' + lifecycle::deprecate_warn("0.7.11", "add_footnotes()", details = dep_msg) footnotes(x) <- c(footnotes(x), value) x } diff --git a/R/g_forest.R b/R/g_forest.R index d1a45a1fa8..bf0d262db6 100644 --- a/R/g_forest.R +++ b/R/g_forest.R @@ -246,12 +246,6 @@ g_forest <- function(tbl, # nolint vp = grid::plotViewport(margins = rep(1, 4)) ) - fn <- footnotes(tbl) - if (!is.null(fn)) { - footnotes(grob_forest) <- fn - message("grob footnote is not added to plot; suggest to use decorate_grob() to further decorate the grob") - } - if (draw) { if (newpage) grid::grid.newpage() grid::grid.draw(grob_forest) diff --git a/R/wrap_text.R b/R/wrap_text.R deleted file mode 100644 index aff0be99cc..0000000000 --- a/R/wrap_text.R +++ /dev/null @@ -1,110 +0,0 @@ -#' Split String -#' -#' @description `r lifecycle::badge("deprecated")` -#' Return split text that fits onto page width. -#' -#' @param txt string (or vector of strings) to be split in multiple lines, not that -#' \code{\\n} is also split into to lines -#' @param width max with of string, by default the width of the current viewport -#' @param gp graphical parameters for text -#' -#' @return e vector with the new strings. -#' -#' @author Adrian Waddell -#' -#' @examples -#' text <- "This is a test with many words and more" -#' -#' # Internal function - wrap_text -#' \dontrun{ -#' wrap_text(txt = text, width = grid::unit(4, "cm"), collapse = "\n") -#' wrap_text(txt = text, width = grid::unit(5, "cm"), collapse = "\n") -#' } -#' -#' @noRd -#' @keywords internal -wrap_text <- function(txt, # nolint - width = grid::convertWidth(grid::unit(1, "npc"), "inch", TRUE), - gp = grid::gpar(), - collapse = NULL) { - 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) - } - - if (length(txt) == 0) { - return(character(0)) - } - - g_string_width <- function(label) { - vapply( - label, - function(lab) grid::convertWidth(grid::grobWidth(grid::textGrob(lab, gp = gp)), "inch", TRUE), - numeric(1) - ) - } - - space_width <- g_string_width(" ") - width_s <- width - space_width - - # splits a string into multiple strings that fit - splitstr <- function(str) { - if (g_string_width(str) > width_s) { - strs <- unlist(strsplit(str, " ", fixed = TRUE)) - n <- length(strs) - - if (n <= 1) { - str - } else { - strsw <- g_string_width(strs) + space_width - part <- rep(NA_integer_, n) - # string partition - k <- 1 - part[1] <- k - s <- strsw[1] # current width - for (i in 2:n) { - if (s + strsw[i] > width_s) { - k <- k + 1 - s <- strsw[i] - } else { - s <- s + strsw[i] - } - part[i] <- k - } - as.vector(tapply(strs, part, function(x) paste(x, collapse = " "), simplify = TRUE)) - } - } else { - str - } - } - strs_to_split <- unlist( - Map( - function(x) { - if (length(x) == 0) { - "" - } else { - x - } - }, - strsplit(txt, "\n", fixed = TRUE) - ) - ) - - strings <- unlist( - Map( - function(str) { - splitstr(str) - }, - strs_to_split - ), - use.names = FALSE - ) - - if (!is.null(collapse)) { - paste(strings, collapse = collapse) - } else { - strings - } -} diff --git a/man/add_footnotes-set.Rd b/man/add_footnotes-set.Rd index 49e2e0285c..308180e3ea 100644 --- a/man/add_footnotes-set.Rd +++ b/man/add_footnotes-set.Rd @@ -12,7 +12,7 @@ add_footnotes(x) <- value \item{value}{character vector} } \description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} This adds more footnotes. } diff --git a/man/footnotes-set.Rd b/man/footnotes-set.Rd index 65481f7592..041a8fccec 100644 --- a/man/footnotes-set.Rd +++ b/man/footnotes-set.Rd @@ -12,7 +12,7 @@ footnotes(x) <- value \item{value}{character vector} } \description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Assign value to attribute footnote of object \code{x}. } diff --git a/man/footnotes.Rd b/man/footnotes.Rd index 9fe904c53a..0282c10d30 100644 --- a/man/footnotes.Rd +++ b/man/footnotes.Rd @@ -10,7 +10,7 @@ footnotes(x) \item{x}{an object} } \description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Retrieve value from attribute \code{footnote} of object \code{x}. } diff --git a/tests/testthat/_snaps/wrap_text.md b/tests/testthat/_snaps/wrap_text.md deleted file mode 100644 index 31cf645674..0000000000 --- a/tests/testthat/_snaps/wrap_text.md +++ /dev/null @@ -1,7 +0,0 @@ -# wrap_text works with default settings - - Code - res - Output - [1] "This is a test with\nmany words and\nmore" - diff --git a/tests/testthat/test-footnotes.R b/tests/testthat/test-footnotes.R index 0fa66fc4f1..67d268a282 100644 --- a/tests/testthat/test-footnotes.R +++ b/tests/testthat/test-footnotes.R @@ -2,7 +2,7 @@ testthat::test_that("footnotes works correctly", { x <- table(iris$Species) footnotes(x) <- "Species are equally distributed" - res <- testthat::expect_silent(footnotes(x)) + res <- footnotes(x) testthat::expect_snapshot(res) }) @@ -11,6 +11,6 @@ testthat::test_that("add_footnotes works correctly", { footnotes(x) <- "Species are equally distributed" add_footnotes(x) <- "Add more footnotes" - res <- testthat::expect_silent(footnotes(x)) + res <- footnotes(x) testthat::expect_snapshot(res) }) diff --git a/tests/testthat/test-wrap_text.R b/tests/testthat/test-wrap_text.R deleted file mode 100644 index 982d638720..0000000000 --- a/tests/testthat/test-wrap_text.R +++ /dev/null @@ -1,8 +0,0 @@ -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") - - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) -})