This article explains how to install and configure R in RHEL 8 / CentOS 8.

In this tutorial you will learn:

  • R Overview
  • Statistical Features of R
  • Download, Compilation, Installation of R
  • Hello World with R
R Features
R Features.

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System RHEL 8 / CentOS 8
Software R
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

R Overview

R is a programming language and free software environment for statistical computing and graphics supported by the R Foundation for Statistical Computing. The R language is widely used among statisticians and data miners for developing statistical software and data analysis. Polls, data mining surveys, and studies of scholarly literature databases show substantial increases in popularity in recent years as of February 2019, R ranks 15th in the TIOBE index, a measure of popularity of programming languages.

A GNU package, source code for the R software environment is written primarily in C, Fortran and R itself, and is freely available under the GNU General Public License. Pre-compiled binary versions are provided for various operating systems. Although R has a command line interface, there are several graphical user interfaces, such as RStudio, an integrated development environment.

Statistical Features of R

R and its libraries implement a wide variety of statistical and graphical techniques, including linear and nonlinear modelling, classical statistical tests, time-series analysis, classification, clustering, and others. R is easily extensible through functions and extensions, and the R community is noted for its active contributions in terms of packages. Many of R's standard functions are written in R itself, which makes it easy for users to follow the algorithmic choices made. For computationally intensive tasks, C, C++, and Fortran code can be linked and called at run time. Advanced users can write C, C++, Java, .NET or Python code to manipulate R objects directly. R is highly extensible through the use of user-submitted packages for specific functions or specific areas of study. Due to its S heritage, R has stronger object-oriented programming facilities than most statistical computing languages. Extending R is also eased by its lexical scoping rules.

SUBSCRIBE TO NEWSLETTER
Subscribe to Linux Career NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


Another strength of R is static graphics, which can produce publication-quality graphs, including mathematical symbols. Dynamic and interactive graphics are available through additional packages.

R has Rd, its own LaTeX-like documentation format, which is used to supply comprehensive documentation, both online in a number of formats and in hard copy.

Download, Compilation, Installation of R

Sources, binaries and documentation for R can be obtained via CRAN, the “Comprehensive R Archive Network”. Open the link https://cran.r-project.org/mirrors.html and select any of the mirror to download R. Here we have used the mirror from University of California, Berkeley i.e https://cran.cnr.berkeley.edu/ to download R. Once downloaded the R-3.5.2.tar.gz (The latest release (2018-12-20, Eggshell Igloo) file extract it and change the permission to root user.
# tar -xzvf R-3.5.2.tar.gz
# ls -lrth
total 29M
drwxr-xr-x. 10  501 games 4.0K Dec 20 12:04 R-3.5.2
-rw-------.  1 root root  1.2K Feb  3 22:58 anaconda-ks.cfg
# chown -R root:root R-3.5.2/
# ls -lrth
total 29M
drwxr-xr-x. 10 root root 4.0K Dec 20 12:04 R-3.5.2
-rw-------.  1 root root 1.2K Feb  3 22:58 anaconda-ks.cfg
Before compiling the R from downloaded package you need to install the following packages with the commands below
# yum group install "Development tools"
# yum install readline-devel
# yum install xz xz-devel 
# yum install pcre pcre-devel
# yum install libcurl-devel
# yum install texlive
# yum install java-1.8.0-openjdk
# yum install *gfortran*
# yum install zlib*
# yum install bzip2-*
Now, change to the extracted directory and issue the following commands.
#./configure –with-x=no
After successful configure command you will get below message
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

  Default C++ compiler:      g++   -g -O2
  C++98 compiler:            g++ -std=gnu++98 -g -O2
  C++11 compiler:            g++ -std=gnu++11 -g -O2
  C++14 compiler:            g++ -std=gnu++14 -g -O2
  C++17 compiler:            g++ -std=gnu++17 -g -O2
  Fortran 90/95 compiler:    gfortran -g -O2
  Obj-C compiler:	      

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

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

  Recommended packages:      yes
Now run below commands from the same extracted R directory.


# make
If these commands execute successfully, the R binary and a shell script front-end called R are created and copied to the bin directory. You can copy the script to a place where users can invoke it, for example to /usr/local/bin. In addition, plain text help pages as well as HTML and LaTeX versions of the documentation are built. Finally, use make check to find out whether your R system works correctly.
# make check
make[1]: Entering directory '/root/R-3.5.2/tests'
make[2]: Entering directory '/root/R-3.5.2/tests'
make[3]: Entering directory '/root/R-3.5.2/tests/Examples'
Testing examples for package ‘base’
Testing examples for package ‘tools’
  comparing ‘tools-Ex.Rout’ to ‘tools-Ex.Rout.save’ ... OK
Testing examples for package ‘utils’
Testing examples for package ‘grDevices’
  comparing ‘grDevices-Ex.Rout’ to ‘grDevices-Ex.Rout.save’ ... OK
Testing examples for package ‘graphics’
  comparing ‘graphics-Ex.Rout’ to ‘graphics-Ex.Rout.save’ ... OK
Testing examples for package ‘stats’
  comparing ‘stats-Ex.Rout’ to ‘stats-Ex.Rout.save’ ... OK
Testing examples for package ‘datasets’
  comparing ‘datasets-Ex.Rout’ to ‘datasets-Ex.Rout.save’ ... OK
Testing examples for package ‘methods’
Testing examples for package ‘grid’
  comparing ‘grid-Ex.Rout’ to ‘grid-Ex.Rout.save’ ... OK
Testing examples for package ‘splines’
  comparing ‘splines-Ex.Rout’ to ‘splines-Ex.Rout.save’ ... OK
Testing examples for package ‘stats4’
  comparing ‘stats4-Ex.Rout’ to ‘stats4-Ex.Rout.save’ ... OK
Testing examples for package ‘tcltk’
Testing examples for package ‘compiler’
Testing examples for package ‘parallel’
make[3]: Leaving directory '/root/R-3.5.2/tests/Examples'
make[2]: Leaving directory '/root/R-3.5.2/tests'
make[2]: Entering directory '/root/R-3.5.2/tests'
running strict specific tests
make[3]: Entering directory '/root/R-3.5.2/tests'
running code in 'eval-etc.R' ... OK
  comparing 'eval-etc.Rout' to './eval-etc.Rout.save' ... OK
running code in 'simple-true.R' ... OK
  comparing 'simple-true.Rout' to './simple-true.Rout.save' ... OK
running code in 'arith-true.R' ... OK
  comparing 'arith-true.Rout' to './arith-true.Rout.save' ... OK
running code in 'arith.R' ... OK
  comparing 'arith.Rout' to './arith.Rout.save' ... OK
running code in 'lm-tests.R' ... OK
  comparing 'lm-tests.Rout' to './lm-tests.Rout.save' ... OK
running code in 'ok-errors.R' ... OK
  comparing 'ok-errors.Rout' to './ok-errors.Rout.save' ... OK
running code in 'method-dispatch.R' ... OK
  comparing 'method-dispatch.Rout' to './method-dispatch.Rout.save' ... OK
running code in 'any-all.R' ... OK
  comparing 'any-all.Rout' to './any-all.Rout.save' ... OK
running code in 'd-p-q-r-tests.R' ... OK
  comparing 'd-p-q-r-tests.Rout' to './d-p-q-r-tests.Rout.save' ... OK
make[3]: Leaving directory '/root/R-3.5.2/tests'
running sloppy specific tests
make[3]: Entering directory '/root/R-3.5.2/tests'
running code in 'complex.R' ... OK
  comparing 'complex.Rout' to './complex.Rout.save' ... OK
running code in 'eval-etc-2.R' ... OK
  comparing 'eval-etc-2.Rout' to './eval-etc-2.Rout.save' ... OK
running code in 'print-tests.R' ... OK
  comparing 'print-tests.Rout' to './print-tests.Rout.save' ... OK
running code in 'lapack.R' ... OK
  comparing 'lapack.Rout' to './lapack.Rout.save' ... OK
running code in 'datasets.R' ... OK
  comparing 'datasets.Rout' to './datasets.Rout.save' ... OK
running code in 'datetime.R' ... OK
  comparing 'datetime.Rout' to './datetime.Rout.save' ... OK
running code in 'iec60559.R' ... OK
  comparing 'iec60559.Rout' to './iec60559.Rout.save' ... OK
make[3]: Leaving directory '/root/R-3.5.2/tests'
make[3]: Entering directory '/root/R-3.5.2/tests'
checking Sys.timezone ...
make[4]: Entering directory '/root/R-3.5.2/tests'
running code in 'timezone.R' ... OK
make[4]: Leaving directory '/root/R-3.5.2/tests'
make[3]: Leaving directory '/root/R-3.5.2/tests'
make[2]: Leaving directory '/root/R-3.5.2/tests'
make[2]: Entering directory '/root/R-3.5.2/tests'
running regression tests ...
make[3]: Entering directory '/root/R-3.5.2/tests'
running code in 'array-subset.R' ... OK
running code in 'reg-tests-1a.R' ... OK
running code in 'reg-tests-1b.R' ... OK
running code in 'reg-tests-1c.R' ... OK
running code in 'reg-tests-1d.R' ... OK
running code in 'reg-tests-2.R' ... OK
  comparing 'reg-tests-2.Rout' to './reg-tests-2.Rout.save' ... OK
running code in 'reg-examples1.R' ... OK
running code in 'reg-examples2.R' ... OK
running code in 'reg-packages.R' ... OK
running code in 'p-qbeta-strict-tst.R' ... OK
running code in 'r-strict-tst.R' ... OK
running code in 'reg-IO.R' ... OK
  comparing 'reg-IO.Rout' to './reg-IO.Rout.save' ... OK
running code in 'reg-IO2.R' ... OK
  comparing 'reg-IO2.Rout' to './reg-IO2.Rout.save' ... OK
running code in 'reg-plot.R' ... OK
  comparing 'reg-plot.pdf' to './reg-plot.pdf.save' ... OK
running code in 'reg-S4-examples.R' ... OK
running code in 'reg-BLAS.R' ... OK
make[3]: Leaving directory '/root/R-3.5.2/tests'
make[3]: Entering directory '/root/R-3.5.2/tests'
running code in 'reg-tests-3.R' ... OK
  comparing 'reg-tests-3.Rout' to './reg-tests-3.Rout.save' ... OK
running code in 'reg-examples3.R' ... OK
  comparing 'reg-examples3.Rout' to './reg-examples3.Rout.save' ... OK
running tests of plotting Latin-1
  expect failure or some differences if not in a Latin-1 or UTF-8 locale
running code in 'reg-plot-latin1.R' ... OK
  comparing 'reg-plot-latin1.pdf' to './reg-plot-latin1.pdf.save' ... OK
running code in 'reg-S4.R' ... OK
  comparing 'reg-S4.Rout' to './reg-S4.Rout.save' ... OK
make[3]: Leaving directory '/root/R-3.5.2/tests'
make[2]: Leaving directory '/root/R-3.5.2/tests'
make[2]: Entering directory '/root/R-3.5.2/tests'
running tests of Internet functions
make[3]: Entering directory '/root/R-3.5.2/tests'
running code in 'internet.R' ... OK
  comparing 'internet.Rout' to './internet.Rout.save' ... OK
make[3]: Leaving directory '/root/R-3.5.2/tests'
make[2]: Leaving directory '/root/R-3.5.2/tests'
make[1]: Leaving directory '/root/R-3.5.2/tests'
To perform a “system-wide” installation use make install.
# make install
By default, this will install to the following directories: ${prefix}/bin - the front-end shell script ${prefix}/man/man1 - the man page ${prefix}/lib/R - all the rest (libraries, on-line help system, …). This is the “R Home Directory” (R_HOME) of the installed system.

In the above, prefix is determined during configuration (typically /usr/local) and can be set by running configure with the option.

#./configure --prefix=/where/you/want/R/to/go
(E.g., the R executable will then be installed into /where/you/want/R/to/go/bin.)

Upon successful installation, the R can be invoked by the following command.



# R
R version 3.5.2 (2018-12-20) -- "Eggshell Igloo"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

Hello World with R

To check the R whether it has properly functioning, lets create a simple Hello World R Program to verify. Create a new R code by using vim and save with the *.R extension.

hello <- function( name ) {

    sprintf( "Hello, %s", name );

}
The R script is executed using source command. Go to the command prompt in the R console, and write the following command to execute the script.
> source("/root/helloworld.R")

> hello("LinuxConfig.org")
[1] "Hello, LinuxConfig.org"
>

Conclusion

R is free and open-source, making it possible for anyone to have access to world-class statistical analysis tools. It is used widely in academia and the private sector and is the most popular statistical analysis programming language today. Learning R isn’t easy — if it was, data scientists wouldn’tbe in such high demand. However, there is no shortage of quality resources you can use to learn R if you’re willing to put in the time and effort.
ARE YOU LOOKING FOR A LINUX JOB?
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed on LinuxCareers.com.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.