Skip to content

Commit 399ec2d

Browse files
committed
Add test for aes eval environment. Closes #744
1 parent f7bfdfc commit 399ec2d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

inst/tests/test-aes.r

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,25 @@ test_that("function aes_auto", {
7171
expect_equal(aes_auto(df), structure(setNames(list(), character(0)), class = "uneval"))
7272
})
7373

74+
75+
76+
test_that("aes evaluated in environment where plot created", {
77+
df <- data.frame(x = 1, y = 1)
78+
79+
p <- ggplot(df, aes(foo, y)) + geom_point()
80+
x_data <- function(p) ggplot_build(p)$data[[1]]$x
81+
82+
# Accessing an undefined variable should result in error
83+
expect_error(x_data(p), "'foo' not found")
84+
85+
# Once it's defined we should get it back
86+
foo <- 0
87+
expect_equal(x_data(p), 0)
88+
89+
# And regular variable shadowing should work
90+
f <- function() {
91+
foo <- 10
92+
ggplot(df, aes(foo, y)) + geom_point()
93+
}
94+
expect_equal(x_data(f()), 10)
95+
})

0 commit comments

Comments
 (0)