From acf3c1c7251d014b5d3e43e05fa5af5a1bf05b71 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 15 Oct 2024 10:36:16 +0200 Subject: [PATCH 1/5] `deprecate_stop()` for everything prior to ggplot2 3.0.0 --- R/aes.R | 24 +----------------------- R/facet-grid-.R | 5 ++--- R/facet-wrap.R | 5 +++-- R/geom-spoke.R | 3 +-- R/labeller.R | 2 +- R/layer.R | 6 +++--- R/stat-bin.R | 11 +++-------- R/theme.R | 15 ++++----------- 8 files changed, 18 insertions(+), 53 deletions(-) diff --git a/R/aes.R b/R/aes.R index 0829f64daf..352dd21c4f 100644 --- a/R/aes.R +++ b/R/aes.R @@ -367,29 +367,7 @@ aes_all <- function(vars) { #' @keywords internal #' @export aes_auto <- function(data = NULL, ...) { - deprecate_warn0("2.0.0", "aes_auto()") - - # detect names of data - if (is.null(data)) { - cli::cli_abort("{.fn aes_auto} requires a {.cls data.frame} or names of data.frame.") - } else if (is.data.frame(data)) { - vars <- names(data) - } else { - vars <- data - } - - # automatically detected aes - vars <- intersect(ggplot_global$all_aesthetics, vars) - names(vars) <- vars - aes <- lapply(vars, function(x) parse(text = x)[[1]]) - - # explicitly defined aes - if (length(match.call()) > 2) { - args <- as.list(match.call()[-1]) - aes <- c(aes, args[names(args) != "data"]) - } - - structure(rename_aes(aes), class = "uneval") + lifecycle::deprecate_stop("2.0.0", "aes_auto()") } mapped_aesthetics <- function(x) { diff --git a/R/facet-grid-.R b/R/facet-grid-.R index 784e394885..79f79b383c 100644 --- a/R/facet-grid-.R +++ b/R/facet-grid-.R @@ -132,10 +132,9 @@ facet_grid <- function(rows = NULL, cols = NULL, scales = "fixed", switch = NULL, drop = TRUE, margins = FALSE, axes = "margins", axis.labels = "all", facets = deprecated()) { - # `facets` is deprecated and renamed to `rows` + # `facets` is deprecated if (lifecycle::is_present(facets)) { - deprecate_warn0("2.2.0", "facet_grid(facets)", "facet_grid(rows)") - rows <- facets + lifecycle::deprecate_stop("2.2.0", "facet_grid(facets)", "facet_grid(rows)") } # Should become a warning in a future release diff --git a/R/facet-wrap.R b/R/facet-wrap.R index 114b3332d9..2f9b3f0e64 100644 --- a/R/facet-wrap.R +++ b/R/facet-wrap.R @@ -180,8 +180,9 @@ facet_wrap <- function(facets, nrow = NULL, ncol = NULL, scales = "fixed", facets <- compact_facets(facets) if (lifecycle::is_present(switch) && !is.null(switch)) { - deprecate_warn0("2.2.0", "facet_wrap(switch)", "facet_wrap(strip.position)") - strip.position <- if (switch == "x") "bottom" else "left" + lifecycle::deprecate_stop( + "2.2.0", "facet_wrap(switch)", "facet_wrap(strip.position)" + ) } strip.position <- arg_match0(strip.position, c("top", "bottom", "left", "right")) diff --git a/R/geom-spoke.R b/R/geom-spoke.R index 032267b765..9ffbe71144 100644 --- a/R/geom-spoke.R +++ b/R/geom-spoke.R @@ -47,8 +47,7 @@ geom_spoke <- function(mapping = NULL, data = NULL, #' @rdname geom_spoke #' @usage NULL stat_spoke <- function(...) { - deprecate_warn0("2.0.0", "stat_spoke()", "geom_spoke()") - geom_spoke(...) + lifecycle::deprecate_stop("2.0.0", "stat_spoke()", "geom_spoke()") } #' @rdname ggplot2-ggproto diff --git a/R/labeller.R b/R/labeller.R index 4ca220c2b4..eac1f85111 100644 --- a/R/labeller.R +++ b/R/labeller.R @@ -411,7 +411,7 @@ labeller <- function(..., .rows = NULL, .cols = NULL, keep.as.numeric = deprecated(), .multi_line = TRUE, .default = label_value) { if (lifecycle::is_present(keep.as.numeric)) { - deprecate_warn0("2.0.0", "labeller(keep.as.numeric)") + lifecycle::deprecate_stop("2.0.0", "labeller(keep.as.numeric)") } dots <- list2(...) .default <- as_labeller(.default) diff --git a/R/layer.R b/R/layer.R index b10c230e1d..9c0923ed43 100644 --- a/R/layer.R +++ b/R/layer.R @@ -110,9 +110,9 @@ layer <- function(geom = NULL, stat = NULL, # Handle show_guide/show.legend if (!is.null(params$show_guide)) { - deprecate_warn0("2.0.0", "layer(show_guide)", "layer(show.legend)", user_env = user_env) - show.legend <- params$show_guide - params$show_guide <- NULL + lifecycle::deprecate_stop( + "2.0.0", "layer(show_guide)", "layer(show.legend)" + ) } # we validate mapping before data because in geoms and stats diff --git a/R/stat-bin.R b/R/stat-bin.R index c085f818a2..1e81df53dd 100644 --- a/R/stat-bin.R +++ b/R/stat-bin.R @@ -109,18 +109,13 @@ StatBin <- ggproto("StatBin", Stat, } if (!is.null(params$drop)) { - deprecate_warn0("2.1.0", "stat_bin(drop)", "stat_bin(pad)") - params$drop <- NULL + lifecycle::deprecate_stop("2.1.0", "stat_bin(drop)", "stat_bin(pad)") } if (!is.null(params$origin)) { - deprecate_warn0("2.1.0", "stat_bin(origin)", "stat_bin(boundary)") - params$boundary <- params$origin - params$origin <- NULL + lifecycle::deprecate_stop("2.1.0", "stat_bin(origin)", "stat_bin(boundary)") } if (!is.null(params$right)) { - deprecate_warn0("2.1.0", "stat_bin(right)", "stat_bin(closed)") - params$closed <- if (params$right) "right" else "left" - params$right <- NULL + lifecycle::deprecate_stop("2.1.0", "stat_bin(right)", "stat_bin(closed)") } if (!is.null(params$boundary) && !is.null(params$center)) { cli::cli_abort("Only one of {.arg boundary} and {.arg center} may be specified in {.fn {snake_class(self)}}.") diff --git a/R/theme.R b/R/theme.R index 2eedd300c5..db93a3bf20 100644 --- a/R/theme.R +++ b/R/theme.R @@ -456,32 +456,25 @@ theme <- function(..., elements <- find_args(..., complete = NULL, validate = NULL) if (!is.null(elements$axis.ticks.margin)) { - deprecate_warn0( + lifecycle::deprecate_stop( "2.0.0", "theme(axis.ticks.margin)", details = "Please set `margin` property of `axis.text` instead" ) - elements$axis.ticks.margin <- NULL } if (!is.null(elements$panel.margin)) { - deprecate_warn0( + lifecycle::deprecate_stop( "2.2.0", "theme(panel.margin)", "theme(panel.spacing)" ) - elements$panel.spacing <- elements$panel.margin - elements$panel.margin <- NULL } if (!is.null(elements$panel.margin.x)) { - deprecate_warn0( + lifecycle::deprecate_stop( "2.2.0", "theme(panel.margin.x)", "theme(panel.spacing.x)" ) - elements$panel.spacing.x <- elements$panel.margin.x - elements$panel.margin.x <- NULL } if (!is.null(elements$panel.margin.y)) { - deprecate_warn0( + lifecycle::deprecate_stop( "2.2.0", "theme(panel.margin.y)", "theme(panel.spacing.y)" ) - elements$panel.spacing.y <- elements$panel.margin.y - elements$panel.margin.y <- NULL } if (is.unit(elements$legend.margin) && !is.margin(elements$legend.margin)) { cli::cli_warn(c( From ee0c9de05cd622a4701b538372b386643cd90585 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 15 Oct 2024 11:07:59 +0200 Subject: [PATCH 2/5] stuff before 3.2.0 becomes proper warning --- R/aes.R | 4 ++-- R/annotation-custom.R | 2 +- R/fortify-map.R | 2 +- R/plot.R | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/R/aes.R b/R/aes.R index 352dd21c4f..cc31c56f48 100644 --- a/R/aes.R +++ b/R/aes.R @@ -283,7 +283,7 @@ is_position_aes <- function(vars) { #' #' @export aes_ <- function(x, y, ...) { - deprecate_soft0( + deprecate_warn0( "3.0.0", "aes_()", details = "Please use tidy evaluation idioms with `aes()`" @@ -310,7 +310,7 @@ aes_ <- function(x, y, ...) { #' @rdname aes_ #' @export aes_string <- function(x, y, ...) { - deprecate_soft0( + deprecate_warn0( "3.0.0", "aes_string()", details = c( diff --git a/R/annotation-custom.R b/R/annotation-custom.R index 4261526b89..76f2c2b7de 100644 --- a/R/annotation-custom.R +++ b/R/annotation-custom.R @@ -89,7 +89,7 @@ GeomCustomAnn <- ggproto("GeomCustomAnn", Geom, editGrob(grob, vp = vp, name = paste(grob$name, annotation_id())) }, - default_aes = aes_(xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf) + default_aes = aes(xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf) ) annotation_id <- local({ diff --git a/R/fortify-map.R b/R/fortify-map.R index d0dc76b716..31bf3a3911 100644 --- a/R/fortify-map.R +++ b/R/fortify-map.R @@ -133,6 +133,6 @@ map_data <- function(map, region = ".", exact = FALSE, ...) { borders <- function(database = "world", regions = ".", fill = NA, colour = "grey50", xlim = NULL, ylim = NULL, ...) { df <- map_data(database, regions, xlim = xlim, ylim = ylim) - geom_polygon(aes_(~long, ~lat, group = ~group), data = df, + geom_polygon(aes(long, lat, group = group), data = df, fill = fill, colour = colour, ..., inherit.aes = FALSE) } diff --git a/R/plot.R b/R/plot.R index f6a6aaeb49..9baaf63bea 100644 --- a/R/plot.R +++ b/R/plot.R @@ -182,13 +182,13 @@ plot_clone <- function(plot) { #' #' # Doesn't seem to do anything! #' for (colour in colours) { -#' ggplot(mpg, aes_(~ displ, ~ hwy, colour = colour)) + +#' ggplot(mpg, aes(displ, hwy, colour = colour)) + #' geom_point() #' } #' #' # Works when we explicitly print the plots #' for (colour in colours) { -#' print(ggplot(mpg, aes_(~ displ, ~ hwy, colour = colour)) + +#' print(ggplot(mpg, aes(displ, hwy, colour = colour)) + #' geom_point()) #' } print.ggplot <- function(x, newpage = is.null(vp), vp = NULL, ...) { From 3e18e9e1c633ae34606233800d37e470e437cf25 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 15 Oct 2024 11:11:42 +0200 Subject: [PATCH 3/5] add news bullet --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index f369879868..4aef25f94a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # ggplot2 (development version) +* Deprecated functions and arguments prior to ggplot2 3.0.0 throw errors instead + of warnings. +* Functions and arguments that were soft-deprecated up to ggplot2 3.2.0 now + throw warnings. * Fixed bug where the `ggplot2::`-prefix did not work with `stage()` (@teunbrand, #6104). * New `get_labs()` function for retrieving completed plot labels From 3e7155f38963e63f46643a57da283f740402c6a8 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 15 Oct 2024 11:16:41 +0200 Subject: [PATCH 4/5] document --- man/print.ggplot.Rd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/man/print.ggplot.Rd b/man/print.ggplot.Rd index 07b2a68942..4fdb4763eb 100644 --- a/man/print.ggplot.Rd +++ b/man/print.ggplot.Rd @@ -32,13 +32,13 @@ colours <- list(~class, ~drv, ~fl) # Doesn't seem to do anything! for (colour in colours) { - ggplot(mpg, aes_(~ displ, ~ hwy, colour = colour)) + + ggplot(mpg, aes(displ, hwy, colour = colour)) + geom_point() } # Works when we explicitly print the plots for (colour in colours) { - print(ggplot(mpg, aes_(~ displ, ~ hwy, colour = colour)) + + print(ggplot(mpg, aes(displ, hwy, colour = colour)) + geom_point()) } } From edb9c453ce2a87ce6471085ad1d765a645634dea Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 15 Oct 2024 12:28:41 +0200 Subject: [PATCH 5/5] use tidy eval idioms to replace old idioms --- R/fortify-map.R | 2 +- R/plot.R | 9 ++++----- man/print.ggplot.Rd | 9 ++++----- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/R/fortify-map.R b/R/fortify-map.R index 31bf3a3911..e63485fedf 100644 --- a/R/fortify-map.R +++ b/R/fortify-map.R @@ -133,6 +133,6 @@ map_data <- function(map, region = ".", exact = FALSE, ...) { borders <- function(database = "world", regions = ".", fill = NA, colour = "grey50", xlim = NULL, ylim = NULL, ...) { df <- map_data(database, regions, xlim = xlim, ylim = ylim) - geom_polygon(aes(long, lat, group = group), data = df, + geom_polygon(aes(.data$long, .data$lat, group = .data$group), data = df, fill = fill, colour = colour, ..., inherit.aes = FALSE) } diff --git a/R/plot.R b/R/plot.R index 9baaf63bea..c992530a0b 100644 --- a/R/plot.R +++ b/R/plot.R @@ -178,18 +178,17 @@ plot_clone <- function(plot) { #' @export #' @method print ggplot #' @examples -#' colours <- list(~class, ~drv, ~fl) +#' colours <- c("class", "drv", "fl") #' #' # Doesn't seem to do anything! #' for (colour in colours) { -#' ggplot(mpg, aes(displ, hwy, colour = colour)) + +#' ggplot(mpg, aes(displ, hwy, colour = .data[[colour]])) + #' geom_point() #' } #' -#' # Works when we explicitly print the plots #' for (colour in colours) { -#' print(ggplot(mpg, aes(displ, hwy, colour = colour)) + -#' geom_point()) +#' print(ggplot(mpg, aes(displ, hwy, colour = .data[[colour]])) + +#' geom_point()) #' } print.ggplot <- function(x, newpage = is.null(vp), vp = NULL, ...) { set_last_plot(x) diff --git a/man/print.ggplot.Rd b/man/print.ggplot.Rd index 4fdb4763eb..1d558a3e9e 100644 --- a/man/print.ggplot.Rd +++ b/man/print.ggplot.Rd @@ -28,18 +28,17 @@ to call \code{print()} explicitly if you want to draw a plot inside a function or for loop. } \examples{ -colours <- list(~class, ~drv, ~fl) +colours <- c("class", "drv", "fl") # Doesn't seem to do anything! for (colour in colours) { - ggplot(mpg, aes(displ, hwy, colour = colour)) + + ggplot(mpg, aes(displ, hwy, colour = .data[[colour]])) + geom_point() } -# Works when we explicitly print the plots for (colour in colours) { - print(ggplot(mpg, aes(displ, hwy, colour = colour)) + - geom_point()) + print(ggplot(mpg, aes(displ, hwy, colour = .data[[colour]])) + + geom_point()) } } \keyword{hplot}