We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Learn how to – Install R and Rstudio on Rocky Linux 9 / AlmaLinux 9

Learn how to – Install R and Rstudio on Rocky Linux 9 / AlmaLinux 9.

R is a programming language as well as a software environment for graphical representation of data and statistical computing supported by the R Foundation. This integrated suite can be used for data calculation, manipulation, and graphical display.

It has the following components:

  • An effective data handling and storage facility
  • A set of operators for calculations on arrays, in particular, matrices
  • Graphical facilities for data analysis and display either on-screen or on hardcopy.
  • A large, coherent, integrated collection of intermediate tools for data analysis

R was developed by Ross Ihaka and Robert Gentleman at the University of Auckland. The name R was derived from the first letter of the two R authors. Currently, it is widely used by developers to develop statistical and data analysis software. It is referred to as an environment rather than a programming language to characterize it as a fully planned and coherent system. It offers an environment within which statistical techniques are implemented. R can also be extended through packages provided by the R distribution and via the CRAN family.

R is preferred due to the following:

  • It is free and open-source
  • It is available for Windows, Mac, and Linux.
  • Publication-quality graphs.
  • It exceeds SAS and Stata in terms of the availability of advanced statistical methods and algorithms.

The file types associated with R include:

  • *.rmd: An R Markdown file
  • *.r: An R script
  • *.rnw: An R Sweave file.
  • *.rds: A file containing a single R object. It can be created using saveRDS() and loaded with readRDS()
  • *.rdata: contains one or more R objects/workspaces. It can be created using save() and loaded with load().

Full-time R developers, required an integrated development environment(IDE). The RStudio acts as the integrated development environment for R. It makes development efficient and productive by providing the below features:

  • Compatibility with Windows, Linux, and macOS
  • Console, syntax-highlighting editor that supports direct code execution.
  • Integrated support for Git and Subversion
  • Integrated R help and documentation
  • Extensive package development tools
  • An interactive debugger that helps troubleshoot and diagnose errors
  • Interactive graphics with Shiny and ggvis

RStudio is available in two editions i.e the open-source which is free for use and the commercial edition which is payable with advanced features.

In this guide, we will chew over how to install R and Rstudio on Rocky Linux 9 / AlmaLinux 9.

Prepare Your System

Before we begin, there are a number of packages required. Begin by updating the available system packages:

sudo dnf update

Once the update is complete, enable the EPEL and POwerTools(CRB) on Rocky Linux 9 / AlmaLinux 9.

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

#1. Install R Rocky Linux 9 / AlmaLinux 9

R can now be installed from, the Rocky Linux 9 / AlmaLinux 9 YUM repositories using the command:

sudo dnf install R

Dependency Tree:


.....
 texlive-zref                     noarch 9:20200406-25.el9      appstream 659 k
 tk                               x86_64 1:8.6.10-8.el9         appstream 1.6 M
 tk-devel                         x86_64 1:8.6.10-8.el9         appstream 483 k
 tre                              x86_64 0.8.0-34.20140228gitc2f5d13.el9
                                                                epel       42 k
 tre-common                       noarch 0.8.0-34.20140228gitc2f5d13.el9
                                                                epel       31 k
 tre-devel                        x86_64 0.8.0-34.20140228gitc2f5d13.el9
                                                                epel       12 k
 ttmkfdir                         x86_64 3.0.9-65.el9           appstream  52 k
 tzdata-java                      noarch 2022a-1.el9_0          appstream 156 k
 xorg-x11-fonts-Type1             noarch 7.5-33.el9             appstream 499 k
 xorg-x11-proto-devel             noarch 2021.4-2.el9           appstream 262 k
 xz-devel                         x86_64 5.2.5-8.el9_0          appstream  52 k
 zlib-devel                       x86_64 1.2.11-31.el9_0.1      appstream  44 k
 zziplib                          x86_64 0.13.71-9.el9          appstream  85 k
Installing weak dependencies:
 perl-CPAN-DistnameInfo           noarch 0.12-23.el9            appstream  14 k
 perl-Encode-Locale               noarch 1.05-21.el9            appstream  19 k
 perl-File-ShareDir               noarch 1.118-4.el9            appstream  30 k
 perl-List-MoreUtils              noarch 0.430-4.el9            appstream  63 k
 perl-Term-Size-Any               noarch 0.002-35.el9           appstream  13 k
 perl-TermReadKey                 x86_64 2.38-11.el9            appstream  36 k
 perl-Unicode-LineBreak           x86_64 2019.001-11.el9        appstream 120 k

Transaction Summary
================================================================================
Install  544 Packages

Total download size: 540 M
Installed size: 1.4 G
Is this ok [y/N]: y

Once the installation is complete, check the installed version.

$ R --version
R version 4.1.3 (2022-03-10) -- "One Push-Up"
Copyright (C) 2022 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/.

#2. Getting Started With R

Once installed, R can be used from the console. To launch the R console, execute the command:

sudo -i R 

Sample Output:

R version 4.1.3 (2022-03-10) -- "One Push-Up"
Copyright (C) 2022 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 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.

> 

Now you can execute the desired commands in the R console. For example, installing the stringrpackage, use the command:

install.packages("stringr") 

Select your CRAN and proceed:

35: France (Marseille) [https]
36: France (Paris 1) [https]
37: Germany (Erlangen) [https]
38: Germany (Leipzig) [https]
39: Germany (Göttingen) [https]
40: Germany (Münster) [https]
......
Selection: 37
....
trying URL 'https://ftp.fau.de/cran/src/contrib/stringi_1.7.8.tar.gz'
Content type 'application/x-gzip' length 8032287 bytes (7.7 MB)
==================================================
downloaded 7.7 MB

trying URL 'https://ftp.fau.de/cran/src/contrib/stringr_1.4.0.tar.gz'
Content type 'application/x-gzip' length 135777 bytes (132 KB)
==================================================
downloaded 132 KB
....
* DONE (stringr)
Making 'packages.html' ... done

The downloaded source packages are in
	‘/tmp/Rtmp5yLZgV/downloaded_packages’
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done

Once the installation is complete, we can use the installed package. First, load the library:

library(stringr) 

Create a simple character vector with the name test

test <- c("Klinsmann", "Installed", "R", "on", "RockyLinux", "9") 

Run a function to print the length of each string in the character vector.

str_length(test) 

Sample Output:

To exit the R console, type:

> q()
Save workspace image? [y/n/c]: y

#3. Install RStudio on Rocky Linux 9 / AlmaLinux 9

RStudio is the integrated development environment for R. It makes the whole development process easier. To install it on Rocky Linux 9 / AlmaLinux 9 you require OpenSSL 1.1.0 installed. This OpenSSL version is not provided in the Rocky Linux 9 / AlmaLinux 9 repositories. So we will compile and install it.

Install the required build tools:

sudo yum install -y make gcc perl-core pcre-devel wget zlib-devel

Proceed and download OpenSSL 1.1.0 archive:

wget https://www.openssl.org/source/openssl-1.1.0i.tar.gz

Extract the archive and navigate to the directory:

tar -zxf openssl-1.1.0i.tar.gz
cd openssl-1.1.0i

Make and install OpenSSL 1.1.0

./config
make test
make
sudo make install

The make test might with some errors but that doesn’t affect the process much if both make and make install are successful. Once complete, export the PATH:

export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64
echo "export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64" >> ~/.bashrc
source ~/.bashrc

Check the OpenSSL version:

$ openssl version
OpenSSL 1.1.0i  14 Aug 2018

Now download RStudio, by visiting the RStudio downloads page and obtaining the latest release version.

You can also obtain the file using wget as below:

wget https://download1.rstudio.org/desktop/rhel8/x86_64/rstudio-2022.07.2-576-x86_64.rpm

Now install the package with the command:

sudo yum localinstall ./rstudio-*.rpm

Dependency Tree:

Dependencies resolved.
================================================================================
 Package        Architecture  Version                 Repository           Size
================================================================================
Installing:
 rstudio        x86_64        2022.07.1+554-1         @commandline        143 M
Installing dependencies:
 libpq          x86_64        13.5-1.el9              appstream           205 k
 sqlite         x86_64        3.34.1-5.el9            appstream           748 k

Transaction Summary
================================================================================
Install  3 Packages

Total size: 144 M
Total download size: 954 k
Installed size: 579 M
Is this ok [y/N]: y

#4. Using Rstudio on Rocky Linux 9 / AlmaLinux 9

To demonstrate if the installed RStudio is working together with R as desired, launch RStudio from the App Menu.

It will start with the below window.

This shows that RStudio has connected to the available R installation and you are ready to get started. In this guide, we will create a simple project by navigating to File-> New Project

Select the project type.

Provide the project name and path. You can also check the box to use renv in your project if you need it.

Now your project will be ready. I will also demonstrate a few R Programming examples. These include:

A. Simple Arithmetics with R

For example to perform a simple arithmetic such as division, proceed as shown below.

B. Hello World Program

R can also be used to run a simple Hello Word program. The code with the below syntax can be used, with the print() function:

###To Print "Hello World!"
print("Hello World!")

### To suppress Quotes in the output
print("Hello World!", quote = FALSE)

## If there are more than 1 item, we can concatenate using paste()
print(paste("How","are","you?"))

Sample Output:

C. Take Input From User

We can also run an R code that takes input from the user and print the desired output. Below is an example code that takes the name and age of the user and prints the age with +1 year.

##Take Input
my.name <- readline(prompt="Enter name: ")
my.age <- readline(prompt="Enter age: ")

## convert character into integer
my.age <- as.integer(my.age)

##Print the Output
print(paste("Hello,", my.name, "next year you will be", my.age+1, "years old."))

Sample Output:

D. Check Prime Number

You can also use R to check if a number is a prime number or not. This also takes the input from the user and uses the provided code to check if the number is prime or not.

## take input from the user
num = as.integer(readline(prompt="Enter a number: "))
flag = 0

## prime numbers are greater than 1
if(num > 1) {
# check for factors
flag = 1
for(i in 2:(num-1)) {
if ((num %% i) == 0) {
flag = 0
break
}
}
} 
if(num == 2)    flag = 1
if(flag == 1) {
print(paste(num,"is a prime number"))
} else {
print(paste(num,"is not a prime number"))
}

Sample Output:

The end!

We have triumphantly walked through how to install R and Rstudio on Rocky Linux 9 / AlmaLinux 9. You are now set to use R for the graphical representation of data and statistical computing. I hope this was important.

Related posts:

Best Books To Master R Programming in 2022

Install R and RStudio on Ubuntu 22.04|20.04|18.04

Install R & RStudio on CentOS 8 / RHEL 8 Linux

How To Install R & RStudio on Debian 11/10

Cart

Your Cart is Empty

Back To Shop