Site icon DataFlair

How to Install R, RStudio and R Packages – The Easiest Process Ever!

R & RStudio Installation

FREE Online Courses: Elevate Skills, Zero Cost. Enroll Now!

With this tutorial, we will learn to install RStudio and R for Mac, Linux, and Windows along with its process of updating in all these operating systems. We will also cover the concept of R packages in detail.

Let’s start the R installation tutorial.

Steps to Install R, RStudio, and R Packages

Here we will discuss the simple steps to install RStudio. But, before installing RStudio, we will have to install R. So, first, let’s learn the process of R installation.

We have to follow three basic steps in the same order to run R and RStudio on your system.

  1. Install R
  2. Then, install RStudio
  3. Lastly, install R Packages

1. Install R

The process of installing R depends on the type of your operating system. R can be installed in the following ways:

For Mac

CRAN R Project

Now, for Linux

Technology is evolving rapidly!
Stay updated with DataFlair on WhatsApp!!

Lastly, for Windows

Step 1: Go to the website –  CRAN R Project Windows 

Step 2: Click on the “Download R 3.6.0 for Windows”

Step 3: Clicking on the tab will download the R installer. Double click on the installer to launch it.

Step 4: Select the language of your choice in the installer and click OK.

Step 5: Clicking on Next will lead you to the important information of the license. Click on Next.

Step 6: Then, it will provide you with an interface for selecting the destination for your R installation.

Step 7: After clicking on Next, you will be directed to select components for installation. It is ideal to keep all the components.

Step 8: In the next step, you will be asked if you would want to customize the startup. Click on No(accept defaults) as an ideal option.

Step 9: In the next step, you will be asked to select the start menu folder. By default, start menu folder cannot be created but you can change that by unchecking the checkbox.

Step 10: In the next step, you will be asked for additional details. You can create a desktop shortcut or a Quick Launch Startup by checking the boxes.

Step 11: Clicking on Next will prompt the installation to start. After this, the installation is complete and R is installed.

You must definitely check the Latest Features of R Programming

2. Install RStudio

Now, in order to install the IDE RStudio, we will take the following steps:

Step 1: Go to the website – RStudio download

Step 2: Here, you will find various versions of R. Click on the Download button.

For Windows

Step 1: Clicking on Download will shift the page lower to the various platforms of R installation. Click on Windows 7+ (64 Bit)

Step 2: After the download is finished, click on the installer and click Next.

Step 3: Clicking on Next will direct you to the installation location.

Step 4: Clicking on Next will direct you to choose the Start Menu Folder.

Step 5: Clicking on Install will start the installation process.

Step 6: Finally, click on the Finish button.

Step 7: In the final step, test if R is properly installed by opening RStudio and typing the following lines:

> line <- "Hello World"
> line

Output:

You have successfully installed R on Windows!

3. Install the R Packages (Optional)

In RStudio, if you require a particular library, then you can go through the following instructions:

Updating R and RStudio

1. Updating R

Mac and Ubuntu

On Mac and Ubuntu, you need to go to the CRAN website, https://www.r-project.org/ to install the newer package installer.

Windows

A package called installr, which is only for Windows can be used to ease the process. Updating on windows is tricky.

If you don’t have installr package then first install it

#installing the latest installr package:

install.packages(“installr”); library(installr) # For installing & loading installr

updateR()

After running the updateR(), R will detect if there is a new version available. If there is, it will download and install it.

2. Updating RStudio

Updating RStudio is easy, go to Help > Check for Updates to install a newer version.

Don’t forget to explore the RStudio Tutorial for Beginners

3. Updating R Packages

3.1 Updating Out of date Packages

Install.packages() is used to install any package of CRAN. For example:

Typing Install.packages(“ggplot2”) in the console will install the latest package of ggplot2

You can also update any out of date package with the help of the update.packages() function. 

update.packages()

Doing so will prompt the system to ask your permission prior to the installation of the package. In order to not let the system prompt for your permission, use the ask = False attribute in the packages() function. 

update.packages(ask = FALSE)

Unfortunately, this won’t update packages installed by devtools::install_github().

3.2 Updating all Packages after R update

By using the package installr, we can handle it on windows. But for other operating systems, after updating R, a lot of packages might have been built under the old R version. It would be safer to re-install all the packages already installed. This can be done with the following commands. Again this won’t update packages installed with devtools::install_github().

## get packages installed
packs = as.data.frame(installed.packages(.libPaths()[1]), stringsAsFactors = F)
## and now re-install install packages using install.packages()
install.packages(packs$Package)

Master the complete process of Installing and Using Packages in R Programming

R Packages (Libraries)

Packages comprise of R functions, data and compiled code that are present in a well-defined format. The location where the packages are installed is known as a library. R comes with a standard set of packages. Others are available for download and installation. If we will install it once, we have to be load it into the session to be used.

1. Recommended Packages

install.packages("<the package's name>")

There are thousands of useful R packages for us, but navigating them all can be a challenge.Here are a few packages, we recommend to a beginner:

  1. Tidyversre: tidyverse is a collection of packages that are useful for many tasks like data management, data reshaping, data formatting, memory management, etc.
  2. Ggplot2: the ggplot2 package is the most popular graphics package in R. It extends R’s graphical capabilities by a large margin able to make static, dynamic as well as animated graphics with simple commands.
  3. Installr: the installr package is highly useful for installing, updating and managing versions of R, RStudio, and R packages.
  4. Stringr: Stringr is a package very popular for its string manipulation functions. Stringr functions are much easier to use and more powerful than the base R functions.

2. Basic Notions

The R Language

The R Project

Basic R Concepts

Basic Interaction with R Console

print('Testing')

Output:

Output:

 

Using R as a Calculator

> 1+2
> 1/2
> 11^2

Output:

Documentation

Every good package consists of documentation. Users will not know how to make sense of the package. Documentation is also useful for future-you, and for developers extending your package.

Datasets

There are a large number of datasets that are open for free analysis in R. Furthermore, there are other open datasets that are available on Kaggle which you can directly utilize for analyzing and predicting. 

Summary

We understood the process of installing RStudio and R in all the operating systems. We also learned the steps to update R, RStudio and R packages.

Learn to implement various Data Types in R Programming Language

Any feedback or suggestion for us? Share your views in the comment section below. We will be glad to hear from you.

Exit mobile version