Skip to content

Clear merge debris (Re: #6416) #6432

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,6 @@ export(is.facet)
export(is.ggplot)
export(is.ggproto)
export(is.theme)
export(is.waiver)
export(is_coord)
export(is_facet)
export(is_geom)
Expand All @@ -490,6 +489,7 @@ export(is_scale)
export(is_stat)
export(is_theme)
export(is_theme_element)
export(is_waiver)
export(label_both)
export(label_bquote)
export(label_context)
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
@yutannihilation's prior work, #3120)
* When discrete breaks have names, they'll be used as labels by default
(@teunbrand, #6147).
* The helper function `is.waiver()` is now exported to help extensions to work
* The helper function `is_waiver()` is now exported to help extensions to work
with `waiver()` objects (@arcresu, #6173).
* Date(time) scales now throw appropriate errors when `date_breaks`,
`date_minor_breaks` or `date_labels` are not strings (@RodDalBen, #5880)
Expand Down
2 changes: 1 addition & 1 deletion R/aes.R
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ aes_ <- function(x, y, ...) {
caller_env <- parent.frame()

as_quosure_aes <- function(x) {
if (is.formula(x) && length(x) == 2) {
if (is_formula(x) && length(x) == 2) {
as_quosure(x)
} else if (is.null(x) || is.call(x) || is.name(x) || is.atomic(x)) {
new_aesthetic(x, caller_env)
Expand Down
20 changes: 10 additions & 10 deletions R/axis-secondary.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,19 @@ dup_axis <- function(transform = identity, name = derive(), breaks = derive(),
sec_axis(transform, trans = trans, name, breaks, labels, guide)
}

is.sec_axis <- function(x) {
is_sec_axis <- function(x) {
inherits(x, "AxisSecondary")
}

set_sec_axis <- function(sec.axis, scale) {
if (!is.waiver(sec.axis)) {
if (!is_waiver(sec.axis)) {
if (scale$is_discrete()) {
if (!identical(.subset2(sec.axis, "trans"), identity)) {
cli::cli_abort("Discrete secondary axes must have the {.fn identity} transformation.")
}
}
if (is.formula(sec.axis)) sec.axis <- sec_axis(sec.axis)
if (!is.sec_axis(sec.axis)) {
if (is_formula(sec.axis)) sec.axis <- sec_axis(sec.axis)
if (!is_sec_axis(sec.axis)) {
cli::cli_abort("Secondary axes must be specified using {.fn sec_axis}.")
}
scale$secondary.axis <- sec.axis
Expand All @@ -150,7 +150,7 @@ set_sec_axis <- function(sec.axis, scale) {
derive <- function() {
structure(list(), class = "derived")
}
is.derived <- function(x) {
is_derived <- function(x) {
inherits(x, "derived")
}
#' @rdname ggplot2-ggproto
Expand Down Expand Up @@ -182,9 +182,9 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
if (!is.function(transform)) {
cli::cli_abort("Transformation for secondary axes must be a function.")
}
if (is.derived(self$name) && !is.waiver(scale$name)) self$name <- scale$name
if (is.derived(self$breaks)) self$breaks <- scale$breaks
if (is.waiver(self$breaks)) {
if (is_derived(self$name) && !is_waiver(scale$name)) self$name <- scale$name
if (is_derived(self$breaks)) self$breaks <- scale$breaks
if (is_waiver(self$breaks)) {
if (scale$is_discrete()) {
self$breaks <- setNames(nm = scale$get_breaks())
} else {
Expand All @@ -197,8 +197,8 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
}
}
}
if (is.derived(self$labels)) self$labels <- scale$labels
if (is.derived(self$guide)) self$guide <- scale$guide
if (is_derived(self$labels)) self$labels <- scale$labels
if (is_derived(self$guide)) self$guide <- scale$guide
},

transform_range = function(self, range) {
Expand Down
2 changes: 1 addition & 1 deletion R/coord-radial.R
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ deg2rad <- function(deg) deg * pi / 180
# Function to rotate a radius axis through viewport
rotate_r_axis <- function(axis, angle, bbox, position = "left") {

if (inherits(axis, "zeroGrob")) {
if (is_zero(axis)) {
return(axis)
}

Expand Down
14 changes: 7 additions & 7 deletions R/coord-sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
x_breaks <- graticule$degree[graticule$type == "E"]
if (is.null(scale_x$labels)) {
x_labels <- rep(NA, length(x_breaks))
} else if (is.waiver(scale_x$labels)) {
} else if (is_waiver(scale_x$labels)) {
x_labels <- graticule$degree_label[graticule$type == "E"]
needs_autoparsing[graticule$type == "E"] <- TRUE
} else {
Expand All @@ -141,7 +141,7 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
y_breaks <- graticule$degree[graticule$type == "N"]
if (is.null(scale_y$labels)) {
y_labels <- rep(NA, length(y_breaks))
} else if (is.waiver(scale_y$labels)) {
} else if (is_waiver(scale_y$labels)) {
y_labels <- graticule$degree_label[graticule$type == "N"]
needs_autoparsing[graticule$type == "N"] <- TRUE
} else {
Expand Down Expand Up @@ -334,7 +334,7 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,

# we don't draw the graticules if the major panel grid is
# turned off
if (inherits(el, "element_blank")) {
if (is_theme_element(el, "blank")) {
grobs <- list(element_render(theme, "panel.background"))
} else {
line_gp <- gg_par(
Expand Down Expand Up @@ -553,7 +553,7 @@ coord_sf <- function(xlim = NULL, ylim = NULL, expand = TRUE,
ndiscr = 100, default = FALSE, clip = "on",
reverse = "none") {

if (is.waiver(label_graticule) && is.waiver(label_axes)) {
if (is_waiver(label_graticule) && is_waiver(label_axes)) {
# if both `label_graticule` and `label_axes` are set to waive then we
# use the default of labels on the left and at the bottom
label_graticule <- ""
Expand Down Expand Up @@ -640,13 +640,13 @@ sf_breaks <- function(scale_x, scale_y, bbox, crs) {
bbox[is.na(bbox)] <- c(-180, -90, 180, 90)[is.na(bbox)]
}

if (!(is.waiver(scale_x$breaks) && is.null(scale_x$n.breaks))) {
if (!(is_waiver(scale_x$breaks) && is.null(scale_x$n.breaks))) {
x_breaks <- scale_x$get_breaks(limits = bbox[c(1, 3)])
finite <- is.finite(x_breaks)
x_breaks <- if (any(finite)) x_breaks[finite] else NULL
}

if (!(is.waiver(scale_y$breaks) && is.null(scale_y$n.breaks))) {
if (!(is_waiver(scale_y$breaks) && is.null(scale_y$n.breaks))) {
y_breaks <- scale_y$get_breaks(limits = bbox[c(2, 4)])
finite <- is.finite(y_breaks)
y_breaks <- if (any(finite)) y_breaks[finite] else NULL
Expand Down Expand Up @@ -769,7 +769,7 @@ view_scales_from_graticule <- function(graticule, scale, aesthetic,
if (scale$position != position) {
# Try to use secondary axis' guide
guide <- scale$secondary.axis$guide %||% waiver()
if (is.derived(guide)) {
if (is_derived(guide)) {
guide <- scale$guide
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion R/facet-grid-.R
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ ulevels <- function(x, na.last = TRUE) {

table_has_grob <- function(table, pattern) {
grobs <- table$grobs[grep(pattern, table$layout$name)]
!all(vapply(grobs, is.zero, logical(1)))
!all(vapply(grobs, is_zero, logical(1)))
}

seam_table <- function(table, grobs = NULL, side, shift = 1, name, z = 1,
Expand Down
4 changes: 2 additions & 2 deletions R/facet-null.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ FacetNull <- ggproto("FacetNull", Facet,
layout_null()
},
map_data = function(data, layout, params) {
# Need the is.waiver check for special case where no data, but aesthetics
# Need the is_waiver check for special case where no data, but aesthetics
# are mapped to vectors
if (is.waiver(data))
if (is_waiver(data))
return(data_frame0(PANEL = factor()))

if (empty(data))
Expand Down
10 changes: 5 additions & 5 deletions R/facet-wrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ FacetWrap <- ggproto("FacetWrap", Facet,
if (length(empty_bottom) > 0) {
x_axes <- original$x$bottom[matched[empty_bottom]]
clash["bottom"] <- strip == "bottom" && !inside && !free$x &&
!all(vapply(x_axes, is.zero, logical(1)))
!all(vapply(x_axes, is_zero, logical(1)))
if (!clash["bottom"]) {
bottom[empty_bottom] <- x_axes
}
Expand All @@ -336,7 +336,7 @@ FacetWrap <- ggproto("FacetWrap", Facet,
if (length(empty_top) > 0) {
x_axes <- original$x$top[matched[empty_top]]
clash["top"] <- strip == "top" && !inside && !free$x &&
!all(vapply(x_axes, is.zero, logical(1)))
!all(vapply(x_axes, is_zero, logical(1)))
if (!clash["top"]) {
top[empty_top] <- x_axes
}
Expand All @@ -345,7 +345,7 @@ FacetWrap <- ggproto("FacetWrap", Facet,
if (length(empty_right) > 0) {
y_axes <- original$y$right[matched[empty_right]]
clash["right"] <- strip == "right" && !inside && !free$y &&
!all(vapply(y_axes, is.zero, logical(1)))
!all(vapply(y_axes, is_zero, logical(1)))
if (!clash["right"]) {
right[empty_right] <- y_axes
}
Expand All @@ -354,7 +354,7 @@ FacetWrap <- ggproto("FacetWrap", Facet,
if (length(empty_left) > 0) {
y_axes <- original$y$left[matched[empty_left]]
clash["left"] <- strip == "left" && !inside && !free$y &&
!all(vapply(y_axes, is.zero, logical(1)))
!all(vapply(y_axes, is_zero, logical(1)))
if (!clash["left"]) {
left[empty_left] <- y_axes
}
Expand Down Expand Up @@ -410,7 +410,7 @@ FacetWrap <- ggproto("FacetWrap", Facet,

if (!inside) {
axes <- grepl(paste0("axis-", pos), table$layout$name)
has_axes <- !vapply(table$grobs[axes], is.zero, logical(1))
has_axes <- !vapply(table$grobs[axes], is_zero, logical(1))
has_axes <- split(has_axes, table$layout[[pos]][axes])
has_axes <- vapply(has_axes, sum, numeric(1)) > 0
padding <- rep(padding, length(has_axes))
Expand Down
2 changes: 1 addition & 1 deletion R/grob-null.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ grobHeight.zeroGrob <- function(x) unit(0, "cm")
#' @method drawDetails zeroGrob
drawDetails.zeroGrob <- function(x, recording) {}

is.zero <- function(x) is.null(x) || inherits(x, "zeroGrob")
is_zero <- function(x) is.null(x) || inherits(x, "zeroGrob")
2 changes: 1 addition & 1 deletion R/grouping.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ add_group <- function(data) {
if (empty(data)) return(data)

if (is.null(data[["group"]])) {
disc <- vapply(data, is.discrete, logical(1))
disc <- vapply(data, is_discrete, logical(1))
disc[names(disc) %in% c("label", "PANEL")] <- FALSE

if (any(disc)) {
Expand Down
2 changes: 1 addition & 1 deletion R/guide-.R
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ Guide <- ggproto(
},

add_title = function(gtable, title, position, just) {
if (is.zero(title)) {
if (is_zero(title)) {
return(gtable)
}

Expand Down
2 changes: 1 addition & 1 deletion R/guide-axis-logticks.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ guide_axis_logticks <- function(
if (is_bare_numeric(mid)) mid <- rel(mid)
if (is_bare_numeric(short)) short <- rel(short)

check_fun <- function(x) (is.rel(x) || is.unit(x)) && length(x) == 1
check_fun <- function(x) (is_rel(x) || is.unit(x)) && length(x) == 1
what <- "a {.cls rel} or {.cls unit} object of length 1"
check_object(long, check_fun, what)
check_object(mid, check_fun, what)
Expand Down
2 changes: 1 addition & 1 deletion R/guide-axis-stack.R
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ GuideAxisStack <- ggproto(
}

# Remove empty grobs
grobs <- grobs[!vapply(grobs, is.zero, logical(1))]
grobs <- grobs[!vapply(grobs, is_zero, logical(1))]
if (length(grobs) == 0) {
return(zeroGrob())
}
Expand Down
10 changes: 5 additions & 5 deletions R/guide-axis-theta.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ GuideAxisTheta <- ggproto(

build_labels = function(key, elements, params) {

if (inherits(elements$text, "element_blank")) {
if (is_theme_element(elements$text, "blank")) {
return(zeroGrob())
}

Expand All @@ -197,7 +197,7 @@ GuideAxisTheta <- ggproto(
}

# Resolve text angle
if (is.waiver(params$angle) || is.null(params$angle)) {
if (is_waiver(params$angle) || is.null(params$angle)) {
angle <- elements$text$angle
} else {
angle <- flip_text_angle(params$angle - rad2deg(key$theta))
Expand Down Expand Up @@ -268,12 +268,12 @@ GuideAxisTheta <- ggproto(
key <- params$key
key <- vec_slice(key, !is.na(key$.label) & nzchar(key$.label))
labels <- validate_labels(key$.label)
if (length(labels) == 0 || inherits(elements$text, "element_blank")) {
if (length(labels) == 0 || is_theme_element(elements$text, "blank")) {
return(list(offset = offset))
}

# Resolve text angle
if (is.waiver(params$angle %||% waiver())) {
if (is_waiver(params$angle %||% waiver())) {
angle <- elements$text$angle
} else {
angle <- flip_text_angle(params$angle - rad2deg(key$theta))
Expand Down Expand Up @@ -365,7 +365,7 @@ GuideAxisTheta <- ggproto(

theta_tickmarks <- function(key, element, length, offset = NULL) {
n_breaks <- nrow(key)
if (n_breaks < 1 || inherits(element, "element_blank")) {
if (n_breaks < 1 || is_theme_element(element, "blank")) {
return(zeroGrob())
}

Expand Down
10 changes: 5 additions & 5 deletions R/guide-axis.R
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,10 @@ GuideAxis <- ggproto(
override_elements = function(params, elements, theme) {
elements$text <-
label_angle_heuristic(elements$text, params$position, params$angle)
if (inherits(elements$ticks, "element_blank")) {
if (is_theme_element(elements$ticks, "blank")) {
elements$major_length <- unit(0, "cm")
}
if (inherits(elements$minor, "element_blank") || isFALSE(params$minor.ticks)) {
if (is_theme_element(elements$minor, "blank") || isFALSE(params$minor.ticks)) {
elements$minor_length <- unit(0, "cm")
}
return(elements)
Expand Down Expand Up @@ -379,7 +379,7 @@ GuideAxis <- ggproto(
# Ticks
major_cm <- convertUnit(elements$major_length, "cm", valueOnly = TRUE)
range <- range(0, major_cm)
if (params$minor.ticks && !inherits(elements$minor, "element_blank")) {
if (params$minor.ticks && !is_theme_element(elements$minor, "blank")) {
minor_cm <- convertUnit(elements$minor_length, "cm", valueOnly = TRUE)
range <- range(range, minor_cm)
}
Expand Down Expand Up @@ -420,7 +420,7 @@ GuideAxis <- ggproto(
# Unlist the 'label' grobs
z <- if (params$position == "left") c(2, 1, 3) else 1:3
z <- rep(z, c(1, length(grobs$labels), 1))
has_labels <- !is.zero(grobs$labels[[1]])
has_labels <- !is_zero(grobs$labels[[1]])
grobs <- c(list(grobs$ticks), grobs$labels, list(grobs$title))

# Initialise empty gtable
Expand Down Expand Up @@ -590,7 +590,7 @@ axis_label_priority_between <- function(x, y) {
#' overridden from the user- or theme-supplied element.
#' @noRd
label_angle_heuristic <- function(element, position, angle) {
if (!inherits(element, "element_text")
if (!is_theme_element(element, "text")
|| is.null(position)
|| is.null(angle %|W|% NULL)) {
return(element)
Expand Down
2 changes: 1 addition & 1 deletion R/guide-bins.R
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ GuideBins <- ggproto(

parse_binned_breaks <- function(scale, breaks = scale$get_breaks()) {

if (is.waiver(scale$labels) || is.function(scale$labels)) {
if (is_waiver(scale$labels) || is.function(scale$labels)) {
breaks <- breaks[!is.na(breaks)]
}
if (length(breaks) == 0) {
Expand Down
2 changes: 1 addition & 1 deletion R/guide-custom.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ GuideCustom <- ggproto(
# Render title
params <- replace_null(params, position = position, direction = direction)
elems <- GuideLegend$setup_elements(params, self$elements, theme)
if (!is.waiver(params$title) && !is.null(params$title)) {
if (!is_waiver(params$title) && !is.null(params$title)) {
title <- self$build_title(params$title, elems, params)
} else {
title <- zeroGrob()
Expand Down
Loading