You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Suggestion for more informative error message when () missing from geom_* #3571
This issue wasn't prompted by confusion between %>% and + or people using functions without () in pipelines. In most cases where I've seen code like this it wasn't due to an expectation of geom_point() working without the (), it was just forgetting to add the parantheses. I, like many others, start teaching with visualization/ggplot2 so there are lots of very newbie mistakes as people are learning the syntax.
I also agree that this is not widespread confusion, but more of a nice-to-have to help the few who struggle.
Note that I have not done a cost-benefit analysis of implementation difficulty vs. benefit of having the improved error in place, so I can't really say if it's "worth it" to make the change.
Actually, I think this will do it. I can prepare a PR.
library(ggplot2)
# ggplot_add variant to be addedggplot_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
)
}
# new error message
ggplot() +geom_point#> Error: Don't know how to add geom_point to a plot. Did you mean geom_point()?
Activity
yutannihilation commentedon Oct 28, 2019
This has been discussed on #3106 (comment) and some of us actually agreed the error message can be improved.
mine-cetinkaya-rundel commentedon Oct 28, 2019
I see, thanks for the link!
This issue wasn't prompted by confusion between
%>%and+or people using functions without()in pipelines. In most cases where I've seen code like this it wasn't due to an expectation ofgeom_point()working without the(), it was just forgetting to add the parantheses. I, like many others, start teaching with visualization/ggplot2 so there are lots of very newbie mistakes as people are learning the syntax.I also agree that this is not widespread confusion, but more of a nice-to-have to help the few who struggle.
Note that I have not done a cost-benefit analysis of implementation difficulty vs. benefit of having the improved error in place, so I can't really say if it's "worth it" to make the change.
yutannihilation commentedon Oct 28, 2019
Ah, thanks for the context. I guess it won't be very difficult to add some heuristic here, which is called only when raising this error:
ggplot2/R/plot-construction.r
Lines 90 to 92 in 6f5ffea
clauswilke commentedon Oct 28, 2019
Yes, just check whether
objectis a function, and if it is suggest that they may have forgotten the parentheses.clauswilke commentedon Oct 28, 2019
Actually, I think this will do it. I can prepare a PR.
Created on 2019-10-28 by the reprex package (v0.3.0)
better error message when trying to add a function to a plot. Closes t…
clauswilke commentedon Oct 28, 2019
See #3594.
better error message when trying to add a function to a plot. Closes #…
lock commentedon 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/