why roxygen2 does not automatically update “Imports” in DESCRIPTION file?

风流意气都作罢 提交于 2019-12-03 09:51:07

The namespace_roclet edits the NAMESPACE file based on the tags added in the script before the function. As there are three types of dependencies (Depends, Imports, and Suggests), a similar method as used by the namespace_roclet would require three different tags (notice Imports should be a different one, to differentiate it from the packages to attach in NAMESPACE).

If you are willing to take a semi-automated process, you could identify the packages you have used and add the missing ones to DESCRIPTION, in the adequate sections.

library(reinstallr)

package.dir <- getwd()
base_path   <- normalizePath(package.dir)
files       <- list.files(file.path(base_path, "R"), full.names = TRUE)
packages    <- unique(reinstallr:::scan_for_packages(files)$package)

packages

Regarding the two bullets you wonder about at the bottom:

  • Updates to the DESCRIPTION file could be further automated with additional roclets, however already >4 years ago such a pull request was deferred: https://github.com/klutometis/roxygen/pull/76
  • I have to assume that the guys would indeed rather have you use the devtools package for updating the DESCRIPTION file, instead of adding this to roxygen2. So in that sense, devtools would be the first available choice

I have written a little R package for that task:

https://github.com/markusdumke/pkghelper

It scans the R Code and NAMESPACE for packages in use and adds them to the Imports section.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!