Skip to content

Preserve class when adding uneval objects #1624

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 3 commits into from
Aug 12, 2016
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: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* Minor code formatting issues in examples and function parameters were
fixed. (@hrbrmstr)

* Class of aesthetic mapping is preserved when adding `aes()` objects. (#1624)

# ggplot2 2.1.0

## New features
Expand Down
2 changes: 2 additions & 0 deletions R/plot-construction.r
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ add_ggplot <- function(p, object, objectname) {
p <- update_guides(p, object)
} else if (inherits(object, "uneval")) {
p$mapping <- defaults(object, p$mapping)
# defaults() doesn't copy class, so copy it.
class(p$mapping) <- class(object)

labels <- lapply(object, deparse)
names(labels) <- names(object)
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-add.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
context("Adding plot elements")

test_that("Mapping class is preserved when adding uneval objects", {
p <- ggplot(mtcars) + aes(wt, mpg)
expect_identical(class(p$mapping), "uneval")
})