-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Conversation
R/fortify.r
Outdated
) | ||
if (class(model) == "uneval") { |
There was a problem hiding this comment.
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()?") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()?
There was a problem hiding this comment.
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())
?
There was a problem hiding this comment.
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?"
- 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()
Looks like something has gone wrong with your merge/rebase |
I rewrote history so nothing bad ever happend |
Thanks! |
👍 |
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/ |
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 fromggplot()
, the old behavior wasThe new behavior is