diff --git a/R/plot-construction.r b/R/plot-construction.r index 8e64c84e03..2f71cd9a45 100644 --- a/R/plot-construction.r +++ b/R/plot-construction.r @@ -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) } diff --git a/tests/testthat/test-aes.r b/tests/testthat/test-aes.r index 598b0ee86e..f32bcc48ac 100644 --- a/tests/testthat/test-aes.r +++ b/tests/testthat/test-aes.r @@ -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 ------------------------------------------------------------