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

Better error messages for incorrect aesthetic mappings #3060

Closed
clauswilke opened this issue Jan 7, 2019 · 2 comments · Fixed by #3091
Closed

Better error messages for incorrect aesthetic mappings #3060

clauswilke opened this issue Jan 7, 2019 · 2 comments · Fixed by #3091
Labels
tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day

Comments

@clauswilke
Copy link
Member

I encountered some cryptic error messages that pop up in response to fairly normal user mistakes, where the user maps an aesthetic to a data column that doesn't exist. A better error message could help a lot here.

My code example below first shows the desired output and then two incorrect ways in which a user might try to generate it.

library(ggplot2)

# desired plot
ggplot(mtcars, aes(mpg, 1)) +
  geom_tile(aes(fill = stat(density)), stat = "density") +
  geom_point(position = "jitter")

# wrong, `fill` aesthetic mapped to stat-generated data column that
# doesn't exist in `geom_point()` layer
ggplot(mtcars, aes(mpg, 1, fill = stat(density))) +
  geom_tile(stat = "density") +
  geom_point(position = "jitter")
#> Error in is.finite(x): default method not implemented for type 'closure'

# wrong, `fill` aesthetic mapped to data column that doesn't exist
ggplot(mtcars, aes(mpg, 1, fill = density)) +
  geom_tile(stat = "density") +
  geom_point(position = "jitter")
#> Don't know how to automatically pick scale for object of type function. Defaulting to continuous.
#> Error: Column `fill` must be a 1d atomic vector or a list

Created on 2019-01-07 by the reprex package (v0.2.1)

@clauswilke clauswilke added the tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day label Jan 19, 2019
@clairemcwhite
Copy link
Contributor

I'll work in this for dev-day

clairemcwhite added a commit to clairemcwhite/ggplot2 that referenced this issue Jan 19, 2019
clairemcwhite added a commit to clairemcwhite/ggplot2 that referenced this issue Jan 19, 2019
clauswilke pushed a commit that referenced this issue Apr 29, 2019
* Clearer error messages for invalid aesthetics

Fixes #3060

* closes #3060

* Modified error messages, fixed spacing, right line endings

* Replace use of deparse with rlang::as_label

* Fix NEWS mispelling and punctuation. layer.R format suggestions

* Left in merge >>>, removed

* Remove punctuation in test-layer.R that was failing

* Add support for multiple problematic aesthetics, fix NEWS.md addition

* Change error to display whole problematic phrase, like fill = density

* Update tests to be more specific

* Fix failing tests, ideally

* Another go at test passing

* expect_error uses regex, so ( caused failing. Added fixed = TRUE
@lock
Copy link

lock bot commented Oct 26, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Oct 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants