3

I'm developing an R package where I frequently use functions from other packages. I know it's usually best practice to be explicit about other packages in your source code (as in dplyr::filter()), but, for example, in plotting functions which are based on ggplot2 it becomes tedious and verbose to write something like ggplot2::ggplot(data, ggplot2::aes(x = ...)), and so on.

Let's say I follow the recommendations and add the @import ggplot2 tag as a roxygen comment in the respective function. Now, this adds import(ggplot2) to the NAMESPACE file, which is nice. But, it does not add ggplot2 to the Imports: section in the DESCRIPTION file, which is exactly what I would like to do. Calling roxygen2::roxygenize() does not do this either.

Note that the same question was basically asked here, but unless I missed something, the question is not answered (after all, the Imports: section is not automatically generated, only the NAMESPACE file).

I am aware of the importance of a correctly maintained NAMESPACE file, and given there are easy and convenient ways to populate it, I guess my main question is whether there is a function to automatically "translate" the NAMESPACE imports into the respective field in the DESCRIPTION. I know you can manually edit your DESCRIPTION file via usethis::use_package("ggplot2") but it seems odd to me to have to specify the same information twice, and in two completely different ways.

henhesu
  • 756
  • 4
  • 9
  • 1
    It's not possible as far as I know. However, I found this [answer](https://stackoverflow.com/questions/38738292/how-can-i-automatically-add-update-depends-imports-suggests-versions-in-descript) that may help you. – NelsonGon Jun 29 '20 at 14:25
  • 1
    I also believe it's not possible. I suspect the reason is that it is good practice to scope your calls to functions fom other packages in your source code. That way your intentions explicit and unambiguous. Relying on indirect scoping (via DESCRIPTION or other means) is not. So yes, it's (mildly) inconvenient for the package creator, but there are benefits as well: both for the wroiter and the user. – Limey Jun 29 '20 at 14:34

0 Answers0