Skip to content

Fix cryptic error messages caused by missing aesthetics #2754

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

Merged
merged 3 commits into from
Aug 7, 2018

Conversation

dpseidel
Copy link
Collaborator

Fixes #2637 ; Fixes #2706

This is a minor change switching the order of calls in layer$compute_geom_1 to call check_required_aesthetics() before geom*$setup_data() in order to catch missing aesthetics and offer informative error messages.

This fixes cryptic error messages from GeomArea, GeomCol, GeomCrossbar, GeomErrorbar, GeomErrorbarh, GeomLine, GeomRaster, GeomSpoke, and GeomTile.

From my analysis this should have no adverse side effects.

The other Geoms' were appropriately handled for one of two reasons:

  1. their setup_data() functions simply return data unchanged and therefore did not call any potentially missing aesthetics which caused the cryptic errors before check_required_aesthetics was originally called (e.g. GeomPoint, GeomText, GeomRibbon, ...).

Or,

  1. the missing aesthetics are caught by stat_*$compute_layer() and the appropriate warning returned earlier (e.g. GeomBoxplot, GeomSmooth, GeomHex, GeomBar...).

All tests pass and I have checked the new behaviour of all Geoms, but I am open to considering other ways to test this or potential side effects I have not foreseen. I was unsure if the NEWS bullet was warranted but as it fixes two user facing issues I figured it was potentially useful.

@hadley
Copy link
Member

hadley commented Jul 11, 2018

Can you please turn one of the issues into a test? (i.e. test that the error is informative)

@clauswilke do you mind reviewing this? I suspect you are more familiar with this part of the ggplot2 code than me at the moment.

@dpseidel
Copy link
Collaborator Author

✔️ test added!

@clauswilke
Copy link
Member

I had looked at this when #2637 was originally filed. My judgment then was that it's probably fine to switch the order but I don't understand the implications well enough to be 100% confident. I think it is reasonable to go ahead with the change and hope for the best. It might break some extension package somewhere out there, but it's probably not technically a breaking change, more of an API clarification.

As an extra check, I just looked at the code I have written in ggridges. It assumes that required aesthetics are checked before setup_data() is called. It's probably what most people would assume intuitively: You want to check your input, not what you do with your input.

@dpseidel dpseidel merged commit f135340 into tidyverse:master Aug 7, 2018
@lock
Copy link

lock bot commented Feb 3, 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 Feb 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Make Missing mapping Errors More Informative Cryptic errors because Geom*$setup_data runs before check_required_aes
3 participants