Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ ggplot2 0.9.3.1.99
* `ggpcp()`, `ggfluctuation()`, `ggmissing()`, `ggstructure()`, and
`ggorder()` are now defunct and have been removed.

* `aes()` no more treats variables like `a..x..b as a calculated aesthetic.
(@krlmlr, #834.)

* Add `"none"` to documentation of `theme()` for parameter `legend.position`.
(@krlmlr, #829)

Expand Down
2 changes: 1 addition & 1 deletion R/labels.r
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ ggtitle <- function(label) {
# Convert aesthetic mapping into text labels
make_labels <- function(mapping) {
remove_dots <- function(x) {
gsub("\\.\\.([a-zA-z._]+)\\.\\.", "\\1", x)
gsub(.calculated_aes_regex, "\\1", x)
}

lapply(mapping, function(x) remove_dots(deparse(x)))
Expand Down
10 changes: 6 additions & 4 deletions R/layer.r
Original file line number Diff line number Diff line change
Expand Up @@ -258,17 +258,19 @@ Layer <- proto(expr = {
#' @export
layer <- Layer$new

# Regex to determine if an identifier refers to a calculated aesthetic
.calculated_aes_regex <- "^\\.\\.([a-zA-z._]+)\\.\\.$"

# Determine if aesthetic is calculated
is_calculated_aes <- function(aesthetics) {
match <- "\\.\\.([a-zA-z._]+)\\.\\."
stats <- rep(FALSE, length(aesthetics))
grepl(match, sapply(aesthetics, deparse))
grepl(.calculated_aes_regex, sapply(aesthetics, deparse))
}

# Strip dots from expressions
strip_dots <- function(aesthetics) {
match <- "\\.\\.([a-zA-z._]+)\\.\\."
strings <- lapply(aesthetics, deparse)
strings <- lapply(strings, gsub, pattern = match, replacement = "\\1")
strings <- lapply(strings, gsub, pattern = .calculated_aes_regex,
replacement = "\\1")
lapply(strings, function(x) parse(text = x)[[1]])
}
7 changes: 7 additions & 0 deletions inst/tests/test-layer.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
context("Layer")

test_that("Correctly decide if a variable is a calculated aesthetic", {
expect_true(ggplot2:::is_calculated_aes(aes(x=..density..)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are run in the package namespace, so you don't need ggplot2:::

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh. Fixed.

I just haven't found a good workflow for running new tests from within RStudio (without building the package or remembering difficult testthat function calls). How do you test new tests?

expect_false(ggplot2:::is_calculated_aes(aes(x=a..x..b)))
expect_equal(as.character(ggplot2:::strip_dots(aes(x=..density..))), "density")
})