Archive

programming

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).

Following the tradition of the last years, I’ve made a geek christmas card. This year I typed it in javascript using the improvements of HTML5.

sct

The card is a minigame where a small and blue snowman has lost his hat and you need to help him to recover it. The characteristic of the game is that the snowman moves autonomously once the user gave him a direction. The blue guy moves along the gray platforms until it bounces with the orange corners or falls outside the game. Later the user can make him jump by pressing space-bar.

Make a click on the picture to play the game.

In R there are many functions that work with a pattern written as a regular expression. Today I needed to deal with one of these functions: str_locate_all (doc) from stringr

My goal was to find "223777_at [Chip: U133B]" in a series of strings like the following one:

text <- "11753227_s_at [Chip: PrimeView]; 223777_at [Chip: HT_HG-U133B]; 223777_PM_at [Chip: U133_Plus_PM]; 48336_at [Chip: U95B]; 223777_at [Chip: GeneProfilingArray]; g13477210_3p_at [Chip: U133_X3P]; MmugDNA.4759.1.S1_at [Chip: Rhesus]; 11753227_s_at [Chip: HG-U219]; ADXECADA.19261_s_at [Chip: Xcel]; ADXECRS.13279_at [Chip: Xcel]; ADXECRS.13279_x_at [Chip: Xcel]; 223777_at [Chip: U133B]; 223777_at [Chip: U133_Plus_2]; RC_T49570_at [Chip: Hu35KsubB]"

The way to find the location (in my case all the locations) of the pattern number slash at white-space bracket Chip two-points U133B brecket follows:

str_locate_all(text, pattern="[0-9]+_at \\[Chip: U133B\\]")

This returns a list of matrix with the locations (start and end point) of all the occurrences found by the given pattern. Take care, so the brackets need to be escaped by double slash.

I love Sublime Text 3 but I’m sued to Ctrl + Shift + C to toggle comment the current line or block of lines. The default behaviour of Sublime Text for commenting is:

{ "keys": ["ctrl+/"], "command": "toggle_comment", "args": { "block": false } }
{ "keys": ["ctrl+shift+/"], "command": "toggle_comment", "args": { "block": true } }

I like it to behave like this:

{ "keys": ["ctrl+shift+c"], "command": "toggle_comment", "args": { "block": false } }

So, this lines means that the comments are done by line (not by block) and with the Ctrl + Shift + C key-binding.

A long the process of creating and testing R packages I usually need to unload a loaded package. The function to perform this operation is called detach and must be run as:

detach(name="package:rexposome", unload=TRUE)

The name argument needs to be filled with package: and followed by the name of the package to be unload, that can be found at search().