Skip to content

Commit 02fdb3e

Browse files
committed
Merge pull request #917 from krlmlr/fix/834-calculated-dots-2
when testing if an identifier refers to a calculated aesthetic, check the whole identifier, not a substring
2 parents 8bbeef3 + efa35f9 commit 02fdb3e

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ ggplot2 0.9.3.1.99
77
* `ggpcp()`, `ggfluctuation()`, `ggmissing()`, `ggstructure()`, and
88
`ggorder()` are now defunct and have been removed.
99

10+
* `aes()` no more treats variables like `a..x..b as a calculated aesthetic.
11+
(@krlmlr, #834.)
12+
1013
* Add `"none"` to documentation of `theme()` for parameter `legend.position`.
1114
(@krlmlr, #829)
1215

R/labels.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ ggtitle <- function(label) {
6565
# Convert aesthetic mapping into text labels
6666
make_labels <- function(mapping) {
6767
remove_dots <- function(x) {
68-
gsub("\\.\\.([a-zA-z._]+)\\.\\.", "\\1", x)
68+
gsub(.calculated_aes_regex, "\\1", x)
6969
}
7070

7171
lapply(mapping, function(x) remove_dots(deparse(x)))

R/layer.r

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,17 +258,19 @@ Layer <- proto(expr = {
258258
#' @export
259259
layer <- Layer$new
260260

261+
# Regex to determine if an identifier refers to a calculated aesthetic
262+
.calculated_aes_regex <- "^\\.\\.([a-zA-z._]+)\\.\\.$"
263+
261264
# Determine if aesthetic is calculated
262265
is_calculated_aes <- function(aesthetics) {
263-
match <- "\\.\\.([a-zA-z._]+)\\.\\."
264266
stats <- rep(FALSE, length(aesthetics))
265-
grepl(match, sapply(aesthetics, deparse))
267+
grepl(.calculated_aes_regex, sapply(aesthetics, deparse))
266268
}
267269

268270
# Strip dots from expressions
269271
strip_dots <- function(aesthetics) {
270-
match <- "\\.\\.([a-zA-z._]+)\\.\\."
271272
strings <- lapply(aesthetics, deparse)
272-
strings <- lapply(strings, gsub, pattern = match, replacement = "\\1")
273+
strings <- lapply(strings, gsub, pattern = .calculated_aes_regex,
274+
replacement = "\\1")
273275
lapply(strings, function(x) parse(text = x)[[1]])
274276
}

inst/tests/test-layer.r

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
context("Layer")
2+
3+
test_that("Correctly decide if a variable is a calculated aesthetic", {
4+
expect_true(is_calculated_aes(aes(x=..density..)))
5+
expect_false(is_calculated_aes(aes(x=a..x..b)))
6+
expect_equal(as.character(strip_dots(aes(x=..density..))), "density")
7+
})

0 commit comments

Comments
 (0)