Miskatonic University Press

Installing R from source (updated)


Last year I wrote up how I install R from source. I’ve refined it a bit so it’s easier to copy and paste, and here it is, suitable for use with the fresh release of R 3.3.0.

cd /usr/local/src/R
curl -O http://cran.utstat.utoronto.ca/src/base/R-3/R-$VERSION.tar.gz
tar xzvf R-$VERSION.tar.gz
make && make check
cd ..
rm R Rscript
ln -s R-$VERSION/bin/R R
ln -s R-$VERSION/bin/Rscript Rscript
PACKAGE_LIST="dplyr readr ggplot2 devtools lubridate shiny knitr ggvis seriation igraph arules arulesViz tm wordcloud cluster fpc topicmodels"
for PKG in $PACKAGE_LIST; do ./Rscript --vanilla -e "install.packages('$PKG', repos=c('https://cran.hafro.is/'))"; done
./Rscript --vanilla -e "devtools::install_github('rstudio/shinyapps')"

When 3.3.1 comes out, just change VERSION, rerun, and there you go. There’s nothing to catch errors, but I’m pretty sure everything will always work, and if there’s some horrible accident and it doesn’t, the previous version of R is still there and it’s just a matter of changing symlinks.

The aim of the symlinks is to always be able to refer to /usr/local/src/R/R and /usr/local/src/R/Rscript in a stable way, so this addition to my $PATH in .bashrc always works:


If you have that set, and you can write to /usr/local/src/, then you can paste in those shell commands and it should all just work (assuming you’ve already installed the necessary packages for building from source generally, and topicmodels requires the GNU Scientific Library).

I was talking to someone the other day who uses Ansible and explained how he uses it for keeping all his machines in sync and set up the way he likes. It looks very powerful, but right now it’s not for me. I’ll keep the block above in an Org file and copy and paste as needed, and I’ll do something similar with other packages. I could even run them remotely from Org.