Skip to content

Use .ignore_empty="all" for enquos() #2936

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

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Imports:
mgcv,
plyr (>= 1.7.1),
reshape2,
rlang (>= 0.2.1),
rlang (>= 0.2.99.0),
scales (>= 0.5.0),
stats,
tibble,
Expand Down Expand Up @@ -243,3 +243,5 @@ VignetteBuilder: knitr
RoxygenNote: 6.1.0
Roxygen: list(markdown = TRUE)
Encoding: UTF-8
Remotes:
r-lib/rlang
6 changes: 2 additions & 4 deletions R/aes.r
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,8 @@ NULL
#' cut3 <- function(x) cut_number(x, 3)
#' scatter_by(mtcars, cut3(disp), drat)
aes <- function(x, y, ...) {
exprs <- rlang::enquos(x = x, y = y, ...)
is_missing <- vapply(exprs, rlang::quo_is_missing, logical(1))

aes <- new_aes(exprs[!is_missing], env = parent.frame())
exprs <- rlang::enquos(x = x, y = y, ..., .ignore_empty = "all")
aes <- new_aes(exprs, env = parent.frame())
rename_aes(aes)
}

Expand Down
12 changes: 3 additions & 9 deletions R/quick-plot.r
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,13 @@ qplot <- function(x, y, ..., data, facets = NULL, margins = FALSE,
if (!missing(position)) warning("`position` is deprecated", call. = FALSE)
if (!is.character(geom)) stop("`geom` must be a character vector", call. = FALSE)

exprs <- rlang::enquos(x = x, y = y, ...)
is_missing <- vapply(exprs, rlang::quo_is_missing, logical(1))
exprs <- rlang::enquos(x = x, y = y, ..., .ignore_empty = "all")
# treat arguments as regular parameters if they are wrapped into I() or
# if they don't have a name that is in the list of all aesthetics
is_constant <- (!names(exprs) %in% ggplot_global$all_aesthetics) |
vapply(exprs, rlang::quo_is_call, logical(1), name = "I")

mapping <- new_aes(exprs[!is_missing & !is_constant], env = parent.frame())
mapping <- new_aes(exprs[!is_constant], env = parent.frame())

consts <- exprs[is_constant]

Expand All @@ -90,12 +89,7 @@ qplot <- function(x, y, ..., data, facets = NULL, margins = FALSE,
xlab <- rlang::quo_name(exprs$x)
}
if (is.null(ylab)) {
# Work around quo_name() bug: https://github.com/r-lib/rlang/issues/430
if (rlang::quo_is_null(exprs$y)) {
ylab <- "NULL"
} else {
ylab <- rlang::quo_name(exprs$y)
}
ylab <- rlang::quo_name(exprs$y)
}

if (missing(data)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-aes.r
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ test_that("assignment methods pull unwrap constants from quosures", {
})

test_that("quosures are squashed when creating default label for a mapping", {
p <- ggplot(mtcars) + aes(!!quo(identity(!!quo(cyl))))
p <- ggplot(mtcars) + aes(!!rlang::quo(identity(!!rlang::quo(cyl))))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why this matters, but if I use .ignore_empty = "all", this fails...

expect_identical(p$labels$x, "identity(cyl)")
})

Expand Down