1

Suppose I have several R scripts within a GitHub repository, and I'd like to know which packages I've used (loaded) within all of the scripts. How could I accomplish this dynamically with the stringr package? As an example, I'd like to find package names through library() calls as shown below.

library(dplyr)
library(ggplot2)
library(xml2)
library(jsonlite)

In other words, given a string library(some_package_one) and another string library(some_package_two), how could I use stringr (and perhaps rvest or similar scraping package) to determine each unique package that has been loaded from various scripts within a repo?

This would allow me to determine which packages I'd need to install before even cloning a given repository.

Take a miscellaneous repository from Hadley Wickham.

  • There are several scripts within this repository that load packages through library() calls.
  • There are different packages used in different scripts

How could I extract the package names that have been loaded by searching for all library() calls?

Dan Kalleward
  • 183
  • 1
  • 8
  • You would need to check for calls to 'require' as well. And there are other ways to load packages too. For example the p_load function from the pacman package. – Dason Mar 30 '17 at 23:16
  • The checkpoint package has a function that does this - i.e., scans a directory for all package dependencies (including packages that aren't attached to the search path (i.e., b/c the person used :: and not a call to library or require) but are nevertheless loaded. The function in checkpoint I'm talking about is called projectScanPackages. It isn't exported but you can access it using checkpoint:::projectScanPackages – Chris Mar 31 '17 at 01:26

0 Answers0