Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify environment of aes #125

Closed
3 tasks done
rpruim opened this issue Jun 13, 2019 · 1 comment
Closed
3 tasks done

modify environment of aes #125

rpruim opened this issue Jun 13, 2019 · 1 comment

Comments

@rpruim
Copy link

rpruim commented Jun 13, 2019

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

  • write a function that finds all (or some subset of) quosures in a mapping and sets their environments as we desire
  • use the environment of the formula as the environment
  • make this change in or after calling gf_ingredients().
@rpruim
Copy link
Author

rpruim commented Jun 13, 2019

This now works:

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant