Skip to content

Commit f4cfc8c

Browse files
teunbrandthomasp85
authored andcommitted
Don't strip classes in Geom$use_defaults() (#5657)
* Use `vec_cbind()` instead of data.frame assignment * ignore rownames in test * Add test for AsIs class
1 parent c0af317 commit f4cfc8c

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

R/geom-.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ Geom <- ggproto("Geom",
173173
# Override mappings with params
174174
aes_params <- intersect(self$aesthetics(), names(params))
175175
check_aesthetics(params[aes_params], nrow(data))
176-
data[aes_params] <- params[aes_params]
177-
data
176+
vec_cbind(data[setdiff(names(data), aes_params)], !!!params[aes_params])
178177
},
179178

180179
# Most parameters for the geom are taken automatically from draw_panel() or

tests/testthat/test-geom-smooth.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ test_that("data is ordered by x", {
44
ps <- ggplot(df, aes(x, y))+
55
geom_smooth(stat = "identity", se = FALSE)
66

7-
expect_equal(layer_data(ps)[c("x", "y")], df[order(df$x), ])
7+
expect_equal(layer_data(ps)[c("x", "y")], df[order(df$x), ], ignore_attr = TRUE)
88
})
99

1010
test_that("geom_smooth works in both directions", {

tests/testthat/test-layer.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,19 @@ test_that("layer warns for constant aesthetics", {
140140

141141
# Data extraction ---------------------------------------------------------
142142

143+
test_that("AsIs data passes unmodified", {
144+
p <- ggplot() + geom_blank(aes(x = 1:2, y = 1:2))
145+
ld <- layer_data(p + geom_point(aes(x = I(0.5), y = I(0.5))), 2)
146+
expect_s3_class(ld$x, "AsIs")
147+
expect_equal(ld$y, I(0.5))
148+
ld <- layer_data(p + geom_point(x = I(0.5), y = I(0.5), data = mtcars), 2)
149+
expect_s3_class(ld$x, "AsIs")
150+
expect_equal(ld$y[1], I(0.5))
151+
ld <- layer_data(p + annotate("point", x = I(0.5), y = I(0.5)), 2)
152+
expect_s3_class(ld$x, "AsIs")
153+
expect_equal(ld$y, I(0.5))
154+
})
155+
143156
test_that("layer_data returns a data.frame", {
144157
l <- geom_point()
145158
expect_equal(l$layer_data(mtcars), unrowname(mtcars))

0 commit comments

Comments
 (0)