How to Install R in Ubuntu
To Install R in Ubuntu
R is an open source programming language that used for statistical computing and graphics. It is widely used by statisticians and data miners for data analysis or developing statistical software. This article explains the installation process of R in Ubuntu.
Installation of R
Run the following command to update the apt source list.
root@linuxhelp1:~# apt-get update
Hit:1 http://in.archive.ubuntu.com/ubuntu xenial InRelease
Hit:2 http://security.ubuntu.com/ubuntu xenial-security InRelease
Hit:3 http://in.archive.ubuntu.com/ubuntu xenial-updates InRelease
Hit:4 http://in.archive.ubuntu.com/ubuntu xenial-backports InRelease
Reading package lists... Done
Once the update process is completed , you need to add R into the Ubuntu key.
root@linuxhelp1:~# gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9 gpg: keyring `/home/user1/.gnupg/secring.gpg' created gpg: keyring `/home/user1/.gnupg/pubring.gpg' created gpg: requesting key E084DAB9 from hkp server keyserver.ubuntu.com gpg: /home/user1/.gnupg/trustdb.gpg: trustdb created gpg: key E084DAB9: public key " Michael Rutter < marutter@gmail.com> " imported gpg: Total number processed: 1 gpg: imported: 1 (RSA: 1) root@linuxhelp1:~# gpg -a --export E084DAB9 | sudo apt-key add - OK
Then add the R repository to the /etc/apt/sources.list file.
root@linuxhelp1:~# echo " deb http://cran.rstudio.com/bin/linux/ubuntu xenial/" | tee -a /etc/apt/sources.list
deb http://cran.rstudio.com/bin/linux/ubuntu xenial/
Also update the package list by using the following command.
root@linuxhelp1:~# apt-get update
Hit:1 http://in.archive.ubuntu.com/ubuntu xenial InRelease
Hit:2 http://security.ubuntu.com/ubuntu xenial-security InRelease
Get:3 http://cran.rstudio.com/bin/linux/ubuntu xenial/ InRelease [3,590 B]
Get:4 http://in.archive.ubuntu.com/ubuntu xenial-updates InRelease [95.7 kB]
Get:5 http://cran.rstudio.com/bin/linux/ubuntu xenial/ Packages [36.2 kB]
Get:6 http://in.archive.ubuntu.com/ubuntu xenial-backports InRelease [92.2 kB]
Fetched 228 kB in 4s (54.1 kB/s)
Reading package lists... Done
Utilize the following command to install the R language.
root@linuxhelp1:~# apt-get install r-base r-base-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
autoconf automake autotools-dev binutils bzip2-doc cdbs cpp-5 debhelper dh-strip-nondeterminism dh-translations g++-5
gcc-5 gcc-5-base gfortran gfortran-5 icu-devtools intltool libasan2 libatomic1 libblas-common libblas-dev libblas3
libbz2-dev libcc1-0 libcilkrts5 libfile-stripnondeterminism-perl libgcc-5-dev libgfortran-5-dev libgfortran3 libgomp1
libicu-dev libitm1 libjpeg-dev libjpeg-turbo8-dev libjpeg8-dev liblapack-dev liblapack3 liblsan0 liblzma-dev
libmail-sendmail-perl libmpx0 libncurses5-dev libpcre3-dev libpcre32-3 libpcrecpp0v5 libpng12-dev libquadmath0
libreadline-dev libreadline6-dev libsigsegv2 libstdc++-5-dev libstdc++6 libsys-hostname-long-perl libtinfo-dev
.
.
.
Setting up r-base-dev (3.3.2-1xenial0) ...
Processing triggers for libc-bin (2.23-0ubuntu3) ...
If installation take few minutes then check the connection speed.
Once the installation is completed, start writing code in R.
root@linuxhelp1:~# R
R version 3.3.2 (2016-10-31) -- " Sincere Pumpkin Patch"
Copyright (C) 2016 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.
>
Install the additional R packages with the following command.
> install.packages(' txtplot' ) Installing package into ‘ /usr/local/lib/R/site-library’ (as ‘ lib’ is unspecified) --- Please select a CRAN mirror for use in this session ---trying URL ' https://ftp.iitm.ac.in/cran/src/contrib/txtplot_1.0-3.tar.gz' Content type ' application/x-gzip' length 6152 bytes ================================================== downloaded 6152 bytes * installing *source* package ‘ txtplot’ ... ** package ‘ txtplot’ successfully unpacked and MD5 sums checked ** R ** preparing package for lazy loading ** help *** installing help indices ** building package indices ** testing if installed package can be loaded * DONE (txtplot)
In the above process, select India (https) to set time zone.
The downloaded source packages are in the following location.
‘ /tmp/Rtmp5kF0jR/downloaded_packages’
>
After installed the add-on, use the following command to load the library.
> library(' txtplot' )
>
Once the package is loaded, test the library with sample as follows,
> txtplot(cars[,1], cars[,2], xlab = " speed" , ylab = " distance" )
Finally type ' q()' to quit R.
> q() Save workspace image? [y/n/c]: y
Comments ( 1 )