Skip to content

Commit 0f7d790

Browse files
teunbrandthomasp85
andauthored
Polishes triggered by revdep failures (#6506)
* don't extract <element_blank>@hjust * ensure `if` switch is scalar * contingency where `merge_element(..., e2 = <S3_element>)` * cast a wider net for function matching * Fix NOTE: no visible binding for global variable 'properties' * stabilise missingness detection for 2D structures * avoid recursion issue when `theme` is missing * avoid renaming argument for S3 method consistency purposes * demote warning to message * stop complaints about 0-length labels, which is commonly used in label supression * allow merging <S3> + <S3> * fix #6521 * fix #6513 * avoid rare error when using GeomSf based extensions * `label.size` should be soft-deprecated first * put `convert` into `local()` too * restore accent colour for `geom_contour()` * new revdepcheck * don't prepend `""` as class * mark the binning change as a breaking change * fix #6531 * fix #6529 * no longer soft-deprecated * attempt to tone down spurious warnings * fallback for translating `geom_errorbarh(height)` * alias to prevent breaking linking docs * avoid `rel(0)` margins, fix #6536 * last attempt at removing rownames * use logical NA for casting purposes --------- Co-authored-by: Thomas Lin Pedersen <thomasp85@gmail.com>
1 parent d5ff3a6 commit 0f7d790

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1019
-10541
lines changed

NEWS.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
rather than in the layer method of `update_ggplot()`
2626
(previously `ggplot_add.Layer()`). This may affect code that accessed the
2727
`plot$labels` property (@teunbrand, #5894).
28+
* In binning stats, the default `boundary` is now chosen to better adhere to
29+
the `nbin` argument. This may affect plots that use default binning
30+
(@teunbrand, #5882, #5036)
2831

2932
### Lifecycle changes
3033

@@ -218,8 +221,6 @@
218221
aesthetics (@teunbrand, #2800, #3142, #5740, #3722).
219222
* All binning stats now use the `boundary`/`center` parametrisation rather
220223
than `origin`, following in `stat_bin()`'s footsteps (@teunbrand).
221-
* In `stat_bin()`, the default `boundary` is now chosen to better adhere to
222-
the `nbin` argument (@teunbrand, #5882, #5036)
223224
* Reintroduced `drop` argument to `stat_bin()` (@teunbrand, #3449)
224225
* `stat_bin()` now accepts functions for argument `breaks` (@aijordan, #4561)
225226
* `after_stat()` and `after_scale()` throw warnings when the computed aesthetics

R/aes.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ is_position_aes <- function(vars) {
261261
#'
262262
#' @section Life cycle:
263263
#'
264-
#' All these functions are soft-deprecated. Please use tidy evaluation idioms
264+
#' All these functions are deprecated. Please use tidy evaluation idioms
265265
#' instead. Regarding `aes_string()`, you can replace it with `.data` pronoun.
266266
#' For example, the following code can achieve the same mapping as
267267
#' `aes_string(x_var, y_var)`.

R/compat-plyr.R

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,17 @@ unrowname <- function(x) {
1919
} else if (is.matrix(x)) {
2020
dimnames(x)[1] <- list(NULL)
2121
} else {
22-
cli::cli_abort("Can only remove rownames from {.cls data.frame} and {.cls matrix} objects.")
22+
try_fetch(
23+
{
24+
rownames(x) <- NULL
25+
},
26+
error = function(cnd) {
27+
cli::cli_abort(
28+
"Can only remove rownames from {.cls data.frame} and {.cls matrix} objects.",
29+
parent = cnd
30+
)
31+
}
32+
)
2333
}
2434
x
2535
}

R/coord-radial.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ coord_radial <- function(theta = "x",
136136
}
137137
if (lifecycle::is_present(direction)) {
138138
deprecate_warn0(
139-
"3.5.2", "coord_radial(direction)", "coord_radial(reverse)"
139+
"4.0.0", "coord_radial(direction)", "coord_radial(reverse)"
140140
)
141141
reverse <- switch(reverse, "r" = "thetar", "theta")
142142
}

R/coord-transform.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ coord_transform <- function(x = "identity", y = "identity", xlim = NULL, ylim =
113113
#' @export
114114
coord_trans <- function(...) {
115115
deprecate_soft0(
116-
"3.5.2",
116+
"4.0.0",
117117
"coord_trans()",
118118
"coord_transform()"
119119
)

R/facet-wrap.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ wrap_layout <- function(id, dims, dir) {
569569
# Should only occur when `as.table` was not incorporated into `dir`
570570
dir <- switch(dir, h = "lt", v = "tl")
571571
deprecate_soft0(
572-
"3.5.2",
572+
"4.0.0",
573573
what = I("Internal use of `dir = \"h\"` and `dir = \"v\"` in `facet_wrap()`"),
574574
details = I(c(
575575
"The `dir` argument should incorporate the `as.table` argument.",

R/geom-boxplot.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ GeomBoxplot <- ggproto("GeomBoxplot", Geom,
241241
setup_params = function(data, params) {
242242
if ("fatten" %in% names(params)) {
243243
deprecate_soft0(
244-
"3.6.0", "geom_boxplot(fatten)",
244+
"4.0.0", "geom_boxplot(fatten)",
245245
"geom_boxplot(median.linewidth)"
246246
)
247247
} else {

R/geom-contour.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55
#' @include geom-path.R
66
GeomContour <- ggproto(
77
"GeomContour", GeomPath,
8-
default_aes = aes(weight = 1, !!!GeomPath$default_aes)
8+
default_aes = aes(
9+
weight = 1,
10+
colour = from_theme(colour %||% accent),
11+
linewidth = from_theme(linewidth),
12+
linetype = from_theme(linetype),
13+
alpha = NA
14+
)
915
)
1016

1117
#' @rdname Geom

R/geom-crossbar.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ GeomCrossbar <- ggproto("GeomCrossbar", Geom,
6262
setup_params = function(data, params) {
6363
if (lifecycle::is_present(params$fatten %||% deprecated())) {
6464
deprecate_soft0(
65-
"3.6.0", "geom_crossbar(fatten)",
65+
"4.0.0", "geom_crossbar(fatten)",
6666
"geom_crossbar(middle.linewidth)"
6767
)
6868
} else {

R/geom-density.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ GeomDensity <- ggproto(
7676
#' geom_density(position = "fill")
7777
#' }
7878
geom_density <- make_constructor(
79-
GeomDensity, stat = "density",
79+
GeomDensity, stat = "density", outline.type = "upper",
8080
checks = exprs(
8181
outline.type <- arg_match0(outline.type, c("both", "upper", "lower", "full"))
8282
)

R/geom-errorbar.R

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,19 @@ GeomErrorbar <- ggproto(
1818
required_aes = c("x|y", "ymin|xmin", "ymax|xmax"),
1919

2020
setup_params = function(data, params) {
21-
GeomLinerange$setup_params(data, params)
21+
params <- GeomLinerange$setup_params(data, params)
22+
if (
23+
isTRUE(params$flipped_aes) &&
24+
isTRUE("height" %in% names(params)) &&
25+
!isTRUE("width" %in% names(params))
26+
) {
27+
params <- rename(params, c(height = "width"))
28+
cli::cli_inform("{.arg height} was translated to {.arg width}.")
29+
}
30+
params
2231
},
2332

24-
extra_params = c("na.rm", "orientation"),
33+
extra_params = c("na.rm", "orientation", "height"),
2534

2635
setup_data = function(self, data, params) {
2736
data$flipped_aes <- params$flipped_aes
@@ -69,7 +78,7 @@ GeomErrorbarh <- ggproto(
6978
"GeomErrorbarh", GeomErrorbar,
7079
setup_params = function(data, params) {
7180
deprecate_soft0(
72-
"3.5.2", "geom_errobarh()", "geom_errorbar(orientation = \"y\")",
81+
"4.0.0", "geom_errobarh()", "geom_errorbar(orientation = \"y\")",
7382
id = "no-more-errorbarh"
7483
)
7584
GeomLinerange$setup_params(data, params)
@@ -87,7 +96,7 @@ geom_errorbar <- make_constructor(GeomErrorbar, orientation = NA)
8796
#' `geom_errorbar(orientation = "y")` instead.
8897
geom_errorbarh <- function(..., orientation = "y") {
8998
deprecate_soft0(
90-
"3.5.2", "geom_errobarh()", "geom_errorbar(orientation = \"y\")",
99+
"4.0.0", "geom_errobarh()", "geom_errorbar(orientation = \"y\")",
91100
id = "no-more-errorbarh"
92101
)
93102
geom_errorbar(..., orientation = orientation)

R/geom-label.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ geom_label <- function(mapping = NULL, data = NULL,
2828

2929
extra_args <- list2(...)
3030
if (lifecycle::is_present(label.size)) {
31-
deprecate_warn0("3.5.0", "geom_label(label.size)", "geom_label(linewidth)")
31+
deprecate_soft0("3.5.0", "geom_label(label.size)", "geom_label(linewidth)")
3232
extra_args$linewidth <- extra_args$linewidth %||% label.size
3333
}
3434

R/geom-path.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ GeomPath <- ggproto("GeomPath", Geom,
66
required_aes = c("x", "y"),
77

88
default_aes = aes(
9-
colour = from_theme(ink),
9+
colour = from_theme(colour %||% ink),
1010
linewidth = from_theme(linewidth),
1111
linetype = from_theme(linetype),
1212
alpha = NA

R/geom-pointrange.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ GeomPointrange <- ggproto("GeomPointrange", Geom,
1616

1717
setup_params = function(data, params) {
1818
if (lifecycle::is_present(params$fatten %||% deprecated())) {
19-
deprecate_soft0("3.6.0", "geom_pointrange(fatten)", I("the `size` aesthetic"))
19+
deprecate_soft0("4.0.0", "geom_pointrange(fatten)", I("the `size` aesthetic"))
2020
} else {
2121
# For backward compatibility reasons
2222
params$fatten <- 4

R/geom-violin.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ geom_violin <- function(mapping = NULL, data = NULL,
111111
extra <- list()
112112
if (lifecycle::is_present(draw_quantiles)) {
113113
deprecate_soft0(
114-
"3.6.0",
114+
"4.0.0",
115115
what = "geom_violin(draw_quantiles)",
116116
with = "geom_violin(quantiles.linetype)"
117117
)

R/guide-colorsteps.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ GuideColoursteps <- ggproto(
194194
params$title <- scale$make_title(params$title, scale$name, title)
195195

196196
limits <- c(params$decor$min[1], params$decor$max[nrow(params$decor)])
197-
if (params$reverse) {
197+
if (isTRUE(params$reverse)) {
198198
limits <- rev(limits)
199199
}
200200
params$key$.value <- rescale(params$key$.value, from = limits)

R/guides-.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ Guides <- ggproto(
274274
#
275275
# The resulting guide is then drawn in ggplot_gtable
276276

277-
build = function(self, scales, layers, labels, layer_data, theme = theme()) {
277+
build = function(self, scales, layers, labels, layer_data, theme = NULL) {
278278

279279
# Empty guides list
280280
custom <- self$get_custom()
@@ -300,6 +300,7 @@ Guides <- ggproto(
300300
}
301301

302302
# Merge and process layers
303+
theme <- theme %||% theme()
303304
guides$merge()
304305
guides$process_layers(layers, layer_data, theme)
305306
if (length(guides$guides) == 0) {

R/labels.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ setup_plot_labels <- function(plot, layers, data) {
7878
# `geom_function()`. We can display these labels anyway, so we include them.
7979
plot_labels <- plot@labels
8080
known_labels <- c(names(labels), fn_fmls_names(labs), "x", "y")
81-
extra_labels <- setdiff(names(plot_labels), known_labels)
81+
extra_labels <- names(plot_labels)[lengths(plot_labels) > 0]
82+
extra_labels <- setdiff(extra_labels, known_labels)
8283

8384
if (length(extra_labels) > 0) {
8485

@@ -92,7 +93,7 @@ setup_plot_labels <- function(plot, layers, data) {
9293
extra_labels <- paste0("{.field ", extra_labels, "} : ", warn_labels)
9394
names(extra_labels) <- rep("*", length(extra_labels))
9495

95-
cli::cli_warn(c(
96+
cli::cli_inform(c(
9697
"Ignoring unknown labels:",
9798
extra_labels
9899
))

R/layer-sf.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,12 @@ LayerSf <- ggproto("LayerSf", Layer,
7878
geom_column <- function(data) {
7979
w <- which(vapply(data, inherits, TRUE, what = "sfc"))
8080
if (length(w) == 0) {
81-
"geometry" # avoids breaks when objects without geometry list-column are examined
81+
if (!is.character(data[["geometry"]])) {
82+
"geometry" # avoids breaks when objects without geometry list-column are examined
83+
} else {
84+
# Avoids a rare case where computed_geom_params$legend is present but there is no actual geometry column
85+
""
86+
}
8287
} else {
8388
# this may not be best in case more than one geometry list-column is present:
8489
if (length(w) > 1)

R/layer.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ set_draw_key <- function(geom, draw_key = NULL) {
941941
}
942942
draw_key <- match.fun(draw_key)
943943

944-
ggproto("", geom, draw_key = draw_key)
944+
ggproto(NULL, geom, draw_key = draw_key)
945945
}
946946

947947
cleanup_mismatched_data <- function(data, n, fun) {

R/plot-build.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,13 @@ S7::method(gtable_ggplot, class_ggplot_built) <- function(data) {
317317
# TODO: the S3 generic should be phased out once S7 is adopted more widely
318318
#' @rdname gtable_ggplot
319319
#' @export
320-
ggplot_gtable <- function(plot) {
320+
ggplot_gtable <- function(data) {
321321
UseMethod("ggplot_gtable")
322322
}
323323

324324
#' @export
325-
ggplot_gtable.default <- function(plot) {
326-
gtable_ggplot(plot)
325+
ggplot_gtable.default <- function(data) {
326+
gtable_ggplot(data)
327327
}
328328

329329
#' Generate a ggplot2 plot grob.

R/plot-construction.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#' @param e1 An object of class [ggplot()] or a [theme()].
2525
#' @param e2 A plot component, as described below.
2626
#' @seealso [theme()]
27+
#' @aliases +.gg
2728
#' @rdname gg-add
2829
#' @export
2930
#' @examples
@@ -135,6 +136,10 @@ S7::method(update_ggplot, list(S7::class_any, class_ggplot)) <-
135136
function(object, plot, object_name, ...) {
136137

137138
if (!S7::S7_inherits(object) && inherits(object, "theme")) {
139+
# This is a contingency for patchwork/#438
140+
if (length(object) == 0) {
141+
return(plot)
142+
}
138143
# For backward compatibility, we try to cast old S3 themes (lists with
139144
# the class 'theme') to proper themes. People *should* use `theme()`,
140145
# so we should be pushy here.

R/plot.R

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,14 @@ S7::method(plot, class_ggplot) <- `print.ggplot2::ggplot`
276276
`[[<-.ggplot2::gg` <- `$<-.ggplot2::gg`
277277

278278
#' @importFrom S7 convert
279-
S7::method(convert, list(from = class_ggplot, to = S7::class_list)) <-
280-
function(from, to) {
281-
S7::props(from)
282-
}
283-
284279
# S7 currently attaches the S3 method to the calling environment which gives `ggplot2:::as.list`
285280
# Wrap in `local()` to provide a temp environment which throws away the attachment
286281
local({
287-
S7::method(as.list, class_ggplot) <- function(x, ...) convert(x, S7::class_list)
282+
S7::method(convert, list(from = class_ggplot, to = S7::class_list)) <-
283+
function(from, to) {
284+
S7::props(from)
285+
}
286+
287+
S7::method(as.list, class_ggplot) <-
288+
function(x, ...) convert(x, S7::class_list)
288289
})

R/position-dodge.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ PositionDodge <- ggproto("PositionDodge", Position,
152152
data$order <- xtfrm( # xtfrm makes anything 'sortable'
153153
data$order %||% ave(data$group, data$x, data$PANEL, FUN = match_sorted)
154154
)
155-
if (params$reverse) {
155+
if (isTRUE(params$reverse)) {
156156
data$order <- -data$order
157157
}
158158
if (is.null(params$n)) { # preserve = "total"

R/position-stack.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ PositionStack <- ggproto("PositionStack", Position,
154154
flipped_aes <- has_flipped_aes(data)
155155
data <- flip_data(data, flipped_aes)
156156
var <- self$var %||% stack_var(data)
157-
if (!vec_duplicate_any(data$x)) {
157+
if (!vec_duplicate_any(data$x) && !isTRUE(self$fill)) {
158158
# We skip stacking when all data have different x positions so that
159159
# there is nothing to stack
160160
var <- NULL

R/scale-.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
continuous_scale <- function(aesthetics, scale_name = deprecated(), palette, name = waiver(),
105105
breaks = waiver(), minor_breaks = waiver(), n.breaks = NULL,
106106
labels = waiver(), limits = NULL, rescaler = rescale,
107-
oob = censor, expand = waiver(), na.value = NA_real_,
107+
oob = censor, expand = waiver(), na.value = NA,
108108
transform = "identity", trans = deprecated(),
109109
guide = "legend", position = "left",
110110
call = caller_call(),
@@ -1331,7 +1331,7 @@ ScaleDiscrete <- ggproto("ScaleDiscrete", Scale,
13311331
vec_slice(pal, match(as.character(x), limits, nomatch = vec_size(pal)))
13321332

13331333
if (!is.na(na_value)) {
1334-
vec_slice(pal_match, is.na(x)) <- na_value
1334+
vec_slice(pal_match, vec_detect_missing(x)) <- na_value
13351335
}
13361336
pal_match
13371337
},

R/stat-summary-2d.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ StatSummary2d <- ggproto(
1515
params$drop <- !identical(params$drop, "none")
1616
}
1717

18-
params <- fix_bin_params(params, fun = snake_class(self), version = "3.5.2")
18+
params <- fix_bin_params(params, fun = snake_class(self), version = "4.0.0")
1919
vars <- c("origin", "binwidth", "breaks", "center", "boundary")
2020
params[vars] <- lapply(params[vars], dual_param, default = NULL)
2121
params$closed <- dual_param(params$closed, list(x = "right", y = "right"))

R/stat-summary-bin.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ make_summary_fun <- function(fun.data, fun, fun.max, fun.min, fun.args) {
108108
force(fun.min)
109109
force(fun.args)
110110

111+
as_function <- function(x) {
112+
if (is.character(x)) {
113+
x <- match.fun(x)
114+
}
115+
rlang::as_function(x)
116+
}
117+
111118
if (!is.null(fun.data)) {
112119
# Function that takes complete data frame as input
113120
fun.data <- as_function(fun.data)

R/stat-ydensity.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ StatYdensity <- ggproto(
1212

1313
if (!is.null(params$draw_quantiles)) {
1414
deprecate_soft0(
15-
"3.6.0",
15+
"4.0.0",
1616
what = "stat_ydensity(draw_quantiles)",
1717
with = "stat_ydensity(quantiles)"
1818
)

0 commit comments

Comments
 (0)