Skip to content

Commit

Permalink
Deprecate params in ggnet function
Browse files Browse the repository at this point in the history
  • Loading branch information
92amartins committed Apr 24, 2024
1 parent fee9c60 commit 17bbdc4
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 38 deletions.
67 changes: 45 additions & 22 deletions R/ggnet.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,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 Down Expand Up @@ -199,11 +199,11 @@ 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(),
...
) {

Expand All @@ -213,32 +213,55 @@ ggnet <- function(
# -- 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
1 change: 0 additions & 1 deletion man/ggally_cor_v1_5.Rd

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

20 changes: 10 additions & 10 deletions man/ggnet.Rd

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

10 changes: 5 additions & 5 deletions tests/testthat/test-ggnet.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ test_that("examples", {
xy <- gplot.layout.circle(n) # nolint
n %v% "lon" <- xy[, 1]
n %v% "lat" <- xy[, 2]
expect_warning(ggnet(n, mode = "geo"), "deprecated")
lifecycle::expect_deprecated(ggnet(n, mode = "geo"))

# test names = c(x, y)
expect_warning(ggnet(n, names = c("a", "b")), "deprecated")
lifecycle::expect_deprecated(ggnet(n, names = c("a", "b")))

# test quantize.weights
with_options(list(warn = 2), {
Expand All @@ -62,14 +62,14 @@ test_that("examples", {

# test subset.threshold
suppressMessages({
expect_warning(ggnet(n, subset.threshold = 2))
lifecycle::expect_deprecated(ggnet(n, subset.threshold = 2))
})

# test top8.nodes
expect_warning(ggnet(n, top8.nodes = TRUE))
lifecycle::expect_deprecated(ggnet(n, top8.nodes = TRUE))

# test trim.labels
expect_warning(ggnet(n, trim.labels = TRUE))
lifecycle::expect_deprecated(ggnet(n, trim.labels = TRUE))

# # test subset.threshold by removing all nodes
# expect_warning(
Expand Down

0 comments on commit 17bbdc4

Please sign in to comment.