Skip to content

Instantly share code, notes, and snippets.

@kevinrue
Created October 22, 2018 08:21
Show Gist options
  • Save kevinrue/1d3bede1ec9c23ab8e2b6d8c70ca943b to your computer and use it in GitHub Desktop.
Save kevinrue/1d3bede1ec9c23ab8e2b6d8c70ca943b to your computer and use it in GitHub Desktop.
Identify the unique list of R packages loaded by "library" or "require" statements
# The following command:
# - Parses (recursively) all files within the "R/" folder (Change as relevant).
# - Identifies all lines that include the statements "require(" or "library(".
# - Trims everything before and including "require(" or "library(", and everything after the next ")", leaving only the package name.
# - Identifies the unique list of packages loaded in those ways.
grep -Rn '.*\(require\|library\)(.*' R/* | sed 's/.*\(require\|library\)(\(.*\)).*/\2/g' | sort | uniq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment