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

Better error message when trying to add a function to a plot. #3594

Merged
merged 2 commits into from
Oct 29, 2019

Conversation

clauswilke
Copy link
Member

This closes #3571:

library(ggplot2)
ggplot() + geom_point
#> Error: Don't know how to add geom_point to a plot. Did you mean geom_point()?

Created on 2019-10-28 by the reprex package (v0.3.0)

Copy link
Member

@yutannihilation yutannihilation left a comment

Choose a reason for hiding this comment

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

Looks good!

Comment on lines +103 to +107
ggplot_add.function <- function(object, plot, object_name) {
stop(
"Don't know how to add ", object_name, " to a plot. Did you mean ",
object_name, "()?", call. = FALSE
)
Copy link
Member

Choose a reason for hiding this comment

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

Do we use abort()? Or will it be done in #3526?

Copy link
Member Author

Choose a reason for hiding this comment

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

As of now, we're using stop(). See e.g. here (purposefully not using permalink):
https://github.com/tidyverse/ggplot2/blob/master/R/plot-construction.r#L89-L92

Copy link
Member

Choose a reason for hiding this comment

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

OK.

NAMESPACE Outdated Show resolved Hide resolved
@clauswilke clauswilke merged commit 5188f5e into tidyverse:master Oct 29, 2019
@clauswilke clauswilke deleted the issue-3571-ggplot_add branch October 29, 2019 16:32
@lock
Copy link

lock bot commented May 5, 2020

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 May 5, 2020
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.

Suggestion for more informative error message when () missing from geom_*
2 participants