Skip to content

Commit 1471d92

Browse files
author
Kirill Müller
committed
when testing if an identifier refers to a calculated aesthetic, check the whole identifier, not a substring
also, define the regex that is used for matching only once, in a hidden global variable fixes #834 Conflicts: R/layer.r Resolved by combining.
1 parent 52326a4 commit 1471d92

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-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

1114
ggplot2 0.9.3.1
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
}

0 commit comments

Comments
 (0)