“object not found” error when creating a new geom

2019-08-06 05:46发布

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 :-(

标签: r ggplot2
1条回答
Rolldiameter
2楼-- · 2019-08-06 05:59

Put export(GeomRugAlt) in the NAMESPACE file.

查看更多
登录 后发表回答