Open thibautjombart opened 6 years ago
We could possibly use checkpoint::scanForPackages()
since checkpoint is pretty lightweight
sounds like a good start ;)
Though from what I see it seems to overlook foo::bar
cases.
Doesn't packrat
also scan your package/prject? Maybe there is a good function there as well.
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.
So this would work
install.packages(checkpoint::scanForPackages(use.knitr=TRUE)$pkgs)
It's worth noting that this would work only if the packages were on CRAN. Otherwise, we'll get an error.
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:
identify recursively all files containing code, i.e. extensions:
R
,Rmd
,Rnw
,Snw
etc. (handling different capitalisation)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 namesoutput 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.