Skip to content

Commit d2cf9db

Browse files
teunbrandthomasp85
andauthored
Bump deprecations (#6138)
* `deprecate_stop()` for everything prior to ggplot2 3.0.0 * stuff before 3.2.0 becomes proper warning * add news bullet * document * use tidy eval idioms to replace old idioms * run revdepcheck * use dynamic deprecation strategy in `fix_bin_params()` * just treat old elements as any other misspelled element * Get more in-your-face about deprecating size in favour of linewidth * bump `qplot()` * Turn `fix_labeller()` into a check function * bump version in bullet --------- Co-authored-by: Thomas Lin Pedersen <[email protected]>
1 parent f21a858 commit d2cf9db

22 files changed

+18648
-23897
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# ggplot2 (development version)
22

3+
* Deprecated functions and arguments prior to ggplot2 3.0.0 throw errors instead
4+
of warnings.
5+
* Functions and arguments that were soft-deprecated up to ggplot2 3.4.0 now
6+
throw warnings.
37
* (internal) layer data can be attenuated with parameter attributes
48
(@teunbrand, #3175).
59
* Date scales silently coerce <POSIXct> to <Date> and datetime scales silently

R/aes.R

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ is_position_aes <- function(vars) {
290290
#'
291291
#' @export
292292
aes_ <- function(x, y, ...) {
293-
deprecate_soft0(
293+
deprecate_warn0(
294294
"3.0.0",
295295
"aes_()",
296296
details = "Please use tidy evaluation idioms with `aes()`"
@@ -317,7 +317,7 @@ aes_ <- function(x, y, ...) {
317317
#' @rdname aes_
318318
#' @export
319319
aes_string <- function(x, y, ...) {
320-
deprecate_soft0(
320+
deprecate_warn0(
321321
"3.0.0",
322322
"aes_string()",
323323
details = c(
@@ -374,29 +374,7 @@ aes_all <- function(vars) {
374374
#' @keywords internal
375375
#' @export
376376
aes_auto <- function(data = NULL, ...) {
377-
deprecate_warn0("2.0.0", "aes_auto()")
378-
379-
# detect names of data
380-
if (is.null(data)) {
381-
cli::cli_abort("{.fn aes_auto} requires a {.cls data.frame} or names of data.frame.")
382-
} else if (is.data.frame(data)) {
383-
vars <- names(data)
384-
} else {
385-
vars <- data
386-
}
387-
388-
# automatically detected aes
389-
vars <- intersect(ggplot_global$all_aesthetics, vars)
390-
names(vars) <- vars
391-
aes <- lapply(vars, function(x) parse(text = x)[[1]])
392-
393-
# explicitly defined aes
394-
if (length(match.call()) > 2) {
395-
args <- as.list(match.call()[-1])
396-
aes <- c(aes, args[names(args) != "data"])
397-
}
398-
399-
structure(rename_aes(aes), class = "uneval")
377+
lifecycle::deprecate_stop("2.0.0", "aes_auto()")
400378
}
401379

402380
mapped_aesthetics <- function(x) {

R/annotation-custom.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ GeomCustomAnn <- ggproto("GeomCustomAnn", Geom,
8080
editGrob(grob, vp = vp, name = paste(grob$name, annotation_id()))
8181
},
8282

83-
default_aes = aes_(xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf)
83+
default_aes = aes(xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf)
8484
)
8585

8686
annotation_id <- local({

R/bin.R

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,18 +240,24 @@ bin_loc <- function(x, id) {
240240
)
241241
}
242242

243-
fix_bin_params = function(params, fun, version) {
243+
fix_bin_params <- function(params, fun, version) {
244+
245+
if (package_version(version) < "3.0.0") {
246+
deprecate <- lifecycle::deprecate_stop
247+
} else {
248+
deprecate <- deprecate_warn0
249+
}
244250

245251
if (!is.null(params$origin)) {
246252
args <- paste0(fun, c("(origin)", "(boundary)"))
247-
deprecate_warn0(version, args[1], args[2])
248-
params$boudnary <- params$origin
253+
deprecate(version, args[1], args[2])
254+
params$boundary <- params$origin
249255
params$origin <- NULL
250256
}
251257

252258
if (!is.null(params$right)) {
253259
args <- paste0(fun, c("(right)", "(closed)"))
254-
deprecate_warn0(version, args[1], args[2])
260+
deprecate(version, args[1], args[2])
255261
params$closed <- if (isTRUE(params$right)) "right" else "left"
256262
params$right <- NULL
257263
}

R/facet-grid-.R

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,9 @@ facet_grid <- function(rows = NULL, cols = NULL, scales = "fixed",
132132
switch = NULL, drop = TRUE, margins = FALSE,
133133
axes = "margins", axis.labels = "all",
134134
facets = deprecated()) {
135-
# `facets` is deprecated and renamed to `rows`
135+
# `facets` is deprecated
136136
if (lifecycle::is_present(facets)) {
137-
deprecate_warn0("2.2.0", "facet_grid(facets)", "facet_grid(rows)")
138-
rows <- facets
137+
lifecycle::deprecate_stop("2.2.0", "facet_grid(facets)", "facet_grid(rows)")
139138
}
140139

141140
# Should become a warning in a future release
@@ -177,7 +176,7 @@ facet_grid <- function(rows = NULL, cols = NULL, scales = "fixed",
177176
facets_list <- grid_as_facets_list(rows, cols)
178177

179178
# Check for deprecated labellers
180-
labeller <- fix_labeller(labeller)
179+
check_labeller(labeller)
181180

182181
ggproto(NULL, FacetGrid,
183182
shrink = shrink,

R/facet-wrap.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,15 @@ facet_wrap <- function(facets, nrow = NULL, ncol = NULL, scales = "fixed",
174174
)
175175

176176
# Check for deprecated labellers
177-
labeller <- fix_labeller(labeller)
177+
check_labeller(labeller)
178178

179179
# Flatten all facets dimensions into a single one
180180
facets <- compact_facets(facets)
181181

182182
if (lifecycle::is_present(switch) && !is.null(switch)) {
183-
deprecate_warn0("2.2.0", "facet_wrap(switch)", "facet_wrap(strip.position)")
184-
strip.position <- if (switch == "x") "bottom" else "left"
183+
lifecycle::deprecate_stop(
184+
"2.2.0", "facet_wrap(switch)", "facet_wrap(strip.position)"
185+
)
185186
}
186187
strip.position <- arg_match0(strip.position, c("top", "bottom", "left", "right"))
187188

R/fortify-map.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,6 @@ map_data <- function(map, region = ".", exact = FALSE, ...) {
159159
borders <- function(database = "world", regions = ".", fill = NA,
160160
colour = "grey50", xlim = NULL, ylim = NULL, ...) {
161161
df <- map_data(database, regions, xlim = xlim, ylim = ylim)
162-
geom_polygon(aes_(~long, ~lat, group = ~group), data = df,
162+
geom_polygon(aes(.data$long, .data$lat, group = .data$group), data = df,
163163
fill = fill, colour = colour, ..., inherit.aes = FALSE)
164164
}

R/geom-.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ Geom <- ggproto("Geom",
126126
# Take care of subclasses setting the wrong default when inheriting from
127127
# a geom with rename_size = TRUE
128128
if (self$rename_size && is.null(default_aes$linewidth)) {
129-
deprecate_soft0("3.4.0", I("Using the `size` aesthetic in this geom"), I("`linewidth` in the `default_aes` field and elsewhere"))
129+
deprecate_warn0("3.4.0", I("Using the `size` aesthetic in this geom"), I("`linewidth` in the `default_aes` field and elsewhere"))
130130
default_aes$linewidth <- default_aes$size
131131
}
132132

@@ -281,7 +281,7 @@ check_aesthetics <- function(x, n) {
281281

282282
fix_linewidth <- function(data, name) {
283283
if (is.null(data$linewidth) && !is.null(data$size)) {
284-
deprecate_soft0("3.4.0", I(paste0("Using the `size` aesthetic with ", name)), I("the `linewidth` aesthetic"))
284+
deprecate_warn0("3.4.0", I(paste0("Using the `size` aesthetic with ", name)), I("the `linewidth` aesthetic"))
285285
data$linewidth <- data$size
286286
}
287287
data

R/geom-spoke.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ geom_spoke <- function(mapping = NULL, data = NULL,
4747
#' @rdname geom_spoke
4848
#' @usage NULL
4949
stat_spoke <- function(...) {
50-
deprecate_warn0("2.0.0", "stat_spoke()", "geom_spoke()")
51-
geom_spoke(...)
50+
lifecycle::deprecate_stop("2.0.0", "stat_spoke()", "geom_spoke()")
5251
}
5352

5453
#' @rdname ggplot2-ggproto

R/labeller.R

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ labeller <- function(..., .rows = NULL, .cols = NULL,
411411
keep.as.numeric = deprecated(), .multi_line = TRUE,
412412
.default = label_value) {
413413
if (lifecycle::is_present(keep.as.numeric)) {
414-
deprecate_warn0("2.0.0", "labeller(keep.as.numeric)")
414+
lifecycle::deprecate_stop("2.0.0", "labeller(keep.as.numeric)")
415415
}
416416
dots <- list2(...)
417417
.default <- as_labeller(.default)
@@ -577,22 +577,18 @@ assemble_strips <- function(grobs, theme, horizontal = TRUE, clip) {
577577
})
578578
}
579579

580-
# Repair old school labeller
581-
fix_labeller <- function(labeller) {
580+
# Reject old school labeller
581+
check_labeller <- function(labeller) {
582+
582583
labeller <- match.fun(labeller)
583584
is_deprecated <- all(c("variable", "value") %in% names(formals(labeller)))
584585

585-
if (is_deprecated) {
586-
deprecate_warn0(
587-
"2.0.0", what = "facet_(labeller)",
588-
details =
589-
"Modern labellers do not take `variable` and `value` arguments anymore."
590-
)
591-
old_labeller <- labeller
592-
labeller <- function(labels) {
593-
Map(old_labeller, names(labels), labels)
594-
}
586+
if (!is_deprecated) {
587+
return(invisible())
595588
}
596589

597-
labeller
590+
lifecycle::deprecate_stop(
591+
"2.0.0",
592+
what = I("Providing a labeller with `variable` and `value` arguments")
593+
)
598594
}

R/layer.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ layer <- function(geom = NULL, stat = NULL,
104104

105105
# Handle show_guide/show.legend
106106
if (!is.null(params$show_guide)) {
107-
deprecate_warn0("2.0.0", "layer(show_guide)", "layer(show.legend)", user_env = user_env)
108-
show.legend <- params$show_guide
109-
params$show_guide <- NULL
107+
lifecycle::deprecate_stop(
108+
"2.0.0", "layer(show_guide)", "layer(show.legend)"
109+
)
110110
}
111111

112112
# we validate mapping before data because in geoms and stats
@@ -156,7 +156,7 @@ layer <- function(geom = NULL, stat = NULL,
156156
if (geom$rename_size && "size" %in% extra_param && !"linewidth" %in% mapped_aesthetics(mapping)) {
157157
aes_params <- c(aes_params, params["size"])
158158
extra_param <- setdiff(extra_param, "size")
159-
deprecate_soft0("3.4.0", I("Using `size` aesthetic for lines"), I("`linewidth`"), user_env = user_env)
159+
deprecate_warn0("3.4.0", I("Using `size` aesthetic for lines"), I("`linewidth`"), user_env = user_env)
160160
}
161161
if (check.param && length(extra_param) > 0) {
162162
cli::cli_warn("Ignoring unknown parameters: {.arg {extra_param}}", call = call_env)
@@ -169,7 +169,7 @@ layer <- function(geom = NULL, stat = NULL,
169169
# Take care of size->linewidth aes renaming
170170
if (geom$rename_size && "size" %in% extra_aes && !"linewidth" %in% mapped_aesthetics(mapping)) {
171171
extra_aes <- setdiff(extra_aes, "size")
172-
deprecate_soft0("3.4.0", I("Using `size` aesthetic for lines"), I("`linewidth`"), user_env = user_env)
172+
deprecate_warn0("3.4.0", I("Using `size` aesthetic for lines"), I("`linewidth`"), user_env = user_env)
173173
}
174174
if (check.aes && length(extra_aes) > 0) {
175175
cli::cli_warn("Ignoring unknown aesthetics: {.field {extra_aes}}", call = call_env)
@@ -273,7 +273,7 @@ Layer <- ggproto("Layer", NULL,
273273
!"linewidth" %in% names(self$computed_mapping) &&
274274
"linewidth" %in% self$geom$aesthetics()) {
275275
self$computed_mapping$size <- plot$mapping$size
276-
deprecate_soft0("3.4.0", I("Using `size` aesthetic for lines"), I("`linewidth`"))
276+
deprecate_warn0("3.4.0", I("Using `size` aesthetic for lines"), I("`linewidth`"))
277277
}
278278
# defaults() strips class, but it needs to be preserved for now
279279
class(self$computed_mapping) <- "uneval"

R/plot.R

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,17 @@ plot_clone <- function(plot) {
178178
#' @export
179179
#' @method print ggplot
180180
#' @examples
181-
#' colours <- list(~class, ~drv, ~fl)
181+
#' colours <- c("class", "drv", "fl")
182182
#'
183183
#' # Doesn't seem to do anything!
184184
#' for (colour in colours) {
185-
#' ggplot(mpg, aes_(~ displ, ~ hwy, colour = colour)) +
185+
#' ggplot(mpg, aes(displ, hwy, colour = .data[[colour]])) +
186186
#' geom_point()
187187
#' }
188188
#'
189-
#' # Works when we explicitly print the plots
190189
#' for (colour in colours) {
191-
#' print(ggplot(mpg, aes_(~ displ, ~ hwy, colour = colour)) +
192-
#' geom_point())
190+
#' print(ggplot(mpg, aes(displ, hwy, colour = .data[[colour]])) +
191+
#' geom_point())
193192
#' }
194193
print.ggplot <- function(x, newpage = is.null(vp), vp = NULL, ...) {
195194
set_last_plot(x)

R/quick-plot.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ qplot <- function(x, y, ..., data, facets = NULL, margins = FALSE,
6262
xlab = NULL, ylab = NULL,
6363
asp = NA, stat = deprecated(), position = deprecated()) {
6464

65-
deprecate_soft0("3.4.0", "qplot()")
65+
deprecate_warn0("3.4.0", "qplot()")
6666

6767
caller_env <- parent.frame()
6868

R/theme-elements.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ element_rect <- function(fill = NULL, colour = NULL, linewidth = NULL,
9494
linetype = NULL, color = NULL, inherit.blank = FALSE, size = deprecated()) {
9595

9696
if (lifecycle::is_present(size)) {
97-
deprecate_soft0("3.4.0", "element_rect(size)", "element_rect(linewidth)")
97+
deprecate_warn0("3.4.0", "element_rect(size)", "element_rect(linewidth)")
9898
linewidth <- size
9999
}
100100

@@ -115,7 +115,7 @@ element_line <- function(colour = NULL, linewidth = NULL, linetype = NULL,
115115
inherit.blank = FALSE, size = deprecated()) {
116116

117117
if (lifecycle::is_present(size)) {
118-
deprecate_soft0("3.4.0", "element_line(size)", "element_line(linewidth)")
118+
deprecate_warn0("3.4.0", "element_line(size)", "element_line(linewidth)")
119119
linewidth <- size
120120
}
121121

@@ -307,7 +307,7 @@ element_grob.element_rect <- function(element, x = 0.5, y = 0.5,
307307
fill = NULL, colour = NULL, linewidth = NULL, linetype = NULL, ..., size = deprecated()) {
308308

309309
if (lifecycle::is_present(size)) {
310-
deprecate_soft0("3.4.0", "element_grob.element_rect(size)", "element_grob.element_rect(linewidth)")
310+
deprecate_warn0("3.4.0", "element_grob.element_rect(size)", "element_grob.element_rect(linewidth)")
311311
linewidth <- size
312312
}
313313

@@ -357,7 +357,7 @@ element_grob.element_line <- function(element, x = 0:1, y = 0:1,
357357
default.units = "npc", id.lengths = NULL, ..., size = deprecated()) {
358358

359359
if (lifecycle::is_present(size)) {
360-
deprecate_soft0("3.4.0", "element_grob.element_line(size)", "element_grob.element_line(linewidth)")
360+
deprecate_warn0("3.4.0", "element_grob.element_line(size)", "element_grob.element_line(linewidth)")
361361
linewidth <- size
362362
}
363363

R/theme.R

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -469,34 +469,6 @@ theme <- function(...,
469469
validate = TRUE) {
470470
elements <- find_args(..., complete = NULL, validate = NULL)
471471

472-
if (!is.null(elements$axis.ticks.margin)) {
473-
deprecate_warn0(
474-
"2.0.0", "theme(axis.ticks.margin)",
475-
details = "Please set `margin` property of `axis.text` instead"
476-
)
477-
elements$axis.ticks.margin <- NULL
478-
}
479-
if (!is.null(elements$panel.margin)) {
480-
deprecate_warn0(
481-
"2.2.0", "theme(panel.margin)", "theme(panel.spacing)"
482-
)
483-
elements$panel.spacing <- elements$panel.margin
484-
elements$panel.margin <- NULL
485-
}
486-
if (!is.null(elements$panel.margin.x)) {
487-
deprecate_warn0(
488-
"2.2.0", "theme(panel.margin.x)", "theme(panel.spacing.x)"
489-
)
490-
elements$panel.spacing.x <- elements$panel.margin.x
491-
elements$panel.margin.x <- NULL
492-
}
493-
if (!is.null(elements$panel.margin.y)) {
494-
deprecate_warn0(
495-
"2.2.0", "theme(panel.margin.y)", "theme(panel.spacing.y)"
496-
)
497-
elements$panel.spacing.y <- elements$panel.margin.y
498-
elements$panel.margin.y <- NULL
499-
}
500472
if (is.unit(elements$legend.margin) && !is.margin(elements$legend.margin)) {
501473
cli::cli_warn(c(
502474
"{.var legend.margin} must be specified using {.fn margin}",

man/print.ggplot.Rd

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)