2

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.

Community
  • 1
  • 1
maxheld
  • 3,963
  • 2
  • 32
  • 51
  • 1
    I'm just adding this link as a reference for the source of the warning: https://github.com/wch/r-source/blob/a6e088d02a6fb54c42cfe384865ea6788c24a900/src/library/base/R/namespace.R#L836-L842 – Thomas Feb 22 '15 at 21:37

1 Answers1

1

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
maxheld
  • 3,963
  • 2
  • 32
  • 51