1
votes

Full disclosure: this issue is duplicated on the ggplot2 google group

I'm developing a package that makes heavy use of ggplot2. I've created my own geom—geom_rug_alt—as a way of putting rug fringes on the top/right of the plot instead of the default locations.

My problem is that when geom_rug_alt() is defined and called within a single script, it seems to plot just fine. (Please try it yourself to verify that.) But, in my package geom_rug_alt() is defined in one file (CommonFunctions.R) and called in another (the Residuals() function of larger function foo.R). When I call foo.R on something, I get this error:

Error in geom_rug_alt(aes(x = NULL, y = within.group.residuals, color = factor(within.1.sd.of.the.mean.of.all.residuals)),  : 
object 'GeomRugAlt' not found

Now, I've done a couple of things (suggested by Hadley in this thread) to try to make sure that geom_rug_alt() should work properly within the package:

  1. I define GeomRugAlt as a proto object in a file essentially called CommonFunctions.R within my package. CommonFunctions.R contains lines 3-42 of my example script.

  2. In CommonFunctions.R, I was sure to include the build_accessor() line for geom_rug_alt (line 42 in my example script) after the definition of GeomRugAlt

  3. In the package DESCRIPTION file, I have a collate: line where CommonFunctions.R appears first

  4. In the package DESCRIPTION file, I have a LazyLoad: false line
  5. In CommonFunctions.R, I included a require(ggplot2) call before defining GeomRugAlt as a proto object.
  6. In foo.R, I included a require(ggplot2) call before calling geom_rug_alt() within Residuals().

I'm not sure what else I'm missing. Given that my example script runs just fine, I suspect the issue isn't that my geom doesn't work, but that I'm doing something wrong as part of the package development process.

Sorry for duplicating the issue, but I can't seem to find a thorough solution to the problem :-(

1
Did you put export(geom_rug_alt) in the NAMESPACE file? - Sacha Epskamp
@Sascha - that works! Actually, it needs to be export(GeomRugAlt), not export(geom_rug_alt), since GeomRugAlt is the object it's not finding. Can you please post that as a answer so I can accept it? - briandk
If your description and namespace files are correct you shouldn't need to manually require ggplot2. I'd also recommend running R CMD check - hadley
@Hadley - after running R CMD check on my package, among many other errors I got this: geom_rug_alt: no visible binding for global variable ‘GeomRugAlt’ - briandk
I would suggest fixing all the errors that you can and then making the package source available somewhere. - hadley

1 Answers

1
votes

Put export(GeomRugAlt) in the NAMESPACE file.