Building R from source

The following process, describing how to build R from sources, was run on a Ubuntu 16.04 Xenial Xerus.

Minimal Dependencies

The minimal dependencies to configure a standard version of a R can be installed through APT:

sudo apt-get install gfortran
sudo apt-get install build-essential

sudo apt-get install libreadline6 libreadline6-dev

sudo apt-get install xorg-dev

Java is a requirement. Under ubuntu, the package openjdk-9-jdk has a problem that can be avoided by forcing it to overwrite system files:

sudo apt-get -o Dpkg::Options::="--force-overwrite" install openjdk-9-jdk
sudo apt-get install openjdk-9-jre

Once the installation of the dependencies are done we can go for a minimal configuration.

Minimal Configuration

/.configure

Check the last section Errors if you get some exception and do not get the following result:

R is now configured for x86_64-pc-linux-gnu

Source directory:          .
Installation directory:    /usr/local

C compiler:                gcc  -g -O2
Fortran 77 compiler:       f95  -g -O2

C++ compiler:              g++  -g -O2
C++11 compiler:            g++  -std=c++11 -g -O2
Fortran 90/95 compiler:    gfortran -g -O2
Obj-C compiler:

Interfaces supported:      X11
External libraries:        readline, curl
Additional capabilities:   PNG, NLS
Options enabled:           shared BLAS, R profiling

Capabilities skipped:      JPEG, TIFF, cairo, ICU
Options not enabled:       memory profiling

Recommended packages:      yes

configure: WARNING: you cannot build info or HTML versions of the R manuals
configure: WARNING: you cannot build PDF versions of the R manuals
configure: WARNING: you cannot build PDF versions of vignettes and help pages

OPTIONAL. To remove the WARNING that makes reference to the HTML documentation, we need to install the tool texinfo:

sudo apt-get install texinfo

OPTIONAL. To remove the WARNING that makes reference to the PDF documentation, we need to install LaTeX. I propose to use texlive.

WARNING. The package texlive-full will install a lot of packages, hence it will be very time consuming.

sudo apt-get install texlive-full

Extended Configuration

The first extra step is to enable R and RStudio to talk each other. This is done by adding the modifier --enable-R-shlib. Moreover we usually want to link R with system BLAS libraries rather than use the internal versions from R.

./configure --enable-R-shlib --with-blas --with-lapack

This will result in:

R is now configured for x86_64-pc-linux-gnu

Source directory:          .
Installation directory:    /usr/local

C compiler:                gcc  -g -O2
Fortran 77 compiler:       f95  -g -O2

C++ compiler:              g++  -g -O2
C++11 compiler:            g++  -std=c++11 -g -O2
Fortran 90/95 compiler:    gfortran -g -O2
Obj-C compiler:

Interfaces supported:      X11
External libraries:        readline, curl
Additional capabilities:   PNG, NLS
Options enabled:           shared R library, shared BLAS, R profiling

Capabilities skipped:      JPEG, TIFF, cairo, ICU
Options not enabled:       memory profiling

Recommended packages:      yes

We can see that the section Options enabled includes shared R library.

Next is to allow to use external libraries like cairo or jpeglib. Before, we need to install the dependencies for them.

To allow R to use jpeglib:

sudo apt-get install libjpeg9-dev

To allow R to use cairo:

sudo apt-get install libcairo2-dev libxt-dev

Then we configure again R:

./configure --enable-R-shlib --with-blas --with-lapack --with-cairo --with-jpeglib --with-readline --enable-R-profiling --enable-memory-profiling

The line Additional capabilities has changed:

R is now configured for x86_64-pc-linux-gnu

Source directory:          .
Installation directory:    /usr/local

C compiler:                gcc  -g -O2
Fortran 77 compiler:       f95  -g -O2

C++ compiler:              g++  -g -O2
C++11 compiler:            g++  -std=c++11 -g -O2
Fortran 90/95 compiler:    gfortran -g -O2
Obj-C compiler:

Interfaces supported:      X11
External libraries:        readline, curl
Additional capabilities:   PNG, JPEG, NLS, cairo
Options enabled:           shared R library, shared BLAS, R profiling, memory profiling

Capabilities skipped:      TIFF, ICU
Options not enabled:

Recommended packages:      yes

Now, adding the argument --prefix we locate where to install the new version of R:

./configure --prefix=/home/carleshf/Software/R-3.3.3 --enable-R-shlib --with-blas --with-lapack --with-cairo --with-jpeglib --with-readline --enable-R-profiling --enable-memory-profiling

Compiling R

Once the configuration is done, R needs to be compiled. For this operation we will use the tool make.

Being in R-sources folder we run:

make

This command will generate lots of text. Take care that the following to fragments are clean of errors.

configuring Java ...
Java interpreter : /usr/bin/java
Java version     : 9-internal
Java home path   : /usr/lib/jvm/java-9-openjdk-amd64
Java compiler    : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/bin/jar

[...]

JAVA_HOME        : /usr/lib/jvm/java-9-openjdk-amd64
Java library path: $(JAVA_HOME)/lib/amd64/server
JNI cpp flags    : -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -ljvm
Updating Java configuration in /home/carleshf/Downloads/R-3.3.3
Done.

After the command, a new folder was created with R binaries:

carleshf@sky:~/Downloads/R-3.3.3$ ll
total 2624
drwxr-xr-x 15 carleshf carleshf    4096 abr  4 23:23 ./
drwxr-xr-x  3 carleshf carleshf    4096 abr  4 23:16 ../
drwxrwxr-x  3 carleshf carleshf    4096 abr  4 23:18 bin/

Optional. Once R is compiled, it can be checked using the same make command.

make check

Installing R

After the configuration process and the compilation, a single command is required to install R:

make install

Optionally, you might want to point the R command to the latest R build (in this case, R version 3.3.3).

sudo ln -s /home/carleshf/Software/R-3.3.3/bin/R /bin/R
sudo ln -s /home/carleshf/Software/R-3.3.3/bin/Rscript /bin/Rscript

Optional. Now we can check if the flags used in the configuration process were properly applied. In an R session:

R> capabilities()
jpeg         png        tiff       tcltk         X11        aqua
TRUE        TRUE       FALSE       FALSE        TRUE       FALSE
http/ftp     sockets      libxml        fifo      cledit       iconv
TRUE        TRUE        TRUE        TRUE        TRUE        TRUE
NLS     profmem       cairo         ICU long.double     libcurl
TRUE        TRUE        TRUE       FALSE        TRUE        TRUE

Errors

Configuration

The following is a list of common errors and the packages required to overcome the problem.

bzip2

checking whether bzip2 support suffices... configure: error: bzip2 library and headers are required
sudo apt-get install libbz2-dev

liblzma

configure: error: "liblzma library and headers are required"
sudo apt-get install liblzma-dev

PCRE

checking whether PCRE support suffices... configure: error: pcre >= 8.10 library and headers are required
sudo apt-get install libpcre3-dev

libcurl

configure: error: libcurl >= 7.28.0 library and headers are required with support for https
sudo apt-get install libcurl4-openssl-dev

Post Installation

XML R package

sudo apt-get install libxml2-dev

devtools R package

ERROR: dependencies ‘httr’, ‘git2r’ are not available for package ‘devtools’
* removing ‘/home/kuragari/Software/R-3.3.3/lib/R/library/devtools’
sudo apt-get install libssl-dev
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: