roxygen2 是否自动为“导入:”编写 NAMESPACE 指令?包裹?
我的问题的 tl;dr 版本
如果我想导入包,是否必须手动将 import()
指令写入我的 NAMESPACE 文件中?看起来 roxygen2 不会神奇地为我做到这一点,即使我在描述中将它们列为“导入:”。
完整版本
这是一个非常愚蠢的问题,但我问这个问题是因为答案对我来说并不明显。
我使用roxygen2
来处理我的R包文档。当我想确保导出某个函数时,我会在其 roxygen 块中添加一个 @export
标记。后续运行 roxygenize()
将相应地写入 NAMESPACE 指令。
但是,我的包当前导入了其他几个:
Depends:
R (>= 2.13.0),
ggplot2 (>= 0.8.9)
Imports:
RColorBrewer,
plyr,
gridExtra
看起来,虽然roxygen2
将重写导出函数的NAMESPACE指令,它不会自动重写NAMESPACE以反映我指定应在描述中导入的包。
tl;dr version of my question
If I want to import packages, do I have to manually write import()
directives into my NAMESPACE file? It seems like roxygen2 won't magically do that for me, even if I have them listed as "Imports:" in my description.
Fuller Version
This is a pretty dumb question, but I ask because the answer's not obvious to me.
I use roxygen2
to handle my R package documentation. When I want to be sure a function is exported, I add an @export
tag to its roxygen block. Subsequent runs of roxygenize()
will write the NAMESPACE directive accordingly.
But, my package currently imports several others:
Depends:
R (>= 2.13.0),
ggplot2 (>= 0.8.9)
Imports:
RColorBrewer,
plyr,
gridExtra
It appears that while roxygen2
will rewrite the NAMESPACE directive for exported functions, it won't automatically rewrite NAMESPACE to reflect packages I've designated should be imported in my DESCRIPTION.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
扩展我的评论,如果您想自动为
导入
的包/函数添加命名空间
指令,您可以通过添加@imports包
来实现> 或@importFrom package function
行添加到函数的roxygen2
文档标头。然而,正如@hadley指出的,它只会修改
NAMESPACE
,但不会影响包DESCRIPTION
Expanding on my comment, if you want to automatically add
namespace
directives for packages/functions youimport
, you can do so by adding the@imports package
or@importFrom package function
line to theroxygen2
documentation header of your function.However, as @hadley pointed out, it will only modify the
NAMESPACE
, but not affect the packageDESCRIPTION