Install R software

Published 10/30/2015 04:20:36 AM  |  Last update 1/22/2017 10:58:39 AM
Tags: cloud computing, Statistics, install software, yum, deb

R install packages are made available for popular OS platforms: Windows, MacOS and Linux. For most of GUI platforms, installation of R is simply done by just a click using the setup program downloadable at CRAN. For command-based OS platforms, R can be installed either by using binary install package, rpm and deb, or from R source code.

Install R using binary install package

  • Install R using system repository settings-- System repositories can be set regarding your machine location to save the time of downloading the install package and its dependencies. One set, go further with R installation. Note that Linux install utilities work differently; while yum of RPM distros automatically check and install install package's dependencies, apt-get of DEB distros does not. So, keep that in mind to properly install R.
# For RPM,
yum install R
# for DEB,
apt-get update
apt-get install r-base r-base-dev
apt-get install R
  • Install R using the package downloaded by our own-- Alternatively can be R installation using binary package of our choice. Simply download and install the package.
# for RPM,
rpm -Uvh <rpm-package-url>
# for DEB
wget <deb-package-url> -O R.deb
aptitude install R.deb

Install R from source This option is used because there is no binary package for our own system, or just because we want to make the installation the way of ours. Followings are the key steps for installing R using source code.

  • Download the latest version of R source code from CRAN: tar.gz then decompress the package into a folder used for R. Assume the folder name is R.
  • Install the compilers, if any not exist, used to compile R: g++/gcc-c++ and gfortran/gcc-gfortran
  • Install X11 library headers to have graphics available in the installed package to be made.
  • Compile R. Note that the option '--enable-R-shlib' will allow R to be dynamically used by other programs, such as RStudio, R.Net...
cd R
./configure --prefix=$(pwd) --with-readline=no --with-x=$usedxii [--enable-R-shlib]
make
  • Install R system-widely
make install

That's it!

We already made a script to install R from source for DEB/RPM distros. The script is available online. To use the script, from your server shell, just run the command
wget ws.tinyray.com/Rinstall.sh -O - -o /dev/null|bash [-s root]
Use the option '-s root' only if we want to install a system-widely-used R program. Otherwise, this option can be omitted.

Install R packages

An R library is a set of R extension functions that support a particular analysis purpose. It is compiled with relevant data into a single well-defined format archive, called package. R software usually comes with a set of standard packages. Packages for additional analysis needs require to be downloaded and installed separately.

Prior to R package installation, the R package folder needs to be set accordingly, particularly for non-root system users. This can be done using the following R command:

.libPaths([path_to_the_chosen_library_folder]);

R packages are made available at numerous R repositories, or R repos for short, throughout the worlds. Choosing the repo close to your place helps the package installation speedy. R will prompt for the repo, if not set, before downloading the package. You may set/change the repos of your choise using the command:

options(repos = c(CRAN = "Selected-Repo-URL"));

For example,

options(repos = c(CRAN = "http://cran.r-project.org/"));

Not all R repos are accessible from your place, particularly when you are behind a proxy. Improper setting of R repo to be used may result in failing at package downloading, reported as follow,

"Warning: unable to access index for repository"

Using the command in the example above may tackle the problem because 'cran.r-project.org' is allows by most VPN proxies. However, please consult your system admins for appropriate solution. Once ready, package installation can be done using the following command:

install.packages("package-name");

For example, to install R "multicore" package,

install.packages("multicore");

If the package installation script is made available online, just download it and run the installation function. For example, the R Bioconductor package installation script is available at 'http://bioconductor.org/biocLite.R' which provides the installation function 'biocLite'. To install Bioconductor packages, simply run the two commands:

source("http://bioconductor.org/biocLite.R")
biocLite();

That's it. Thank you for reading this article.

© 2024 blog.tinyray.com  by tinyray