Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 963
briandk Avatar asked Dec 22 '11 00:12

briandk


People also ask

What is NAMESPACE file in r package?

The NAMESPACE file specifies the functions in the package that are exported to the user, and functions or packages that are imported by the package. Exported functions are functions from our package that are accessible by the user, and imported functions are functions from other packages used by our package.

What is the NAMESPACE in R?

Namespaces are the environment where all the functions of a package live. The parent environments of namespaces are the imports environments, which contain all the functions imported from other packages.

What is @export in Roxygen?

The @export line is critical. #' @export. This tells Roxygen2 to add this function to the NAMESPACE file, so that it will be accessible to users. For your first R package, you'll probably want to include @export for each of your functions.

What is description file in R?

Although mostly associated with R packages, a DESCRIPTION file can also be used to declare dependencies for a non-package project. Within such a project, devtools::install_deps() can then be used to install all the required packages. Note that, by default, use_decription() checks for a CRAN-compliant package name.


1 Answers

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

like image 133
Ramnath Avatar answered Oct 11 '22 13:10

Ramnath