Skip to content

Instantly share code, notes, and snippets.

@rhshah
Forked from pachadotdev/r_python_homebrew.sh
Created January 29, 2018 20:15
Show Gist options
  • Save rhshah/9c879728f0e81929f8e93b67c243d01e to your computer and use it in GitHub Desktop.
Save rhshah/9c879728f0e81929f8e93b67c243d01e to your computer and use it in GitHub Desktop.
Install R and Python via Homebrew
# See http://pacha.hk/2017-07-12_r_and_python_via_homebrew.html
# XCode CLT
xcode-select --install
# Update Homebrew and add formulae
brew update
# Check for broken dependencies and/or outdated packages
brew doctor
brew prune
# Brew PATH
echo "export LC_ALL=en_US.UTF-8" >> ~/.bash_profile
echo "export LANG=en_US.UTF-8" >> ~/.bash_profile
echo "export PATH=/usr/local/bin:$PATH" >> ~/.bash_profile && source ~/.bash_profile
# Python
brew install python
pip install pelican==3.6.3
pip install markdown rpy2
# R
brew tap homebrew/science
brew install openblas
brew install r --with-openblas
echo 'Sys.setlocale(category="LC_ALL", locale = "en_US.UTF-8")' >> ~/.bash_profile
# data.table with enabled OpenMP
brew install llvm
echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.bash_profile
mkdir ~/.R
echo "CC=/usr/local/opt/llvm/bin/clang -fopenmp
CXX=/usr/local/opt/llvm/bin/clang++
# -O3 should be faster than -O2 (default) level optimisation ..
CFLAGS=-g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe
CXXFLAGS=-g -O3 -Wall -pedantic -std=c++11 -mtune=native -pipe
LDFLAGS=-L/usr/local/opt/gettext/lib -L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib
CPPFLAGS=-I/usr/local/opt/gettext/include -I/usr/local/opt/llvm/include" >> ~/.R/Makevars
R --vanilla << EOF
install.packages('data.table', repos='http://cran.us.r-project.org')
q()
EOF
rm ~/.R/Makevars
echo "CC=/usr/local/opt/llvm/bin/clang
CXX=/usr/local/opt/llvm/bin/clang++
# -O3 should be faster than -O2 (default) level optimisation ..
CFLAGS=-g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe
CXXFLAGS=-g -O3 -Wall -pedantic -std=c++11 -mtune=native -pipe
LDFLAGS=-L/usr/local/opt/gettext/lib -L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib
CPPFLAGS=-I/usr/local/opt/gettext/include -I/usr/local/opt/llvm/include" >> ~/.R/Makevars
# knitr
R --vanilla << EOF
install.packages('knitr', repos='http://cran.us.r-project.org')
q()
EOF
# rmarkdown
R --vanilla << EOF
install.packages('rmarkdown', repos='http://cran.us.r-project.org')
q()
EOF
# rJava
brew cask install java
sudo ln -f -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib
sudo Rscript -e 'install.packages("rJava", repos="http://rforge.net", type="source")';
# devtools
brew install openssl openssl@1.1 libssh2
sudo Rscript -e 'install.packages("devtools")';
# tidyverse tools
sudo Rscript -e 'install.packages(c("dplyr","tidyr","ggplot2","haven"))';
# pdf extraction tools
brew install poppler
sudo Rscript -e 'install.packages("pdftools")';
sudo Rscript -e 'library(devtools); install_github("ropensci/tabulizer")';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment