Skip to content

Commit b492d55

Browse files
wchhadley
authored andcommitted
Preserve class when adding uneval objects (#1624)
* Preserve class when adding uneval objects * Add test * Update NEWS
1 parent c2d91dc commit b492d55

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
* Fixed problem with `geom_violin()` when quantiles requested but data
6161
have no range. Added unit test. (#1687)
6262

63+
* Class of aesthetic mapping is preserved when adding `aes()` objects. (#1624)
64+
6365
# ggplot2 2.1.0
6466

6567
## New features

R/plot-construction.r

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ add_ggplot <- function(p, object, objectname) {
9292
p <- update_guides(p, object)
9393
} else if (inherits(object, "uneval")) {
9494
p$mapping <- defaults(object, p$mapping)
95+
# defaults() doesn't copy class, so copy it.
96+
class(p$mapping) <- class(object)
9597

9698
labels <- lapply(object, deparse)
9799
names(labels) <- names(object)

tests/testthat/test-add.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
context("Adding plot elements")
2+
3+
test_that("Mapping class is preserved when adding uneval objects", {
4+
p <- ggplot(mtcars) + aes(wt, mpg)
5+
expect_identical(class(p$mapping), "uneval")
6+
})

0 commit comments

Comments
 (0)