Steps to Install R Programming Language on Ubuntu 20.04 LTS

R is a free & open source programming language. It provides a free software environment that specializes in statistical computing, graphical representation & performing data analysis.

There are some steps to setup R programming language on Ubuntu:

Step 1: Update the System.

apt-get update

Step 2: Install the dependencies.

apt install dirmngr gnupg apt-transport-https ca-certificates software-properties-common

  • Here is the command output.

[email protected]:/home/ubuntu# apt install dirmngr gnupg apt-transport-https ca-certificates software-properties-common
Reading package lists... Done
Building dependency tree
Reading state information... Done
ca-certificates is already the newest version (20210119~20.04.2).
ca-certificates set to manually installed.
dirmngr is already the newest version (2.2.19-3ubuntu2.1).
dirmngr set to manually installed.
gnupg is already the newest version (2.2.19-3ubuntu2.1).
gnupg set to manually installed.
software-properties-common is already the newest version (0.99.9.8).
software-properties-common set to manually installed.
The following NEW packages will be installed:
apt-transport-https
0 upgraded, 1 newly installed, 0 to remove and 16 not upgraded.
Need to get 4680 B of archives.
After this operation, 162 kB of additional disk space will be used.
Do you want to continue? [Y/n] y

  • Add the CRAN repository to system sources’ list.

apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/'

  • Here is the command output.

[email protected]:/home/ubuntu# apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
Executing: /tmp/apt-key-gpghome.An7KG7mf9b/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
gpg: key 51716619E084DAB9: public key "Michael Rutter <[email protected]>" imported
gpg: Total number processed: 1
gpg: imported: 1
[email protected]:/home/ubuntu# add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/'
Hit:1 http://sa-east-1.ec2.archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://sa-east-1.ec2.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:3 http://sa-east-1.ec2.archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:4 http://security.ubuntu.com/ubuntu focal-security InRelease
Get:5 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ InRelease [3622 B]
Get:6 https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ Packages [45.6 kB]
Fetched 49.2 kB in 1s (81.0 kB/s)
Reading package lists... Done

Step 3: To Install R on system.

apt install r-base

  • Check Version.

R --version

  • Here is the command output.

[email protected]:/home/ubuntu# R --version
R version 4.1.2 (2021-11-01) -- "Bird Hippie"
Copyright (C) 2021 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 the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
https://www.gnu.org/licenses/.

Step 4: Compiling R Packages, so we need to install some package.

apt install build-essential

Step 5: To Open R console.

R

  • Here is the command output.

[email protected]:/home/ubuntu# R
R version 4.1.2 (2021-11-01) -- "Bird Hippie"
Copyright (C) 2021 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.
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.
>

  • To Install the stringr package.

>install.packages("stringr")

  • Here is the command output.

> install.packages("stringr")
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
also installing the dependencies ‘glue’, ‘magrittr’, ‘stringi’
trying URL 'https://cloud.r-project.org/src/contrib/glue_1.6.0.tar.gz'
Content type 'application/x-gzip' length 110320 bytes (107 KB)
==================================================
downloaded 107 KB
trying URL 'https://cloud.r-project.org/src/contrib/magrittr_2.0.1.tar.gz'
Content type 'application/x-gzip' length 265580 bytes (259 KB)
==================================================
downloaded 259 KB
.....
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (stringr)
The downloaded source packages are in
‘/tmp/RtmpMxeAT2/downloaded_packages’
>

  • Once installation is Done.load the library.

>library(stringr)

Step 6: To Create a simple character vector named testing.

testing <- c("How", "to", "Install", "R", "on", "Ubuntu", "20.04")

  • To prints the length of a string.

str_length(testing)

  • Here is the output.

> library(stringr)
> testing <- c("How", "to", "Install", "R", "on", "Ubuntu", "20.04")
> str_length(testing)
[1] 3 2 7 1 2 6 5

Step 7: To find more package so click on link https://cran.r-project.org/web/packages/available_packages_by_name.html

Step 8: Syntax of install the packages.

install.packages("package-name")

Leave a Reply

Your email address will not be published.