Skip to content

Handle null aesthetics when labelling #2617

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 1 commit into from
May 18, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion R/plot-construction.r
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ ggplot_add.uneval <- function(object, plot, object_name) {
# defaults() doesn't copy class, so copy it.
class(plot$mapping) <- class(object)

labels <- lapply(object, rlang::quo_name)
labels <- lapply(object, function(x) if (is.null(x)) x else rlang::quo_name(x))
names(labels) <- names(object)
update_labels(plot, labels)
}
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-aes.r
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ test_that("quosures are squashed when creating default label for a mapping", {
expect_identical(p$labels$x, "identity(cyl)")
})

test_that("labelling doesn't cause error if aesthetic is nul", {
p <- ggplot(mtcars) + aes(x = NULL)
expect_null(p$labels$x)
})


# Visual tests ------------------------------------------------------------

Expand Down