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.