Skip to content

Commit 7d4c556

Browse files
committed
Merge branch 'NikNakk-master'
2 parents fe0e5c6 + 384bf60 commit 7d4c556

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ ggplot2 1.0.1.9xxx
191191

192192
* `override.aes` now works with American aesthetic spelling, e.g. color
193193

194+
* Fixed `strip_dots` to work with anonymous functions within calculated
195+
aesthetics (e.g. `aes(sapply(..density.., function(x) mean(x))))`
196+
(#1154, @NikNakk)
197+
194198
ggplot2 1.0.1
195199
----------------------------------------------------------------
196200

R/aes-calculated.r

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,18 @@ strip_dots <- function(expr) {
2828
if (is.atomic(expr)) {
2929
expr
3030
} else if (is.name(expr)) {
31-
as.name(gsub(match_calculated_aes, "\\1", as.character(expr)))
31+
expr_ch <- as.character(expr)
32+
if (nchar(expr_ch) > 0) {
33+
as.name(gsub(match_calculated_aes, "\\1", expr_ch))
34+
} else {
35+
expr
36+
}
3237
} else if (is.call(expr)) {
3338
expr[-1] <- lapply(expr[-1], strip_dots)
3439
expr
3540
} else if (is.pairlist(expr)) {
3641
# In the unlikely event of an anonymous function
37-
as.pairlist(lapply(expr, expr))
42+
as.pairlist(lapply(expr, strip_dots))
3843
} else if (is.list(expr)) {
3944
# For list of aesthetics
4045
lapply(expr, strip_dots)

tests/testthat/test-layer.r

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ test_that("Calling using variable surround by .. is calculated", {
1515
test_that("strip_dots remove dots around calculated aesthetics", {
1616
expect_equal(strip_dots(aes(x=..density..))$x, quote(density))
1717
expect_equal(strip_dots(aes(mean(..density..)))$x, quote(mean(density)))
18+
expect_equal(strip_dots(aes(sapply(..density.., function(x) mean(x)))$x),
19+
quote(sapply(density, function(x) mean(x))))
1820
})

0 commit comments

Comments
 (0)