“未找到对象”为包创建新的geom时出错 [英] "object not found" error when creating a new geom for a package

查看:148
本文介绍了“未找到对象”为包创建新的geom时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

完全披露:此问题在 ggplot2 google群组



我正在开发一个大量使用 ggplot2 的包。我已经创建了自己的几何体 - geom_rug_alt - 将地毯边缘放置在情节的顶部/右侧而不是默认位置。



我的问题是当 geom_rug_alt()单个脚本,似乎情节很好。 (请自己尝试验证。)但是,在我的包中 geom_rug_alt()在一个文件中定义( CommonFunctions.R )并在另一个函数(> Residuals())中调用大函数 foo.R )。当我打电话给 foo.R 时,我得到这个错误:

  geom_rug_alt中的错误(aes(x = NULL,y = within.group.residuals,color = factor(within.1.sd.of.the.mean.of.all.residuals)),:
object' GeomRugAlt'找不到

现在,我做了一些事情(Hadley在 this thread )试图确保 geom_rug_alt( )应该在包中正常工作:


$ b


  1. 我定义 GeomRugAlt 作为 proto 对象,在我的包中基本上称为 CommonFunctions.R CommonFunctions.R 包含我的示例脚本的第3-42行。


  2. CommonFunctions.R 中,我确定包含 build_accessor () geom_rug_alt (在我的示例脚本中的第42行)在定义之后, GentRugAlt


  3. 在包描述文件中,我有一个 collat​​e: line其中 CommonFunctions.R 第一个出现


  4. package 描述文件,我有一个 LazyLoad:false

  5. code> CommonFunctions.R ,我在定义 GeomRugAlt require(ggplot2) $ c>作为 proto 对象。

  6. foo.R 中,我在中调用 geom_rug_alt()之前包含了一个 require(ggplot2)调用Residuals()

我不确定我还缺少了什么。鉴于我的示例脚本运行良好,我怀疑问题不在于我的geom无法正常工作,但是我做了一些错误的事情,作为包开发过程的一部分。



对不起,重复了这个问题,但我似乎无法找到一个彻底的解决方案问题: - (

解决方案

导出(GeomRugAlt) NAMESPACE 档案。


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

解决方案

Put export(GeomRugAlt) in the NAMESPACE file.

这篇关于“未找到对象”为包创建新的geom时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆