How to compile R in a specific location
Issue
Recently I noticed that the Bioconductor installed in our Debian server was two versions out of date, but I use the Institutes’s server for which I am not an administrator so I decided to install the newer version of R
and upgrade the packages.
Save installed packages
Firstly I saved the list of packages previously installed so that these could be easily re-installed:
<- function(out_file){
saveInstalledPkgs <- rownames(installed.packages())
pkgs save(pkgs, file=out_file)
}<- getRversion()
version saveInstalledPkgs(
paste(
"~/imb-kettinggr/common_bin/R/installed_packages_",
version,'.Rdata',
sep='')
)
Compile R from source
The goal is to install it in a shared folder so that:
- members of our group - biologists with little knowledge of the command line -get access that to the same R installation with which they can replicate my analysis.
- package versions are the ones needed for our group’s analysis without polluting the system-wide installation.
Ultimately without sudo
powers R needs to be installed from source and since there is no good equivalent to the excellent python virtual env
it can be an involved process. This bit of could should have been all that was needed:
BIN=/fsimb/groups/imb-kettinggr/common_bin/
cd ${BIN}
wget http://cran.rstudio.com/src/base/R-3/R-3.3.2.tar.gz
tar xvf R-3.3.2.tar.gz
cd R-3.3.2
./configure --prefix=/home/adomingu/imb-kettinggr/common_bin/R/R-3.3.2 --enable-R-shlib
make && make install
and it as indeed worked in the past for an older version of R. However, for R version 3.3.2
make && install
threw an error in my general direction:
checking if libcurl is version 7 and >= 7.28.0… no configure: error: libcurl >= 7.28.0 library and headers are required with support for https
Which sucks.
[everytime a tool needs to be compiled I die a little inside]
Compile curl
So I needed to compile the curl
as well. Following this tutorial, #11:
BIN=/fsimb/groups/imb-kettinggr/common_bin
cd $BIN
wget --no-check-certificate https://curl.haxx.se/download/curl-7.51.0.tar.gz &&
tar xzvf curl-7.51.0.tar.gz &&
cd curl-7.51.0 &&
./configure --prefix=$BIN/curl &&
make -j3 &&
make install
# make R (or better gcc) aware of the new libcurl (first two for building, the last two for the ./configure step)
LIBCURL_LOCAL_DIR="$BIN/curl"
export PATH=$LIBCURL_LOCAL_DIR/bin:$PATH
export LD_LIBRARY_PATH=$LIBCURL_LOCAL_DIR/lib:$LD_LIBRARY_PATH
export LIBCURL_CFLAGS=-I$LIBCURL_LOCAL_DIR/include
export LIBCURL_LIBS=-L$LIBCURL_LOCAL_DIR/lib
cd $BIN/
tar xvf R-3.3.2.tar.gz
mv R-3.3.2/ R/
cd $BIN/R/R-3.3.2
## configure R for usage in dependency tree (adjust if needed)
./configure --prefix=/fsimb/groups/imb-kettinggr/common_bin/R/R-3.3.2 --with-x --with-blas --with-lapack --with-cairo --enable-static --enable-R-static-lib --enable-R-shlib --with-libpng --with-jpeglib --with-libtiff --with-ICU --with-tcl-config=/usr/lib/tclConfig.sh --with-tk-config=/usr/lib/tkConfig.sh --with-tcltk &&
make && make install
cd ..
chmod -R ug+rw R-3.3.2
As it is easy to see there were a lot options needed for the compiling to work, but it did work in the end.
Install libraries
Install libraries in a specific folder, instructions. Remember that for each R version there will be a correspondent libraries folder:
TOOL_DEPENDENCIES="/fsimb/groups/imb-kettinggr/common_bin"
mkdir ${TOOL_DEPENDENCIES}/R/R-3.3.2_LIBS
export PATH=${TOOL_DEPENDENCIES}/R/R-3.3.2/bin:$PATH
export R_LIBS=${TOOL_DEPENDENCIES}/R-R/3.3.2_LIBS
This lines were also added to the .bashrc
:
## without the folowing line R will not be able to connect to the internet - custom installation
export PATH=/fsimb/groups/imb-kettinggr/common_bin/curl/bin:$PATH
export LD_LIBRARY_PATH=/fsimb/groups/imb-kettinggr/common_bin/curl/lib:$LD_LIBRARY_PATH
export R_LIBS=/fsimb/groups/imb-kettinggr/common_bin/R/R-3.3.2_LIBS
Then from ${TOOL_DEPENDENCIES}/R/R-3.3.2/bin/R
to install libraries:
## old
#.libPaths()
#[1] "/fsimb/groups/imb-kettinggr/common_bin/R/R-3.2.2_LIBS"
#[2] "/fsimb/groups/imb-kettinggr/common_bin/R/R-3.3.2/lib64/R/library"
="/fsimb/groups/imb-kettinggr/common_bin/R/R-3.3.2_LIBS"
shared_libs.libPaths(shared_libs)
shared_libs# http://stackoverflow.com/a/4090208/1274242
load('~/imb-kettinggr/common_bin/R/installed_packages_3.3.2.Rdata')
<- pkgs[!(pkgs %in% installed.packages()[,"Package"])]
new_pkgs if(length(new_pkgs) > 0) { install.packages(new_pkgs)}
<- pkgs[!(pkgs %in% installed.packages()[,"Package"])]
new_pkgs source("http://bioconductor.org/biocLite.R")
biocLite(new_pkgs)
source("http://bioconductor.org/workflows.R")
workflowInstall("rnaseqGene")
::install_github("genomicsclass/ERBS") devtools
Confer access to other users with chmod -R ug+rw /fsimb/groups/imb-kettinggr/common_bin
.
Bioconductor
Bioconductor packages can also be installed like the above, but through biocLite:
="/fsimb/groups/imb-kettinggr/common_bin/R/R-3.3.2_LIBS"
shared_libssource("http://bioconductor.org/biocLite.R")
biocLite("Gviz", lib=shared_libs)
library(Gviz)
There were some issues installing a package dependency, ggally
, solved with:
library(devtools)
install_github("ggobi/ggally")
And changing the library path is also helpful:
="/fsimb/groups/imb-kettinggr/common_bin/R/R-3.3.2_LIBS"
shared_libs.libPaths(c(.libPaths(), shared_libs))
I hope this helps someone else in my situation.
Reuse
Citation
@online{domingues2017,
author = {Domingues, António},
title = {How to Compile {R} in a Specific Location},
date = {2017-09-03},
url = {https://amjdomingues.com/posts/2017-09-03-compile-r/},
langid = {en}
}