Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
293 views
in Technique[技术] by (71.8m points)

r - Does roxygen2 automatically write NAMESPACE directives for "Imports:" packages?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...