Skip to content

Commit eb8bf83

Browse files
authored
Export is.waive() for extensions to use (#6173)
* Export is.waive() * Add NEWS bullet about is.waive * Rename is.waive to is.waiver
1 parent add05b3 commit eb8bf83

18 files changed

+58
-44
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ export(is.scale)
475475
export(is.stat)
476476
export(is.theme)
477477
export(is.theme_element)
478+
export(is.waiver)
478479
export(label_both)
479480
export(label_bquote)
480481
export(label_context)

NEWS.md

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

3+
* The helper function `is.waiver()` is now exported to help extensions to work
4+
with `waiver()` objects (@arcresu, #6173).
35
* Date(time) scales now throw appropriate errors when `date_breaks`,
46
`date_minor_breaks` or `date_labels` are not strings (@RodDalBen, #5880)
57
* `geom_errorbarh()` is deprecated in favour of

R/axis-secondary.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ is.sec_axis <- function(x) {
129129
}
130130

131131
set_sec_axis <- function(sec.axis, scale) {
132-
if (!is.waive(sec.axis)) {
132+
if (!is.waiver(sec.axis)) {
133133
if (scale$is_discrete()) {
134134
if (!identical(.subset2(sec.axis, "trans"), identity)) {
135135
cli::cli_abort("Discrete secondary axes must have the {.fn identity} transformation.")
@@ -182,9 +182,9 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
182182
if (!is.function(transform)) {
183183
cli::cli_abort("Transformation for secondary axes must be a function.")
184184
}
185-
if (is.derived(self$name) && !is.waive(scale$name)) self$name <- scale$name
185+
if (is.derived(self$name) && !is.waiver(scale$name)) self$name <- scale$name
186186
if (is.derived(self$breaks)) self$breaks <- scale$breaks
187-
if (is.waive(self$breaks)) {
187+
if (is.waiver(self$breaks)) {
188188
if (scale$is_discrete()) {
189189
self$breaks <- scale$get_breaks()
190190
} else {

R/coord-sf.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
108108
x_breaks <- graticule$degree[graticule$type == "E"]
109109
if (is.null(scale_x$labels)) {
110110
x_labels <- rep(NA, length(x_breaks))
111-
} else if (is.waive(scale_x$labels)) {
111+
} else if (is.waiver(scale_x$labels)) {
112112
x_labels <- graticule$degree_label[graticule$type == "E"]
113113
needs_autoparsing[graticule$type == "E"] <- TRUE
114114
} else {
@@ -133,7 +133,7 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
133133
y_breaks <- graticule$degree[graticule$type == "N"]
134134
if (is.null(scale_y$labels)) {
135135
y_labels <- rep(NA, length(y_breaks))
136-
} else if (is.waive(scale_y$labels)) {
136+
} else if (is.waiver(scale_y$labels)) {
137137
y_labels <- graticule$degree_label[graticule$type == "N"]
138138
needs_autoparsing[graticule$type == "N"] <- TRUE
139139
} else {
@@ -534,7 +534,7 @@ coord_sf <- function(xlim = NULL, ylim = NULL, expand = TRUE,
534534
label_axes = waiver(), lims_method = "cross",
535535
ndiscr = 100, default = FALSE, clip = "on") {
536536

537-
if (is.waive(label_graticule) && is.waive(label_axes)) {
537+
if (is.waiver(label_graticule) && is.waiver(label_axes)) {
538538
# if both `label_graticule` and `label_axes` are set to waive then we
539539
# use the default of labels on the left and at the bottom
540540
label_graticule <- ""
@@ -620,13 +620,13 @@ sf_breaks <- function(scale_x, scale_y, bbox, crs) {
620620
bbox[is.na(bbox)] <- c(-180, -90, 180, 90)[is.na(bbox)]
621621
}
622622

623-
if (!(is.waive(scale_x$breaks) && is.null(scale_x$n.breaks))) {
623+
if (!(is.waiver(scale_x$breaks) && is.null(scale_x$n.breaks))) {
624624
x_breaks <- scale_x$get_breaks(limits = bbox[c(1, 3)])
625625
finite <- is.finite(x_breaks)
626626
x_breaks <- if (any(finite)) x_breaks[finite] else NULL
627627
}
628628

629-
if (!(is.waive(scale_y$breaks) && is.null(scale_y$n.breaks))) {
629+
if (!(is.waiver(scale_y$breaks) && is.null(scale_y$n.breaks))) {
630630
y_breaks <- scale_y$get_breaks(limits = bbox[c(2, 4)])
631631
finite <- is.finite(y_breaks)
632632
y_breaks <- if (any(finite)) y_breaks[finite] else NULL

R/facet-null.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ FacetNull <- ggproto("FacetNull", Facet,
2727
layout_null()
2828
},
2929
map_data = function(data, layout, params) {
30-
# Need the is.waive check for special case where no data, but aesthetics
30+
# Need the is.waiver check for special case where no data, but aesthetics
3131
# are mapped to vectors
32-
if (is.waive(data))
32+
if (is.waiver(data))
3333
return(data_frame0(PANEL = factor()))
3434

3535
if (empty(data))

R/guide-axis-theta.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ GuideAxisTheta <- ggproto(
200200
}
201201

202202
# Resolve text angle
203-
if (is.waive(params$angle) || is.null(params$angle)) {
203+
if (is.waiver(params$angle) || is.null(params$angle)) {
204204
angle <- elements$text$angle
205205
} else {
206206
angle <- flip_text_angle(params$angle - rad2deg(key$theta))
@@ -276,7 +276,7 @@ GuideAxisTheta <- ggproto(
276276
}
277277

278278
# Resolve text angle
279-
if (is.waive(params$angle %||% waiver())) {
279+
if (is.waiver(params$angle %||% waiver())) {
280280
angle <- elements$text$angle
281281
} else {
282282
angle <- flip_text_angle(params$angle - rad2deg(key$theta))

R/guide-custom.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ GuideCustom <- ggproto(
9696
# Render title
9797
params <- replace_null(params, position = position, direction = direction)
9898
elems <- GuideLegend$setup_elements(params, self$elements, theme)
99-
if (!is.waive(params$title) && !is.null(params$title)) {
99+
if (!is.waiver(params$title) && !is.null(params$title)) {
100100
title <- self$build_title(params$title, elems, params)
101101
} else {
102102
title <- zeroGrob()

R/labels.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ labs <- function(..., title = waiver(), subtitle = waiver(), caption = waiver(),
152152
tag = tag, alt = allow_lambda(alt), alt_insight = alt_insight,
153153
.ignore_empty = "all")
154154

155-
is_waive <- vapply(args, is.waive, logical(1))
155+
is_waive <- vapply(args, is.waiver, logical(1))
156156
args <- args[!is_waive]
157157
# remove duplicated arguments
158158
args <- args[!duplicated(names(args))]

R/layer.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ Layer <- ggproto("Layer", NULL,
253253
},
254254

255255
layer_data = function(self, plot_data) {
256-
if (is.waive(self$data)) {
256+
if (is.waiver(self$data)) {
257257
data <- plot_data
258258
} else if (is.function(self$data)) {
259259
data <- self$data(plot_data)
@@ -263,7 +263,7 @@ Layer <- ggproto("Layer", NULL,
263263
} else {
264264
data <- self$data
265265
}
266-
if (is.null(data) || is.waive(data)) data else unrowname(data)
266+
if (is.null(data) || is.waiver(data)) data else unrowname(data)
267267
},
268268

269269
# hook to allow a layer access to the final layer data

R/layout.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ Layout <- ggproto("Layout", NULL,
283283
} else {
284284
switch(label, x = ".bottom", y = ".right")
285285
}
286-
if (is.null(labels[[label]][[i]]) || is.waive(labels[[label]][[i]]))
286+
if (is.null(labels[[label]][[i]]) || is.waiver(labels[[label]][[i]]))
287287
return(zeroGrob())
288288

289289
element_render(

0 commit comments

Comments
 (0)