reconhub / recontools

Tools to develop RECON packages
GNU General Public License v3.0
1 stars 3 forks source link

Identify deps in R / Rmd / Rnw files #26

Open thibautjombart opened 6 years ago

thibautjombart commented 6 years ago

This would be useful for RECON learn, but more generally for blogdown websites and other projects where a number of packages are required without being formally declared anywhere. This is fairly generic so may exist somewhere, but the idea is:

  1. identify recursively all files containing code, i.e. extensions: R, Rmd, Rnw, Snw etc. (handling different capitalisation)

  2. in each file, identify references to R packages, including: library("foo"), require("foo"), loadNamespace("foo") (with or without quotes), foo::bar, foo:::bar, etc. and extract the library names

  3. output a list of required packages, identifying those available on CRAN

A sister function to this one would be use the output of 3. to install all available packages.

zkamvar commented 6 years ago

We could possibly use checkpoint::scanForPackages() since checkpoint is pretty lightweight

thibautjombart commented 6 years ago

sounds like a good start ;) Though from what I see it seems to overlook foo::bar cases.

dirkschumacher commented 6 years ago

Doesn't packrat also scan your package/prject? Maybe there is a good function there as well.

thibautjombart commented 6 years ago

I wouldn't be surprised, it's a fairly standard need. So long as it doesn't make us pull half of CRAN as deps, building on any existing solution beats reinventing the wheel ;)

If we want to get fancy and more recon-specific, we could add an extra feature to look for non-CRAN packages on remote/reconhub - and handle that in the install process.

thibautjombart commented 6 years ago

So this would work

install.packages(checkpoint::scanForPackages(use.knitr=TRUE)$pkgs)
zkamvar commented 6 years ago

It's worth noting that this would work only if the packages were on CRAN. Otherwise, we'll get an error.