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
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 internal
#' @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
8 changes: 6 additions & 2 deletions R/ggmatrix_gtable.R
Expand Up @@ -4,7 +4,7 @@
#'
#' @param pm \code{\link{ggmatrix}} object to be plotted
#' @param ... ignored
#' @param progress,progress_format Please use the 'progress' parameter in your \code{\link{ggmatrix}}-like function. See \code{\link{ggmatrix_progress}} for a few examples. These parameters will soon be deprecated.
#' @param progress,progress_format `r lifecycle::badge("deprecated")` Please use the 'progress' parameter in your \code{\link{ggmatrix}}-like function. See \code{\link{ggmatrix_progress}} for a few examples.
#' @author Barret Schloerke
#' @importFrom grid gpar grid.layout grid.newpage grid.text grid.rect popViewport pushViewport viewport grid.draw
#' @export
Expand All @@ -25,7 +25,11 @@ ggmatrix_gtable <- function(
hasProgressBar <- !isFALSE(pm$progress)
progress_fn <- pm$progress
} else {
warning("Please use the 'progress' parameter in your ggmatrix-like function call. See ?ggmatrix_progress for a few examples. ggmatrix_gtable 'progress' and 'progress_format' will soon be deprecated.", immediate = TRUE)
lifecycle::deprecate_soft(
when = "2.2.2",
what = I("`progress` and `progress_format`"),
details = "Please use the 'progress' parameter in your ggmatrix-like function call. See ?ggmatrix_progress for a few examples."
)

# has progress variable defined
# overrides pm$progress
Expand Down
72 changes: 50 additions & 22 deletions R/ggnet.R
Expand Up @@ -4,6 +4,9 @@ if (getRversion() >= "2.15.1") {

#' Network plot
#'
#' @description
#' `r lifecycle::badge("deprecated")`
#'
#' Function for plotting network objects using \pkg{ggplot2}, now replaced by the
#' \code{\link{ggnet2}} function, which provides additional control over
#' plotting parameters. Please visit \url{https://github.com/briatte/ggnet} for
Expand Down Expand Up @@ -114,12 +117,12 @@ if (getRversion() >= "2.15.1") {
#' @param legend.position the location of the plot legend(s). Accepts all
#' \code{legend.position} values supported by \code{\link[ggplot2]{theme}}.
#' Defaults to \code{"right"}.
#' @param names deprecated: see \code{group.legend} and \code{size.legend}
#' @param quantize.weights deprecated: see \code{weight.cut}
#' @param subset.threshold deprecated: see \code{weight.min}
#' @param top8.nodes deprecated: this functionality was experimental and has
#' @param names `r lifecycle::badge("deprecated")` see \code{group.legend} and \code{size.legend}
#' @param quantize.weights `r lifecycle::badge("deprecated")` see \code{weight.cut}
#' @param subset.threshold `r lifecycle::badge("deprecated")` see \code{weight.min}
#' @param top8.nodes `r lifecycle::badge("deprecated")` this functionality was experimental and has
#' been removed entirely from \code{ggnet}
#' @param trim.labels deprecated: see \code{label.trim}
#' @param trim.labels `r lifecycle::badge("deprecated")` see \code{label.trim}
#' @param ... other arguments passed to the \code{geom_text} object that sets
#' the node labels: see \code{\link[ggplot2]{geom_text}} for details.
#' @seealso \code{\link{ggnet2}} in this package,
Expand All @@ -135,6 +138,7 @@ if (getRversion() >= "2.15.1") {
#' @importFrom stats quantile na.omit
#' @importFrom utils head installed.packages
#' @importFrom grDevices gray.colors
#' @keywords internal
#' @examples
#' # Small function to display plots only if it's interactive
#' p_ <- GGally::print_if_interactive
Expand Down Expand Up @@ -199,46 +203,70 @@ ggnet <- function(
legend.size = 9,
legend.position = "right",
# -- deprecated arguments ----------------------------------------------------
names = c("", ""),
quantize.weights = FALSE,
subset.threshold = 0,
top8.nodes = FALSE,
trim.labels = FALSE,
names = deprecated(),
quantize.weights = deprecated(),
subset.threshold = deprecated(),
top8.nodes = deprecated(),
trim.labels = deprecated(),
...
) {
lifecycle::deprecate_soft("2.2.2", "ggnet()", "ggnet2()")

# -- packages ----------------------------------------------------------------

require_namespaces(c("network", "sna", "scales"))
# -- deprecations ------------------------------------------------------------

if (length(mode) == 1 && mode == "geo") {
warning("mode = 'geo' is deprecated; please use mode = c('lon', 'lat') instead")
lifecycle::deprecate_warn(
when = "2.2.2",
what = "ggnet(mode='cannot be `geo`')",
details = "Please use mode = c('lon', 'lat') instead"
)
mode = c("lon", "lat")
}

if (!identical(names, c("", ""))) {
warning("names is deprecated; please use group.legend and size.legend instead")
if (lifecycle::is_present(names)) {
lifecycle::deprecate_warn(
when = "2.2.2",
what = "ggnet(names)",
details = "Please use group.legend and size.legend instead"
)
group.legend = names[1]
size.legend = names[2]
}

if (isTRUE(quantize.weights)) {
warning("quantize.weights is deprecated; please use weight.cut instead")
weight.cut = TRUE
if (lifecycle::is_present(quantize.weights)) {
lifecycle::deprecate_warn(
when = "2.2.2",
what = "ggnet(quantize.weights)",
details = "Please use weight.cut instead"
)
weight.cut = quantize.weights
}

if (subset.threshold > 0) {
warning("subset.threshold is deprecated; please use weight.min instead")
if (lifecycle::is_present(subset.threshold)) {
lifecycle::deprecate_warn(
when = "2.2.2",
what = "ggnet(subset.threshold)",
details = "Please use weight.min instead"
)
weight.min = subset.threshold
}

if (isTRUE(top8.nodes)) {
warning("top8.nodes is deprecated")
if (lifecycle::is_present(top8.nodes)) {
lifecycle::deprecate_warn(
when = "2.2.2",
what = "ggnet(top8.nodes)"
)
}

if (isTRUE(trim.labels)) {
warning("trim.labels is deprecated; please use label.trim instead")
if (lifecycle::is_present(trim.labels)) {
lifecycle::deprecate_warn(
when = "2.2.2",
what = "ggnet(trim.labels)",
details = "Please use label.trim instead"
)
label.trim = function(x) gsub("^@|^http://(www\\.)?|/$", "", x)
}

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.

11 changes: 7 additions & 4 deletions man/ggally_cor_v1_5.Rd

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

2 changes: 1 addition & 1 deletion man/ggmatrix_gtable.Rd

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

23 changes: 13 additions & 10 deletions man/ggnet.Rd

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