Miskatonic University Press

Installing R from source

r

UPDATED on 03 May 2016: See Installing R from source (updated).

I use R a lot, but the Ubuntu package repository wasn’t keeping up with current releases, so I decided (even though there was no particular need for me to do this) to install and run R from source. Here’s how I did it.

First, I removed all traces of R from the APT package system. In synaptic I marked r-base, r-base-dev, r-base-core, r-base-html and r-cran-lattice-extra for complete removal (I could have done this with sudo apt-get purge, I guess), and when they went they took a lot of other packages with them. I have a ~/R/86_64-pc-linux-gnu-library/3.1/ directory where libraries have been installed, but I let that be so I could see what packages I’d need to install.

My favourite CRAN mirror is http://cran.utstat.utoronto.ca/ so I got the source from there, then uncompressed it and compiled, then set up some symlinks. I first did that for 3.2.0, but 3.2.1 just came out so this shows how I upgraded, which is repeatable for future releases:

$ mkdir /usr/local/src/R
$ cd /usr/local/src/R
$ curl -O http://cran.utstat.utoronto.ca/src/base/R-3/R-3.2.1.tar.gz
$ tar xzvf R-3.2.1.tar.gz
$ cd R-3.2.1
$ ./configure
$ make
$ make check
$ cd ..
$ rm -f R Rscript
$ ln -s R-3.2.1/bin/R R
$ ln -s R-3.2.1/bin/Rscript Rscript
$ ls -l
lrwxrwxrwx  1 wtd wtd       13 Jun 23 20:57 R -> R-3.2.1/bin/R
drwxr-xr-x 15 wtd wtd     4096 Jun 23 20:52 R-3.2.1
-rw-r--r--  1 wtd wtd 29197870 Jun 22 12:42 R-3.2.1.tar.gz
lrwxrwxrwx  1 wtd wtd       19 Jun 23 20:58 Rscript -> R-3.2.1/bin/Rscript

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:

PATH=/usr/local/src/R:$PATH

In my .Rprofile I have this line:

options(prompt="ℝ> ")

and that’s why my prompt looks like this when I install the packages I always use (after the welcome message):

$ /usr/local/src/R/R
R version 3.2.1 (2015-06-18) -- "World-Famous Astronaut"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-unknown-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
ℝ> install.packages(c("dplyr", "readr", "ggplot2", "devtools", "lubridate", "shiny", "knitr", "ggvis"))
ℝ> devtools::install_github("rstudio/shinyapps")

And now I’m ready to go.