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

Bump deprecations #6138

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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.4.0 now
throw warnings.
* New parameters for `geom_label()` (@teunbrand and @steveharoz, #5365):
* The `linewidth` aesthetic is now applied and replaces the `label.size`
argument.
Expand Down
28 changes: 3 additions & 25 deletions R/aes.R
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@
#'
#' @export
aes_ <- function(x, y, ...) {
deprecate_soft0(
deprecate_warn0(
"3.0.0",
"aes_()",
details = "Please use tidy evaluation idioms with `aes()`"
Expand All @@ -317,7 +317,7 @@
#' @rdname aes_
#' @export
aes_string <- function(x, y, ...) {
deprecate_soft0(
deprecate_warn0(
"3.0.0",
"aes_string()",
details = c(
Expand Down Expand Up @@ -374,29 +374,7 @@
#' @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()")

Check warning on line 377 in R/aes.R

View check run for this annotation

Codecov / codecov/patch

R/aes.R#L377

Added line #L377 was not covered by tests
}

mapped_aesthetics <- function(x) {
Expand Down
2 changes: 1 addition & 1 deletion R/annotation-custom.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,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({
Expand Down
14 changes: 10 additions & 4 deletions R/bin.R
Original file line number Diff line number Diff line change
Expand Up @@ -240,18 +240,24 @@
)
}

fix_bin_params = function(params, fun, version) {
fix_bin_params <- function(params, fun, version) {

if (package_version(version) < "3.0.0") {
deprecate <- lifecycle::deprecate_stop
} else {
deprecate <- deprecate_warn0
}

if (!is.null(params$origin)) {
args <- paste0(fun, c("(origin)", "(boundary)"))
deprecate_warn0(version, args[1], args[2])
params$boudnary <- params$origin
deprecate(version, args[1], args[2])
params$boundary <- params$origin

Check warning on line 254 in R/bin.R

View check run for this annotation

Codecov / codecov/patch

R/bin.R#L253-L254

Added lines #L253 - L254 were not covered by tests
params$origin <- NULL
}

if (!is.null(params$right)) {
args <- paste0(fun, c("(right)", "(closed)"))
deprecate_warn0(version, args[1], args[2])
deprecate(version, args[1], args[2])

Check warning on line 260 in R/bin.R

View check run for this annotation

Codecov / codecov/patch

R/bin.R#L260

Added line #L260 was not covered by tests
params$closed <- if (isTRUE(params$right)) "right" else "left"
params$right <- NULL
}
Expand Down
7 changes: 3 additions & 4 deletions R/facet-grid-.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,9 @@
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)")

Check warning on line 137 in R/facet-grid-.R

View check run for this annotation

Codecov / codecov/patch

R/facet-grid-.R#L137

Added line #L137 was not covered by tests
}

# Should become a warning in a future release
Expand Down Expand Up @@ -177,7 +176,7 @@
facets_list <- grid_as_facets_list(rows, cols)

# Check for deprecated labellers
labeller <- fix_labeller(labeller)
check_labeller(labeller)

ggproto(NULL, FacetGrid,
shrink = shrink,
Expand Down
7 changes: 4 additions & 3 deletions R/facet-wrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,15 @@
)

# Check for deprecated labellers
labeller <- fix_labeller(labeller)
check_labeller(labeller)

# Flatten all facets dimensions into a single one
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)"
)

Check warning on line 185 in R/facet-wrap.R

View check run for this annotation

Codecov / codecov/patch

R/facet-wrap.R#L183-L185

Added lines #L183 - L185 were not covered by tests
}
strip.position <- arg_match0(strip.position, c("top", "bottom", "left", "right"))

Expand Down
2 changes: 1 addition & 1 deletion R/fortify-map.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,6 @@
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,

Check warning on line 162 in R/fortify-map.R

View check run for this annotation

Codecov / codecov/patch

R/fortify-map.R#L162

Added line #L162 was not covered by tests
fill = fill, colour = colour, ..., inherit.aes = FALSE)
}
4 changes: 2 additions & 2 deletions R/geom-.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
# Take care of subclasses setting the wrong default when inheriting from
# a geom with rename_size = TRUE
if (self$rename_size && is.null(default_aes$linewidth)) {
deprecate_soft0("3.4.0", I("Using the `size` aesthetic in this geom"), I("`linewidth` in the `default_aes` field and elsewhere"))
deprecate_warn0("3.4.0", I("Using the `size` aesthetic in this geom"), I("`linewidth` in the `default_aes` field and elsewhere"))
default_aes$linewidth <- default_aes$size
}

Expand Down Expand Up @@ -279,7 +279,7 @@

fix_linewidth <- function(data, name) {
if (is.null(data$linewidth) && !is.null(data$size)) {
deprecate_soft0("3.4.0", I(paste0("Using the `size` aesthetic with ", name)), I("the `linewidth` aesthetic"))
deprecate_warn0("3.4.0", I(paste0("Using the `size` aesthetic with ", name)), I("the `linewidth` aesthetic"))

Check warning on line 282 in R/geom-.R

View check run for this annotation

Codecov / codecov/patch

R/geom-.R#L282

Added line #L282 was not covered by tests
data$linewidth <- data$size
}
data
Expand Down
3 changes: 1 addition & 2 deletions R/geom-spoke.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
#' @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()")

Check warning on line 50 in R/geom-spoke.R

View check run for this annotation

Codecov / codecov/patch

R/geom-spoke.R#L50

Added line #L50 was not covered by tests
}

#' @rdname ggplot2-ggproto
Expand Down
24 changes: 10 additions & 14 deletions R/labeller.R
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@
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)")

Check warning on line 414 in R/labeller.R

View check run for this annotation

Codecov / codecov/patch

R/labeller.R#L414

Added line #L414 was not covered by tests
}
dots <- list2(...)
.default <- as_labeller(.default)
Expand Down Expand Up @@ -577,22 +577,18 @@
})
}

# Repair old school labeller
fix_labeller <- function(labeller) {
# Reject old school labeller
check_labeller <- function(labeller) {

labeller <- match.fun(labeller)
is_deprecated <- all(c("variable", "value") %in% names(formals(labeller)))

if (is_deprecated) {
deprecate_warn0(
"2.0.0", what = "facet_(labeller)",
details =
"Modern labellers do not take `variable` and `value` arguments anymore."
)
old_labeller <- labeller
labeller <- function(labels) {
Map(old_labeller, names(labels), labels)
}
if (!is_deprecated) {
return(invisible())
}

labeller
lifecycle::deprecate_stop(
"2.0.0",
what = I("Providing a labeller with `variable` and `value` arguments")
)
}
12 changes: 6 additions & 6 deletions R/layer.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@

# 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)"
)

Check warning on line 109 in R/layer.R

View check run for this annotation

Codecov / codecov/patch

R/layer.R#L107-L109

Added lines #L107 - L109 were not covered by tests
}

# we validate mapping before data because in geoms and stats
Expand Down Expand Up @@ -156,7 +156,7 @@
if (geom$rename_size && "size" %in% extra_param && !"linewidth" %in% mapped_aesthetics(mapping)) {
aes_params <- c(aes_params, params["size"])
extra_param <- setdiff(extra_param, "size")
deprecate_soft0("3.4.0", I("Using `size` aesthetic for lines"), I("`linewidth`"), user_env = user_env)
deprecate_warn0("3.4.0", I("Using `size` aesthetic for lines"), I("`linewidth`"), user_env = user_env)

Check warning on line 159 in R/layer.R

View check run for this annotation

Codecov / codecov/patch

R/layer.R#L159

Added line #L159 was not covered by tests
}
if (check.param && length(extra_param) > 0) {
cli::cli_warn("Ignoring unknown parameters: {.arg {extra_param}}", call = call_env)
Expand All @@ -169,7 +169,7 @@
# Take care of size->linewidth aes renaming
if (geom$rename_size && "size" %in% extra_aes && !"linewidth" %in% mapped_aesthetics(mapping)) {
extra_aes <- setdiff(extra_aes, "size")
deprecate_soft0("3.4.0", I("Using `size` aesthetic for lines"), I("`linewidth`"), user_env = user_env)
deprecate_warn0("3.4.0", I("Using `size` aesthetic for lines"), I("`linewidth`"), user_env = user_env)

Check warning on line 172 in R/layer.R

View check run for this annotation

Codecov / codecov/patch

R/layer.R#L172

Added line #L172 was not covered by tests
}
if (check.aes && length(extra_aes) > 0) {
cli::cli_warn("Ignoring unknown aesthetics: {.field {extra_aes}}", call = call_env)
Expand Down Expand Up @@ -273,7 +273,7 @@
!"linewidth" %in% names(self$computed_mapping) &&
"linewidth" %in% self$geom$aesthetics()) {
self$computed_mapping$size <- plot$mapping$size
deprecate_soft0("3.4.0", I("Using `size` aesthetic for lines"), I("`linewidth`"))
deprecate_warn0("3.4.0", I("Using `size` aesthetic for lines"), I("`linewidth`"))
}
# defaults() strips class, but it needs to be preserved for now
class(self$computed_mapping) <- "uneval"
Expand Down
9 changes: 4 additions & 5 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion R/quick-plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ qplot <- function(x, y, ..., data, facets = NULL, margins = FALSE,
xlab = NULL, ylab = NULL,
asp = NA, stat = deprecated(), position = deprecated()) {

deprecate_soft0("3.4.0", "qplot()")
deprecate_warn0("3.4.0", "qplot()")

caller_env <- parent.frame()

Expand Down
8 changes: 4 additions & 4 deletions R/theme-elements.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
linetype = NULL, color = NULL, inherit.blank = FALSE, size = deprecated()) {

if (lifecycle::is_present(size)) {
deprecate_soft0("3.4.0", "element_rect(size)", "element_rect(linewidth)")
deprecate_warn0("3.4.0", "element_rect(size)", "element_rect(linewidth)")

Check warning on line 97 in R/theme-elements.R

View check run for this annotation

Codecov / codecov/patch

R/theme-elements.R#L97

Added line #L97 was not covered by tests
linewidth <- size
}

Expand All @@ -115,7 +115,7 @@
inherit.blank = FALSE, size = deprecated()) {

if (lifecycle::is_present(size)) {
deprecate_soft0("3.4.0", "element_line(size)", "element_line(linewidth)")
deprecate_warn0("3.4.0", "element_line(size)", "element_line(linewidth)")

Check warning on line 118 in R/theme-elements.R

View check run for this annotation

Codecov / codecov/patch

R/theme-elements.R#L118

Added line #L118 was not covered by tests
linewidth <- size
}

Expand Down Expand Up @@ -307,7 +307,7 @@
fill = NULL, colour = NULL, linewidth = NULL, linetype = NULL, ..., size = deprecated()) {

if (lifecycle::is_present(size)) {
deprecate_soft0("3.4.0", "element_grob.element_rect(size)", "element_grob.element_rect(linewidth)")
deprecate_warn0("3.4.0", "element_grob.element_rect(size)", "element_grob.element_rect(linewidth)")

Check warning on line 310 in R/theme-elements.R

View check run for this annotation

Codecov / codecov/patch

R/theme-elements.R#L310

Added line #L310 was not covered by tests
linewidth <- size
}

Expand Down Expand Up @@ -357,7 +357,7 @@
default.units = "npc", id.lengths = NULL, ..., size = deprecated()) {

if (lifecycle::is_present(size)) {
deprecate_soft0("3.4.0", "element_grob.element_line(size)", "element_grob.element_line(linewidth)")
deprecate_warn0("3.4.0", "element_grob.element_line(size)", "element_grob.element_line(linewidth)")

Check warning on line 360 in R/theme-elements.R

View check run for this annotation

Codecov / codecov/patch

R/theme-elements.R#L360

Added line #L360 was not covered by tests
linewidth <- size
}

Expand Down
28 changes: 0 additions & 28 deletions R/theme.R
Original file line number Diff line number Diff line change
Expand Up @@ -469,34 +469,6 @@ theme <- function(...,
validate = TRUE) {
elements <- find_args(..., complete = NULL, validate = NULL)

if (!is.null(elements$axis.ticks.margin)) {
deprecate_warn0(
"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(
"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(
"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(
"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(
"{.var legend.margin} must be specified using {.fn margin}",
Expand Down
9 changes: 4 additions & 5 deletions man/print.ggplot.Rd

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

Loading
Loading