[英]Exporting an environment from an R package
I am developing an R package that wraps the rmongodb
package and creates a developer-friendly interface for working with MongoDB. 我正在开发一个包装
rmongodb
包的R包,并创建一个开发人员友好的界面来处理MongoDB。 The package uses proto
internally. 该软件包内部使用
proto
。
I'd like to export a single factory method via a proto object (an environment) called MongoDB
, whose definition is: 我想通过名为
MongoDB
的proto对象(环境)导出单个工厂方法,其定义是:
MongoDB <- proto(
new = function(., ...) {
# Good stuff in here...
}
)
During development with RStudio & devtools
and during local testing this does not seem to be a problem. 在使用RStudio和
devtools
开发期间以及在本地测试期间,这似乎不是问题。 However, I am experiencing several problems: 但是,我遇到了几个问题:
devtools::check()
insists on putting an import(MongoDB)
in my NAMESPACE file which makes R CMD check
fail with "Namespace dependency not required: 'MongoDB'". devtools::check()
坚持在我的NAMESPACE文件中放入一个import(MongoDB)
,这使得R CMD check
失败并且“不需要命名空间依赖:'MongoDB'”。
When I remove this import directive, R CMD check
fails with "object 'MongoDB' not found" while running my testthat
tests, even if I manually add export(MongoDB)
. 当我删除这个导入指令时,即使我手动添加
export(MongoDB)
,在运行我的testthat
测试时, R CMD check
失败并且“找不到”对象'MongoDB'。 However, devtools::test()
works fine in RStudio. 但是,
devtools::test()
在RStudio中运行良好。
What is the recommended way of exporting proto
objects, which are environments, from R packages? 从R包中导出
proto
对象(环境)的推荐方法是什么?
Update: 更新:
Per Gabor's suggestion below, I've made sure that MongoDB.Rd
declares MongoDB
as data (the link has the source). 根据下面的Gabor建议,我确保
MongoDB.Rd
MongoDB
声明为数据(链接有源)。 I still get a failure in MongoDB
not being visible in the tests (which use testthat
). 我仍然在
MongoDB
失败,在测试testthat
(使用testthat
)。 My DESCRIPTION
file is here and NAMESPACE
is here . 我的
DESCRIPTION
文件在这里 , NAMESPACE
就在这里 。
Try this: 试试这个:
export("MongoDB")
in your NAMESPACE
file to make the MongoDB
proto object publicly available. NAMESPACE
文件中指定export("MongoDB")
以使MongoDB
proto对象公开可用。 LazyData: yes
in your DESCRIPTION
file so that it automatically loads when accessed. DESCRIPTION
文件中指定LazyData: yes
,以便在访问时自动加载。 .Rd
file documenting it as a dataset. .Rd
文件,将其记录为数据集。 It should then pass R CMD check
. 然后它应该通过
R CMD check
。
This directive : 该指令:
import(MongoDB)
means that you import the MongoDB
namespace into your package. 意味着您将
MongoDB
命名空间导入到包中。 Probably not what you want if i understand correctly. 如果我理解正确,可能不是你想要的。
I think you want to export the MongoDB
object, then 我想你想导出
MongoDB
对象
export(MongoDB)
should work fine. 应该工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.