“未找到对象”为包创建新的geom时出错 [英] "object not found" error when creating a new geom for a package
问题描述
我正在开发一个大量使用 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
-
我定义
GeomRugAlt
作为proto
对象,在我的包中基本上称为CommonFunctions.R
。CommonFunctions.R
包含我的示例脚本的第3-42行。 -
在
CommonFunctions.R
中,我确定包含build_accessor ()
geom_rug_alt
(在我的示例脚本中的第42行)在定义
之后, GentRugAlt
-
在包
描述
文件中,我有一个collate:
line其中CommonFunctions.R
第一个出现 - package
描述
文件,我有一个LazyLoad:false
行 - code> CommonFunctions.R ,我在定义
GeomRugAlt $ c之前调用了
require(ggplot2)
$ c>作为proto
对象。 - 在
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:
I define
GeomRugAlt
as aproto
object in a file essentially calledCommonFunctions.R
within my package.CommonFunctions.R
contains lines 3-42 of my example script.In
CommonFunctions.R
, I was sure to include thebuild_accessor()
line forgeom_rug_alt
(line 42 in my example script) after the definition ofGeomRugAlt
In the package
DESCRIPTION
file, I have acollate:
line whereCommonFunctions.R
appears first- In the package
DESCRIPTION
file, I have aLazyLoad: false
line - In
CommonFunctions.R
, I included arequire(ggplot2)
call before definingGeomRugAlt
as aproto
object. - In
foo.R
, I included arequire(ggplot2)
call before callinggeom_rug_alt()
withinResiduals()
.
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屋!