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

Add informative error message if user forgets data arg in ggplot() #2056

Merged
merged 4 commits into from Jun 14, 2017

Conversation

@jrnold
Copy link
Contributor

@jrnold jrnold commented Feb 25, 2017

The error message "gglot2 doesn't know how to deal with data of class uneval" is one of the more common ones that I see, and one that perplexes new users of ggplot2. I added a note about the most common reason for and fix of this error message.

If a data argument was omitted from ggplot(), the old behavior was

> ggplot(aes(x = x))
Error: ggplot2 doesn't know how to deal with data of class uneval

The new behavior is

> ggplot(aes(x = x))
Error: ggplot2 doesn't know how to deal with data of class uneval. Did you forget the data argument  in ggplot()?
@jrnold jrnold changed the title Add helpful error message Add informative error message if user forgets data arg in ggplot() Feb 27, 2017
R/fortify.r Outdated
)
if (class(model) == "uneval") {

This comment has been minimized.

@hadley

hadley Jun 1, 2017
Member

This should use inherits()

R/fortify.r Outdated
)
if (class(model) == "uneval") {
msg <- paste0(msg, " Did you forget the data argument in ggplot()?")

This comment has been minimized.

@hadley

hadley Jun 1, 2017
Member

Can you please surround data in backticks?

Is this function also called by geoms? If so, it might be confusing.

This comment has been minimized.

@jrnold

jrnold Jun 2, 2017
Author Contributor

I think that the error message will get called only if ggplot() has an aes() and no data argument:

> ggplot() + geom_point(aes(x = x, y = y))
Error in FUN(X[[i]], ...) : object 'x' not found 

But

> ggplot(aes(x = x, y = y)) + geom_point()
 Error: ggplot2 doesn't know how to deal with data of class uneval. Did you forget the `data` argument in ggplot()?

This comment has been minimized.

@hadley

hadley Jun 2, 2017
Member

What about geom_point(data = aes()) ?

This comment has been minimized.

@jrnold

jrnold Jun 12, 2017
Author Contributor

Good point. It does appear in that case. how about?

Did you accidentally provide the results of `aes()` to the `data` argument?"
jrnold added a commit to jrnold/ggplot2 that referenced this pull request Jun 2, 2017
- add ticks around `data` in message
- use `inherits` instead of equals when testing class
jrnold added 4 commits Feb 25, 2017
The error message "gglot2 doesn't know how to deal with data of class uneval" is one of the more common ones that I see, and one that perplexes new users of ggplot2. I added a note about the most common reason for and fix of this error message.
- add ticks around `data` in message
- use `inherits` instead of equals when testing class
Needed after updates to the message
As noted by @hadley in #2056, the warning for `uneval` also appears in geoms as well as ggplot()
@hadley
Copy link
Member

@hadley hadley commented Jun 12, 2017

Looks like something has gone wrong with your merge/rebase

@jrnold jrnold force-pushed the jrnold:error-uneval-msg branch from d3da912 to c46184d Jun 14, 2017
@jrnold
Copy link
Contributor Author

@jrnold jrnold commented Jun 14, 2017

I rewrote history so nothing bad ever happend

@hadley hadley merged commit 74d52f5 into tidyverse:master Jun 14, 2017
4 checks passed
4 checks passed
@codecov
codecov/patch 100% of diff hit (target 74.97%)
Details
@codecov
codecov/project 75.07% (+0.1%) compared to f84e315
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@hadley
Copy link
Member

@hadley hadley commented Jun 14, 2017

Thanks!

@jrnold
Copy link
Contributor Author

@jrnold jrnold commented Jun 14, 2017

👍

@lock
Copy link

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

Successfully merging this pull request may close these issues.

None yet

2 participants