Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update deprecation warnings with lifecycle #496

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
3 changes: 2 additions & 1 deletion DESCRIPTION
Expand Up @@ -69,7 +69,8 @@ Suggests:
knitr,
spelling,
emmeans,
vdiffr
vdiffr,
withr (>= 3.0.0)
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
SystemRequirements: openssl
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
@@ -1,5 +1,7 @@
# GGally (development version)

* Use lifecycle for deprecation warnings (#494, #496)

# GGally 2.2.1

* Fix compatibility with ggplot2 3.5.0 (@teunbrand, #481)
Expand Down
52 changes: 46 additions & 6 deletions R/deprecated.R
@@ -1,16 +1,48 @@
#' Modify a \code{\link{ggmatrix}} object by adding an \pkg{ggplot2} object to all
#' @description
#' `r lifecycle::badge("deprecated")`
#'
# \lifecycle{deprecated}
#' This function allows cleaner axis labels for your plots, but is deprecated.
#' You can achieve the same effect by specifying strip's background and placement
#' properties (see Examples).
#'
#' @keywords internal
#'
#' @export
#' @examples
#' # Small function to display plots only if it's interactive
#' p_ <- GGally::print_if_interactive
#'
#' # Cleaner axis labels with v1_ggmatrix_theme
#' p_(ggpairs(iris, 1:2) + v1_ggmatrix_theme())
#' # move the column names to the left and bottom
#'
#' # Move the column names to the left and bottom
#' p_(ggpairs(iris, 1:2, switch = "both") + v1_ggmatrix_theme())
#'
#' # Manually specifying axis labels properties
#' p_(
#' ggpairs(iris, 1:2) +
#' theme(
#' strip.background = element_rect(fill = "white"),
#' strip.placement = "outside"
#' )
#')
#'
#' # This way you have even more control over how the final plot looks.
#' # For example, if you want to set the background color to yellow:
#' p_(
#' ggpairs(iris, 1:2) +
#' theme(
#' strip.background = element_rect(fill = "yellow"),
#' strip.placement = "outside"
#' )
#')
v1_ggmatrix_theme <- function() {
lifecycle::deprecate_soft(
when = "2.2.2",
what = "v1_ggmatrix_theme()",
details = "This function will be removed in future releases."
)
theme(
strip.background = element_rect(fill = "white"),
strip.placement = "outside"
Expand All @@ -20,12 +52,15 @@ v1_ggmatrix_theme <- function() {

#' Correlation value plot
#'
# \lifecycle{deprecated}
#'
#' (Deprecated. See \code{\link{ggally_cor}}.)
#' @description
#' `r lifecycle::badge("deprecated")`
#'
#' Estimate correlation from the given data.
#'
#' This function is deprecated and will be removed in future releases.
#'
#' See \code{\link{ggally_cor}}.
#'
#' @param data data set using
#' @param mapping aesthetics being used
#' @param alignPercent right align position of numbers. Default is 60 percent across the horizontal
Expand All @@ -40,7 +75,7 @@ v1_ggmatrix_theme <- function() {
#' @importFrom stats complete.cases cor
#' @seealso \code{\link{ggally_cor}}
#' @export
#' @keywords hplot
#' @keywords hplot internal
92amartins marked this conversation as resolved.
Show resolved Hide resolved
#' @examples
#' # Small function to display plots only if it's interactive
#' p_ <- GGally::print_if_interactive
Expand Down Expand Up @@ -77,6 +112,11 @@ ggally_cor_v1_5 <- function(
corAlignPercent = NULL, corMethod = NULL, corUse = NULL,
displayGrid = TRUE,
...) {
lifecycle::deprecate_soft(
when = "2.2.2",
what = "ggally_cor_v1_5()",
with = "ggally_cor()"
)
if (!is.null(corAlignPercent)) {
stop("'corAlignPercent' is deprecated. Please use argument 'alignPercent'")
}
Expand Down
23 changes: 16 additions & 7 deletions R/gg-plots.R
Expand Up @@ -261,10 +261,11 @@ ggally_density <- function(data, mapping, ...) {
#' @param group_args arguments being supplied to the split-by-color group's \code{\link[ggplot2]{geom_text}()}
#' @param justify_labels \code{justify} argument supplied when \code{\link[base]{format}}ting the labels
#' @param align_percent relative align position of the text. When \code{justify_labels = 0.5}, this should not be needed to be set.
#' @param alignPercent,displayGrid deprecated. Please use their snake-case counterparts.
#' @param alignPercent,displayGrid `r lifecycle::badge("deprecated")`. Please use their snake-case counterparts.
92amartins marked this conversation as resolved.
Show resolved Hide resolved
#' @param title title text to be displayed
#' @author Barret Schloerke
#' @importFrom stats complete.cases cor
#' @importFrom lifecycle deprecated
#' @seealso \code{\link{ggally_statistic}}, \code{\link{ggally_cor_v1_5}}
#' @export
#' @keywords hplot
Expand Down Expand Up @@ -308,14 +309,22 @@ ggally_cor <- function(
justify_labels = "right",
align_percent = 0.5,
title = "Corr",
alignPercent = warning("deprecated. Use `align_percent`"),
displayGrid = warning("deprecated. Use `display_grid`")) {
if (!missing(alignPercent)) {
warning("`alignPercent` is deprecated. Please use `align_percent` if alignment still needs to be adjusted")
alignPercent = deprecated(),
displayGrid = deprecated()) {
if (lifecycle::is_present(alignPercent)) {
lifecycle::deprecate_soft(
when = "2.2.2",
what = "ggally_cor(alignPercent)",
details = "Please use `align_percent` if alignment still needs to be adjusted."
)
align_percent <- alignPercent
}
if (!missing(displayGrid)) {
warning("`displayGrid` is deprecated. Please use `display_grid`")
if (lifecycle::is_present(displayGrid)) {
lifecycle::deprecate_soft(
when = "2.2.2",
what = "ggally_cor(displayGrid)",
details = "Please use `display_grid`"
)
display_grid <- displayGrid
}

Expand Down
6 changes: 3 additions & 3 deletions man/ggally_cor.Rd

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

10 changes: 7 additions & 3 deletions man/ggally_cor_v1_5.Rd

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

30 changes: 28 additions & 2 deletions man/v1_ggmatrix_theme.Rd

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

32 changes: 32 additions & 0 deletions tests/testthat/_snaps/deprecated.md
@@ -0,0 +1,32 @@
# v1_ggmatrix_theme() is deprecated

Code
v1_ggmatrix_theme()
Condition
Warning:
`v1_ggmatrix_theme()` was deprecated in GGally 2.2.2.
i This function will be removed in future releases.
Output
List of 2
$ strip.background:List of 5
..$ fill : chr "white"
..$ colour : NULL
..$ linewidth : NULL
..$ linetype : NULL
..$ inherit.blank: logi FALSE
..- attr(*, "class")= chr [1:2] "element_rect" "element"
$ strip.placement : chr "outside"
- attr(*, "class")= chr [1:2] "theme" "gg"
- attr(*, "complete")= logi FALSE
- attr(*, "validate")= logi TRUE

# ggally_cor_v1_5() is deprecated

Code
p <- ggally_cor_v1_5(tips, ggplot2::aes(!!as.name("total_bill"), !!as.name(
"tip")))
Condition
Warning:
`ggally_cor_v1_5()` was deprecated in GGally 2.2.2.
i Please use `ggally_cor()` instead.

13 changes: 13 additions & 0 deletions tests/testthat/_snaps/ggmatrix_add.md
@@ -0,0 +1,13 @@
# v1_ggmatrix_theme

Code
pm <- ggpairs(tips, 1:2)
pm1 <- pm + v1_ggmatrix_theme()
Condition
Warning:
`v1_ggmatrix_theme()` was deprecated in GGally 2.2.2.
i This function will be removed in future releases.
Code
expect_true(is.null(pm$gg))
expect_true(!is.null(pm1$gg))

16 changes: 14 additions & 2 deletions tests/testthat/test-deprecated.R
@@ -1,8 +1,20 @@

data(tips)

test_that("ggally-cor", {
test_that("ggally_cor_v1_5() works", {
withr::local_options(lifecycle_verbosity = "quiet")
expect_silent(
p <- ggally_cor_v1_5(tips, ggplot2::aes(!!as.name("total_bill"), !!as.name("tip")))
92amartins marked this conversation as resolved.
Show resolved Hide resolved
)
})

test_that("v1_ggmatrix_theme() is deprecated", {
expect_snapshot(
v1_ggmatrix_theme()
)
})

test_that("ggally_cor_v1_5() is deprecated", {
expect_snapshot(
p <- ggally_cor_v1_5(tips, ggplot2::aes(!!as.name("total_bill"), !!as.name("tip")))
)
})
12 changes: 8 additions & 4 deletions tests/testthat/test-ggmatrix_add.R
Expand Up @@ -50,10 +50,14 @@ test_that("add_list", {
})

test_that("v1_ggmatrix_theme", {
pm <- ggpairs(tips, 1:2)
expect_snapshot(
{
pm <- ggpairs(tips, 1:2)

pm1 <- pm + v1_ggmatrix_theme()
pm1 <- pm + v1_ggmatrix_theme()

expect_true(is.null(pm$gg))
expect_true(!is.null(pm1$gg))
expect_true(is.null(pm$gg))
expect_true(!is.null(pm1$gg))
}
)
})