Archive

gnu/linux

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

I was a fan of the package Dictionaries but is seems that it is no available and that will not be re-included. The package’s wen-page in package control is here, indicating that the package was removed.

Anyway, the package is in GitHub and it can be installed from the repository. The steps follows:

  1. Download the package as a ZIP file.
  2. Open a terminal on your Downloads-folder.
  3. Unzip the file with unzip Dictionaries-master.zip
  4. Rename the folder in a more suitable name with mv Dictionaries-master Dictionaries
  5. Move the unzipped content to you package-folder with mv Dictionaries-master ~/.config/sublime-text-3/Packages

The steps described here are also in the package’s repository (at the end).

I work with a lot of people using the suite Microsoft Office and we usually share docx document. To properly see, edit and share the content of the documents I need the official Microsoft Fonts. In ubuntu flavoured distros they can be installed with:

sudo apt-get install ttf-mscorefonts-installer

After installing the font package we need to update the shared font directories with:

sudo fc-cache -f -v

Extra: The package ttf-mscorefonts-installer is included in ubuntu-restricted-extras (sudo apt-get install ubuntu-restricted-extras)

Download last version pf the tarball from the oficial page.

Unpack the downloaded file:

cd ~/Downloads
tar xjf sublime_text_3_build_3103_x64.tar.bz2

Once unpacked we move this folder under /opt location:

sudo mv sublime_text_3 /opt/

Then, we create a symbolic link under /usr/bin to call Sublime Text from the command line as subl.

sudo ln -s /opt/sublime_text_3/sublime_text /usr/bin/subl

Finally, to add Sublime Text to the manager‘s menu we create a sublime.desktop file under /usr/share/applications:

sudo subl /usr/share/applications/sublime.desktop

And fulfill the file with this content:

[Desktop Entry]
Version=3.0
Name=Sublime Text 3
GenericName=Text Editor
Exec=sublime
Terminal=false
Icon=/opt/sublime_text_3/Icon/48x48/sublime-text.png
Type=Application
Categories=TextEditor;IDE;Development
X-Ayatana-Desktop-Shortcuts=NewWindow

[NewWindow Shortcut Group]
Name=New Window
Exec=sublime -n

I had a file containing ~1M SNPs in their rsid (and their position). I needed to complete the information with their chromosome.

Since the list is really large I use scan combined with a bash command (to know the length of the file).

I found this solution:

library("SNPlocs.Hsapiens.dbSNP.20120608")

## Create connection to big file
inputName <- "input_file.gen"
outputName <- "output_file.gen"
inputCon <- file(description = inputName, open = "r")
outputCon <- file(description = outputName, open = "w")

## We need to know the number of lines of the big file
## This will work for GNU/Linux environments
command <- paste("wc -l ", inputName, " | awk '{ print $1 }'", sep="")
nLines <- as.numeric(system(command = command, intern = TRUE))
rm(command)

## Loop over the file connection until end of lines
pb <- txtProgressBar(min = 0, max = nLines, style = 3)
for(ii in 1:nLines) {
  readLine <- scan(file = inputCon, nlines = 1, what = "list", quiet = TRUE)

  ## Get the chr from the SNP
  x <- tryCatch({
    x <- rsidsToGRanges(readLine[[2]])
    as.character(x@seqnames[1])
  }, error = function(e) {
    "---"
  })

  ## Update on list and save on output
  readLine[[1]] <- x
  writeLines(paste(readLine, collapse = " "), outputCon)

  setTxtProgressBar(pb, ii)
}

close(inputCon)
close(outputCon)

This solution is really slow but it gets the SNP’s chromosome and fills it as "---" when the SNP is not found in dbSNP.

WARNING: The SNP’s rsid must be located into the second column of the file. Take a look at readLine[[2]] in the for.


I am open to know different ways of doing this.