maxheld
maxheld

Reputation: 4273

Pesky ggplot2 namespace conflict when using ggplot2 in package

I'm contributing to the qmethod R package, and I just wrote a function that creates a bunch of ggplot2 objects.

The function works fine, but builds and R CMD Check warns me that:

replacing previous import by ‘ggplot2::%+%’ when loading ‘qmethod’

I've looked at SE posts and @hadley's book but can't figure out the problem.

Here's the relevant parts of my NAMESPACE:

import("ggplot2",
   "stringr")
import("psych")
importFrom("plyr","count")
importFrom("reshape2","melt")
importFrom("digest", "digest")
importFrom("RColorBrewer", "brewer.pal")

And here's part of my DESCRIPTION:

Imports:
  digest,
  psych,
  knitr,
  RColorBrewer,
  stringr,
  ggplot2,
  plyr,
  reshape2

The part where I call a ggplot2 function inside my function array.viz.R looks like this (and more):

g <- ggplot(
      data = array.viz.data
      ,aes(
        x = fsc  # factor scores, always same variable bc dataframe is constructed for every factor array by above loop
        ,y = ycoord  # just the random ycoord for viz
        ,ymax = max(ycoord)
        ,ymin = 0
        #,label = item.wrapped  # this for some reason causes an error
      )
    )
    g <- g + geom_tile(  # add background tiles
      aes(
        fill = item.sd
      )
    )

Ps.: you can find the entire current work here: https://github.com/maxheld83/qmethod/tree/array-viz

Pps.: I am aware that ggplot2 itself imports a bunch of the functions I also import (such as reshape2), so I have a hunch that that might be a problem.

Upvotes: 2

Views: 450

Answers (1)

maxheld
maxheld

Reputation: 4273

Turns out, import("psych") is the offending package.

It seems to somehow export again ggplot::%+%, though I can't think of why that would be the case.

Anyway, the fix is:

importFrom("psych", "principal")  # that's the function we were using

Upvotes: 1

Related Questions