How to install R and R Studio on Linux

How to install R and R Studio on Linux

Abhishek Kumar's photo
Abhishek Kumar
·Jun 19, 2022·

5 min read

If you're looking to install R on Linux that means you already know and familiar with R then you can just directly go to the instructions below but if you're new and still learning and figuring out about it, let me explain.

R is a programming language frequently used for statistical analysis, visualization, and other data analysis. R offers convenient statistical features for data analysis and is useful for creating advanced data visualizations. Well, if you don't believe me with the visualization part then you can try it out yourself or check out in the end where I tried to show a little example of Data Viz using R. Now you might ask that Tableau is also a tool for data viz and can create amazing visualizations and I agree with that but R is not limited to just Data visualization, you can do all sorts of things with it like import your large data sets in it and can perform serious analysis which you usually do in Spreadsheet or SQL programs.

Now there's a whole debate about which is better R or Python for Data Analysis, I'd say use whatever works best for your usecase. For me, I personally feel that Python is a really powerful language and can be used for many purposes no doubt in that but that makes it too general. Whereas, R is designed specifically for statistical and scientific analysis and it's really good in it. I think that much explaination should be enough and now let's move on to the installation part.

Steps to install R :

Before we begin the process of installing R, it's a good practice to check if we have up to date packages and if not then these commands will update them to the latest available version.

$ sudo apt update

$ sudo apt upgrade

  • For Debian based distros :

$ sudo apt install r-base

installing_r-base.png

You may want to install the automatically tuned Atlas or the multi-threaded OpenBlas library in order to get higher performance for linear algebra operations :

$ sudo apt-get install libatlas3-base

or

$ sudo apt-get install libopenblas-base

installing_package_for_linear_algebra.png

To access R Console in Terminal just type R in the terminal and you'll be greeted with R console (Note: Use Capital R).

calling_R.png

Even though we have sucessfully installed R and can use it like that in Terminal or we can install an IDE for R. IDE or Integrated Development Environment is a software application that brings together all the tools you may want to use in a single place. R Studio is one such IDE Application for R and it's really good for this purpose and we'll install that in our system.

Steps to install R Studio :

RStudio is available for linux you can go and download the file from main website or you can click here

Once the file is downloaded, go to the location/directory where you saved the file and double click it, it'll ask for your password and then click install.

RStudio_doble_click_install.png

If for some reason the above method didn't work for you, then you can install the program via terminal. To do that :

  1. Open Terminal
  2. change the directory where you installed the file for example :

    $ cd Downloads

( cd is Change Directory )

  1. To install the .deb file, type :

$ sudo apt install ./nameofthefile.deb

and press enter, this will install the program on your Linux Machine

( Replace Name of file with your RStudio filename. )

RStudio_cli_install_2_crop.png

Creating a simple viz in R (just for fun) :

To create our visualization we first need to install a package called Tidyverse inside R Console. Tidyverse is basically contains all sorts of amazing packages for data manipulation, visualization, and all sorts of data science things. You can read about it here.

Tidyverse is constantly updating itself with new packages, people contribute their scripts and code to make it better and that's the beauty of Open Source projects and it's community. If you come across any Open Source project which you liked and it suits your needs then please consider donating.

To install tidyverse in R :

Before installing Tidyverse we need to install it's dependencies (Sometimes when you install programs, they rely on other programs to work. These other programs are called dependencies.) and to do that, open your terminal and type :

$ sudo apt install libcurl4-openssl-dev libssl-dev libxml2-dev

Then in R Console or in R Studio>Console, type :

install.packages("tidyverse")

It'll take a moment to install the packages, after successfull installation you can load the Tidyverse library on your console by typing :

library("tidyverse")

And it should look like this :

successfull_tidyverse.png

Now we are ready to create some Visualization with some Programming, I'm using a package called "palmerpenguins" for this demo purpose :

install.packages("palmerpenguins")

Time to load the package in the library :

library("palmerpenguins")

Now comes the plotting/visualization part :

ggplot(data=penguins, aes(x=flipper_length_mm, y=body_mass_g))+geom_point(aes(color=species))

Then HIT ENTER and if you've typed everything correct, you'll see a Scatter Plot Visualization of our Penguin data like this :

plotting_palmerpenguins.png

Here you go, now you can work on your Data project on Linux, find cool and meaningful insights from your data and use them to create awesome visualizations. I hope that my instructions were clear and helpful to you, if you still were not able to install it or encounter some error, you can just comment it down and I'll definitely look into it.

Did you find this article valuable?

Support Abhishek Kumar by becoming a sponsor. Any amount is appreciated!

Learn more about Hashnode Sponsors
 
Share this