Does roxygen2 automatically write NAMESPACE directives for “Imports:” packages?

江枫思渺然 提交于 2019-12-28 05:16:30

问题


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.


回答1:


Expanding on my comment, if you want to automatically add namespace directives for packages/functions you import, you can do so by adding the @imports package or @importFrom package function line to the roxygen2 documentation header of your function.

However, as @hadley pointed out, it will only modify the NAMESPACE, but not affect the package DESCRIPTION



来源:https://stackoverflow.com/questions/8597993/does-roxygen2-automatically-write-namespace-directives-for-imports-packages

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!