Skip to content

Instantly share code, notes, and snippets.

@philipperemy
Created October 15, 2019 13:00
Show Gist options
  • Save philipperemy/0b6e803be085bd4101e3e2d66be38be1 to your computer and use it in GitHub Desktop.
Save philipperemy/0b6e803be085bd4101e3e2d66be38be1 to your computer and use it in GitHub Desktop.
R package manager (kind of) - Find and install all dependencies of your R project.
set -e
PACKAGES="$(find . -type f -iname "*.R" -exec cat {} + | grep "^library" | sed 's/library(//g' | cut -d ')' -f 1 | sed -e 's/^"//' -e 's/"$//' | sort -u | xargs)"
for package in $PACKAGES;
do
echo "Installing package: ${package}..."
rscript -e "install.packages('${package}', repos='https://cran.rstudio.com')"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment