ProjectMOSAIC / ggformula

Provides a formula interface to 'ggplot2' graphics.
Other
38 stars 11 forks source link

modify environment of aes #125

Closed rpruim closed 5 years ago

rpruim commented 5 years ago

It looks like we can (attempt to) fix some of the niggling environment issues by manually adjusting the environment of the parts of the mapping/aes that are quosures. (See #96, #110, #119).

ggplot2::aes() doesn't provide a way to control the environment at the point of creation:

ggplot2::aes
## function (x, y, ...) 
## {
##     exprs <- rlang::enquos(x = x, y = y, ...)
##     is_missing <- vapply(exprs, rlang::quo_is_missing, logical(1))
##     aes <- new_aes(exprs[!is_missing], env = parent.frame())
##     rename_aes(aes)
## }
## <bytecode: 0x7f7f1ebab700>
## <environment: namespace:ggplot2>

But we can

rpruim commented 5 years ago

This now works:

suppressPackageStartupMessages(library(ggformula))
t <- rnorm(1000)
gf_histogram(~t)

Created on 2019-06-13 by the reprex package (v0.3.0)