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?