-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add add_ggplot
method
#3818
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
base: main
Are you sure you want to change the base?
Add add_ggplot
method
#3818
Conversation
While I am not 100% against this, I’m very skeptic and fear that we will end up in a situation where the API clarity is impaired. So while it is a fairly simple change I think we should have some internal discussions about this before we move forward |
I'm against. I believe this should be solved by double dispatch, not by avoiding double dispatch. As I commented on #3815, it's possible even with the current ggplot2 if you wrap your object with S4. Anyway, a discussion about this is welcome. |
Agreed that it's possible to have it work with S4. One of the objects would be an S4 object, so S4 dispatch would occur when using an I can not upgrade my object to be S4 without breaking my downstream dependencies. I don't know how this can be solved by double dispatch. The double dispatch that happens on all Being S3, it comes with the advantage that package developers can call |
I meant
Can we see some examples of the breakage? One more question, are there any due date to fix this issue? Even if this PR is accepted, the release would probably be 0.5 ~ 1 year away. I think GGally is one of the important packages in ggplot2 ecosystem so I believe we all want to help you solve the problem, but I'm afraid this PR might not be the best approach. |
Timeline: The ggplot2 v3.3.0 release got me moving again on GGally. But it has been this way for years, so waiting another 6-12 months is not the end of the world. I'd rather have a correct solution than a rushed solution. Off-hand, I believe I am told users access information using the |
Aw, I see... Thanks for the example. |
@schloerke Could you open an issue for this topic? I feel having these discussions in the PR is not that useful. We should first properly document what the problem is, and then we can discuss different solutions to the problem. |
While this fix isn't perfect, I think it's a reasonable hack to get the desired behaviour and it follows a similar pattern to what we've used in vctrs and I'm about to implement in R7. |
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.
@schloerke do you want to finish this off?
Co-authored-by: Hadley Wickham <h.wickham@gmail.com>
* master: (320 commits) Orientation-aware key glyphs (tidyverse#4757) Fix warning in geom_violin with draw_quantiles (tidyverse#4654) Fix misalignment in geom_dotplot when stackratio != 1 and stackdir != "up" (tidyverse#4734) Replace coord_equal in scale-identity.r (tidyverse#4759) Unified message format in `geom_smooth()` (tidyverse#4634) Add parentheses to mentions of binned_scale in scale-alpha and scale-viridis documentation (tidyverse#4735) Update geom-boxplot.r (tidyverse#4744) Remove unneeded backslash from diamonds docs (tidyverse#4711) Re-document Warn on unsupported geoms in annotate() (tidyverse#4721) Re-document Add Trump to presidential terms dataset (tidyverse#4702) Corrects bins / binwidth override documentation (tidyverse#4720) Update infrastructure to new best practices (tidyverse#4748) remove stringsAsFactor for the mapped_discrete as.data.frame method (tidyverse#4750) Workflow updates (tidyverse#4747) Ensure output is numeric even if ifelse clause is NA (tidyverse#4692) Add non_missing_aes to geom_tile (tidyverse#4683) Pass on binwidth and height to geom (tidyverse#4671) Check for range == NULL - happens if no data has been added to plot (tidyverse#4682) ...
@hadley Requested changes made. News entry added. Please let me know if there is anything else I can add! Looking forward to R7! |
Let me clarify my stance on this pull request. Honestly, I'm not very happy that we are about to end up with exposing both |
I think I can accept this if we rename the method to something else. I share @yutannihilation's feelings about having A name I can live with and which makes the method very clear would be |
Providing an out here as well.... If R7 will solve this, I'm happy to wait for a proper solution. The current behavior is more inconvenient than it is broken. So no need to add to the API if it could be resolved later with R7. |
If that is the case I vote for closing this and wait it out. @clauswilke and @yutannihilation are you fine with this? |
Just to be sure, "later" means "at least a few years away" (c.f. #4743 (comment)). I thought it would be a bit too far, so my take stays same as above, but I'm fine if everyone is fine. |
No strong opinion either way from my side. |
I'd prefer this sooner rather than later (especially if it's a few years down the road), but I don't have to deal with the aftermath of maintaining it, so I'm good with the decision that suits the team. |
Followup to #3815
I did not have the separation at the correct point and I did not explain it well. Trying again.
Context
Let's say
foo
is a class defined by a package other than ggplot2.foo
objects also inherit fromgg
.bar
objects doc not inherit fromgg
You can currently perform
gg_obj + foo_obj
as both objects inherit fromgg
and would produce the same+.gg
method from Opt's double dispatch.Currently, to control how the right-hand-side (
foo
objects) are added, we can defineggplot_add.foo
.Problem
However, currently we can not customize how left-hand-side objects (
foo_obj + gg_obj
) are added togg
objects.Ex: left hand side structures are not ggplot2 objects and will not work with ggplot2 internal methods
Ex: conflict
+
methods make addition impossibleGoal with PR
Define a
add_gg.foo(e1, e2)
method. When addingfoo_obj
togg_obj
,+.gg
will be called, which will then calladd_gg
.add_gg
will not invoke double dispatch (like+
does), so custom left-hand-side methods can be created.ggplot2
's+.gg
is not commutative. So I believe this situation has merit.Created on 2020-02-11 by the reprex package (v0.3.0)