Skip to content

Commit f75440b

Browse files
Return NULL if the mapping is NULL
1 parent 2552f95 commit f75440b

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

R/aes-calculated.r

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ strip_dots <- function(expr) {
8787
# Convert aesthetic mapping into text labels
8888
make_labels <- function(mapping) {
8989
default_label <- function(aesthetic, mapping) {
90-
# e.g., geom_smooth(aes(colour = "loess")) or aes(y = NULL)
90+
if (is.null(mapping)) {
91+
return(NULL)
92+
}
93+
94+
# e.g., geom_smooth(aes(colour = "loess"))
9195
if (is.atomic(mapping)) {
9296
return(aesthetic)
9397
}

tests/testthat/test-aes-calculated.r

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ test_that("make_labels() deprases mappings properly", {
3434
# long expression is abbreviated with ...
3535
expect_identical(make_labels(aes(x = 2 * x * exp(`coef 1` * x^2) * 2 * x * exp(`coef 1` * x^2) * 2 * x)),
3636
list(x = "2 * x * exp(`coef 1` * x^2) * 2 * x * exp(`coef 1` * x^2) * 2 * ..."))
37-
# if the mapping is a literal or NULL, the aesthetics is used
37+
# if the mapping is a literal, the aesthetics is used
3838
expect_identical(make_labels(aes(x = 1)), list(x = "x"))
39-
expect_identical(make_labels(aes(x = NULL)), list(x = "x"))
39+
# if the mapping is NULL, there will be no labels
40+
expect_identical(make_labels(aes(x = NULL)), list(x = NULL))
4041
})

0 commit comments

Comments
 (0)