Redefining `ggplot` generic breaks dispatch of methods

Issue #1 new
Pedro J. Aphalo created an issue

I tracked a conflict between ggtern and my packages ggspectra (in CRAN) and ggpmisc (version to be submitted to CRAN next week) to plot.R in ggtern containing an exact copy of the definition of ggplot in ggplot2. Is this really needed?

I have defined new specializations of ggplot and they are not dispatched correctly when ggtern is also loaded unless the call is made explicitly by users to ggplot2::ggplot().

I did a quick test and ggtern seems to work correctly without redefining ggplot from scratch as anyway the definition in your package is identical to that in ggplot2.

This is the edit I did to plot.R as a test.

# ggplot <- function(data = NULL, mapping = aes(), ...,
#                    environment = parent.frame()) {
#   UseMethod("ggplot")
# }

ggplot <- ggplot2::ggplot

and it seems to solve the conflict.

Although the conflict is easy for the user to get around using ggplot2:: it may be difficult to diagnose and redefining the ggplot generic could cause other conflicts in the future.

As I noticed that you enabled Issue tracking I am recording this issue here although I mentioned it already via e-mail some weeks ago.

Best wishes,

Pedro.

Comments (4)

  1. Pedro J. Aphalo reporter

    Thanks Nicholas! This is not that urgent at this time. I do not think you should delay the current release, leave this issue to be resolved in a future release if needed. I just wrote it here both to keep a record of the problem, and as maybe someone can help (may be I can find time myself during Christmas holidays). If you agree you can set it as "on hold".

  2. Nicholas Hamilton

    I have already submitted it, now available via CRAN. Getting too many emails from people since the package was broken with respect to ggplot2 v2.2.0

  3. Log in to comment