Does Roxygen2 Automatically Write Namespace Directives for "Imports:" Packages

Does roxygen2 automatically write NAMESPACE directives for Imports: packages?

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

R: roxygen2, imported packages do not appear in namespace

If your file only contains the lines that you provided, it is ignored by roxygen2. You should add a line after the roxygen code that contains just NULL. So the following should work:

#' @import reshape2 ggplot2 DESeq2 geneplotter
#' @import survcomp gplots pheatmap RColorBrewer
NULL

I have also reduced the number of lines to show you, how several packages can be imported with a single use of @import. But it does not matter for roxygen, on how many lines you distribute the packages.

I think the reason for this is that the roxygen sections must be associated with some R object. For example, the documentation of a function is associated with the corresponding function object. Since you don't want to have the imports associated with a function, you can associate them with NULL, which is an R object as well.

As hadley rightly points out, it is not recommended to fully import that many packages because you might end up with name conflicts. The following two alternatives are usually better:

  • Reference function with their explicit package name and the :: operator: reshape2::melt() This has the added advantage that you immediately see, from which package a function comes.

  • Import only the functions that you need from a package using @importFrom:

    #' @importFrom reshape2 melt cast

You can find more information here.



Related Topics



Leave a reply



Submit