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

Projects
None yet
2 participants
@jrnold
Contributor

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 from Add helpful error message to 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

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

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

Fix hadley comments in tidyverse#2056
- add ticks around `data` in message
- use `inherits` instead of equals when testing class

jrnold added some commits Feb 25, 2017

Add helpful error message
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.
Fix hadley comments in #2056
- add ticks around `data` in message
- use `inherits` instead of equals when testing class
fix fortify test
Needed after updates to the message
improve error message
As noted by @hadley in #2056, the warning for `uneval` also appears in geoms as well as ggplot()
@hadley

This comment has been minimized.

Member

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

This comment has been minimized.

Contributor

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

codecov/patch 100% of diff hit (target 74.97%)
Details
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

This comment has been minimized.

Member

hadley commented Jun 14, 2017

Thanks!

@jrnold

This comment has been minimized.

Contributor

jrnold commented Jun 14, 2017

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment