Skip to content

Commit 569280d

Browse files
committed
Handle null aesthetics when labelling
Fixes #2598
1 parent bcc3ae5 commit 569280d

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

R/plot-construction.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ ggplot_add.uneval <- function(object, plot, object_name) {
117117
# defaults() doesn't copy class, so copy it.
118118
class(plot$mapping) <- class(object)
119119

120-
labels <- lapply(object, rlang::quo_name)
120+
labels <- lapply(object, function(x) if (is.null(x)) x else rlang::quo_name(x))
121121
names(labels) <- names(object)
122122
update_labels(plot, labels)
123123
}

tests/testthat/test-aes.r

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ test_that("quosures are squashed when creating default label for a mapping", {
9393
expect_identical(p$labels$x, "identity(cyl)")
9494
})
9595

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

97102
# Visual tests ------------------------------------------------------------
98103

0 commit comments

Comments
 (0)