Install R and RStudio – A Step-by-Step Guide for Beginners
Looking to install R and RStudio in different operating systems? Follow the step by step procedure and download R and RStudio in an easy way.
Check out the installation process of R and RStudio on Linux operating systems, Microsoft Windows, and Mac OS X and also look at some useful R packages that enhance R’s capabilities.
How to Install R
In this tutorial, you will learn to-
- Install R and RStudio on Linux
- Install R and RStudio on Windows
- Install R and RStudio on Mac OS X
- Some useful Packages in R
Installing R and RStudio on Linux
Linux software is often distributed as source code and then compiled by package managers like apt or yum. To install R in Ubuntu, we will have to go through the following steps.
Install R on Linux
Install the R-base package using the following code
sudo apt-get update
sudo apt-get install r-base
After running the command, a confirmation prompt will appear. Answer it with a ‘Y’ for yes.
Install RStudio on Linux
Step – 1 Next comes installing RStudio. To install RStudio, go to download RStudio, click on the download button for RStudio desktop, click the link for the latest R version for your OS and save the .deb file.
Step – 2 Download and install the gdebi package using the following commands
sudo apt install gdebi
Answer with a ‘Y’ for yes to confirm when prompted.
Step – 3 Use the following commands to install the .deb package
sudo gdebi /path/to/the/file/.deb
Installing R and RStudio on Windows
To install R and RStudio on windows, go through the following steps:
Install R on windows
Step – 1: Go to CRAN R project website.
Step – 2: Click on the Download R for Windows link.
Step – 3: Click on the base subdirectory link or install R for the first time link.
Step – 4: Click Download R X.X.X for Windows (X.X.X stand for the latest version of R. eg: 3.6.1) and save the executable .exe file.
Step – 5: Run the .exe file and follow the installation instructions.
5.a. Select the desired language and then click Next.
5.b. Read the license agreement and click Next.
5.c. Select the components you wish to install (it is recommended to install all the components). Click Next.
5.d. Enter/browse the folder/path you wish to install R into and then confirm by clicking Next.
5.e. Select additional tasks like creating desktop shortcuts etc. then click Next.
5.f. Wait for the installation process to complete.
5.g. Click on Finish to complete the installation.
Install RStudio on Windows
Step – 1: With R-base installed, let’s move on to installing RStudio. To begin, go to download RStudio and click on the download button for RStudio desktop.
Step – 2: Click on the link for the windows version of RStudio and save the .exe file.
Step – 3: Run the .exe and follow the installation instructions.
3.a. Click Next on the welcome window.
3.b. Enter/browse the path to the installation folder and click Next to proceed.
3.c. Select the folder for the start menu shortcut or click on do not create shortcuts and then click Next.
3.d. Wait for the installation process to complete.
3.e. Click Finish to end the installation.
Installing R and RStudio on Mac OS X
To install R and RStudio on Mac OS X, go through the following steps:
Install R on Mac
Step – 1: Go to CRAN R Project Website.
Step – 2: Click on the Download for (Mac) OS X link.
Step – 3: Click on the link for the pkg file of the latest R version and save it.
Step – 4: Double click the downloaded file and follow installation instructions.
Install RStudio on Mac OS X
Step – 1: With the r-base installed, you need to install RStudio. To do that, go to download RStudio and click on the download button for the RStudio desktop.
Step – 2: Click on the link for the Mac OS X version of RStudio and save the .dmg file.
Step – 3: Double click the downloaded file and then drag-and-drop it into your applications folder.
Now with R and RStudio installed in your system, let’s look at a few packages that might help you in learning as well as using R to its fullest potential!
Some useful Packages in R
CRAN is full of packages for everything you will need while working with R, and it is still growing. Many useful functions of R come in these packages. To install a package, simply run the following command in RStudio:
> install.packages(“<package name>”)
Once installed, a package can be made available in the current R session using the command:
> library(“<package name>”)
While it may become confusing at times due to the sheer number of options available, here are a few packages that are popular for their reliability and usefulness:
- Tidyverse – Tidyverse is a collection of packages that work in harmony with each other to clean, process, model, and visualize data. Tidyverse’s core package contains packages like ggplot2, dplyr, tidyr, readr, purrr, tibble, stringr, and forcats.
- Installr – installr allows you to update R and all its packages with just a single command.
- Rtweet – Twitter is the prime target for extracting tweets and building models to understand and predict sentiment. The rtweet package allows you to scrap Tweets and perform sentiment analysis.
- MLR (Machine Learning in R) – MLR is a package that lets you perform all kinds of machine learning tasks. MLR includes all the popular machine learning algorithms used for ML projects.
- Reticulate – Reticulate lets you use Python alongside with R in the R environment. Not only that, but you can also use major Python libraries within R itself.
- R markdown – R markdown lets you create documents in multiple formats like pdf, HTML, and MS Word documents while embedding R codes, results, and visualizations to produce informative and thorough reports.
- Shiny – Shiny is an R package that lets you make interactive web-apps. Using shiny, you can embed the findings of your analysis into the web-apps. This enables the users to play with your data and the results for deeper understanding, resulting in improved communication of the results.
There are many more packages available on repositories like CRAN, Bioconductor, and GitHub that can be used to improve R’s functions and facilities as well as to add new functions.
As you use and explore R some more, you will discover more of them and find new and exciting uses for them all.
In this tutorial, we learned how to install R and RStudio in systems with Linux, Windows, and Mac OS X.
We also learned about some useful R packages that improve and enhance R’s capabilities and prove to be highly useful.
If you find any difficulty to install R and RStudio then ask us in the comment and our TechVidvans will be happy to help.
Install R now and start learning R programming from scratch by following TechVidvan R tutorial.