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") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use inherits()

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please surround data in backticks?

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about geom_point(data = aes()) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
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 tidyverse#2056, the warning for `uneval` also appears in geoms as well as ggplot()
@hadley
Copy link
Member

hadley commented Jun 12, 2017

Looks like something has gone wrong with your merge/rebase

@jrnold
Copy link
Contributor Author

jrnold commented Jun 14, 2017

I rewrote history so nothing bad ever happend

@hadley hadley merged commit 74d52f5 into tidyverse:master Jun 14, 2017
@hadley
Copy link
Member

hadley commented Jun 14, 2017

Thanks!

@jrnold
Copy link
Contributor Author

jrnold commented Jun 14, 2017

👍

@lock
Copy link

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
Development

Successfully merging this pull request may close these issues.

2 participants