How to Install and Configure R on Rocky Linux 8 and CentOS 8

R is a fast growing open source programming language that specializes in statistical computing and graphical representation.

This programming language is supported by the R Foundation for Statistical Computing and is primarily used by statisticians and data miners to develop statistical software and perform data analysis.

This tutorial will teach you how to install R on Rocky Linux 8, CentOS 8 and AlmaLinux 8

Precondition

Make sure you meet the following prerequisites before continuing with this tutorial:

  • Your system has at least 1G RAM. Otherwise, you can create a swap file.
  • You are logged in as a user with sudo privileges.

Install R on Rocky Linux 8 and CentOS 8

The R packages are not included in the Rocky Linux 8 and CentOS 8 core repository. We will install R from the EPEL repository :

To install R on Rocky Linux 8 or CentOS 8, follow these steps:

1) Enable EPEL and PowerTools repositories:

sudo dnf install epel-release 
sudo dnf config-manager --set-enabled PowerTools

2) Install R by typing:

sudo yum install R 

R is a meta-package that contains all the required R components.

3) Verify the installation by printing the R version:

R --version 

At the time of writing, the latest stable version of R is version 3.6.2:

R version 3.6.2 (2019-12-12) -- "Dark and Stormy Night" 
Copyright (C) 2019 The R Foundation for Statistical Computing 
Platform: x86_64-redhat-linux-gnu (64-bit) 

R is free software and comes with ABSOLUTELY NO WARRANTY. 
You are welcome to redistribute it under the terms of the GNU General Public License versions 2 or 3. 
For more information about these matters, see 
https://www.gnu.org/licenses/.

4) Install the libraries and tools used by the R package:

sudo yum install make gcc gcc-c++ libcurl-devel libxml2-devel openssl-devel texlive-*

At this point, you have successfully installed your Rocky Linux 8 and CentOS R system and can start using it.

Install Package R from CRAN

One of the main reasons why R is so popular is the variety of packages available through the Comprehensive R Archive Network (CRAN).

For demonstration purposes, we will install a package named stringr, which provides a fast and correct implementation of general string manipulation.

When started as root, the packages will be installed globally and available to all users of the system. If you start R without sudo, a private library will be set up for your users.

Start by opening the R console as root:

sudo -i R 
R version 3.6.3 (2020-02-29) -- "Holding the Windsock"
Copyright (C) 2020 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.

> 
 

All of the following commands are executed in the R console.

Install package stringrby running the following command:

install.packages("stringr") 

You will be asked to select a CRAN mirror link:

Installing package into ‘/usr/lib64/R/library’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
Secure CRAN mirrors 
 

Select the mirror closest to your location.

The installation will take some time and once done, load the library by typing:

library(stringr) 

Next, create a simple character vector named tutorial:

tutorial <- c("Cara", "Install", "R", "di", "CentOS", "8") 

Run the following function which will print the length of each string:

str_length(tutorial) 
[1] 4 7 1 2 6 1 

You can find more R packages in Available Packages CRAN By Name and install them with install.packages().

Conclusion

You have successfully installed your Rocky Linux 8 and CentOS 8 machine and learned how to install R packages.

Be the first to comment

Leave a Reply

Your email address will not be published.


*