Stats & R - How to install R and Rstudio (2024)

tutorial

A tutorial for R and Rstudio installation on Mac

Author

NING LI

Published

January 19, 2023

R is an open-source programming language and software environment for statistical computing, data analysis, and graphics. It was developed by Ross Ihaka and Robert Gentleman in 1993 and has since become a popular tool for data analysis and visualization in academia, government, and industry.

There are several reasons why you may want to learn R programming:

Overall, learning R programming provides users with a flexible, powerful, and accessible tool for data analysis, visualization, and machine learning.

RStudio is an integrated development environment (IDE) for the R programming language. It provides a user-friendly interface and includes features such as syntax highlighting, code completion, debugging, and visualization tools.

RStudio is not a part of the R programming language, but rather a third-party software that integrates with R. It provides additional functionality and a user-friendly interface on top of R, making it easier for users to interact with the R language and perform complex data analysis and visualization tasks. In short, R is a programming language, and RStudio is an IDE that makes it easier to work with R.

Note

Therefore, the order of installing the R language is: first R, then Rstudio. Remember, R is the basis of Rstudio, R must be installed before installing Rstudio.

5.1 Installing R and RStudio on Windows:

  • Go to the R website (https://cran.r-project.org) and download the latest version of R for Windows.

  • Once the download is complete, run the setup file and follow the on-screen instructions to install R on your computer.

  • Next, go to the RStudio website (https://rstudio.com) and download the latest version of RStudio Desktop for Windows.

  • Run the setup file and follow the on-screen instructions to install RStudio on your computer.

  • Once both R and RStudio are installed, you can launch RStudio from the Windows Start menu.

5.2 Installing R and RStudio on Mac:

  • Go to the R website (https://cran.r-project.org) and download the latest version of R for Mac.

  • Once the download is complete, open the downloaded file and follow the on-screen instructions to install R on your computer.

  • Next, go to the RStudio website (https://rstudio.com) and download the latest version of RStudio Desktop for Mac.

  • Once the download is complete, open the downloaded file and follow the on-screen instructions to install RStudio on your computer.

  • Once both R and RStudio are installed, you can launch RStudio from the Applications folder on your Mac.

5.3 Installing R and RStudio on Linux:

  • Go to the R website (https://cran.r-project.org) and download the latest version of R for Linux.

  • Once the download is complete, open a terminal window and navigate to the directory where the downloaded file is located.

  • Run the following command to install R:

    sudo apt-get install r-base

  • Next, go to the RStudio website (https://rstudio.com) and download the latest version of RStudio Desktop for Linux.

  • Once the download is complete, open a terminal window and navigate to the directory where the downloaded file is located.

  • Run the following command to install RStudio:

    sudo dpkg -i rstudio-*.deb

  • Once both R and RStudio are installed, you can launch RStudio from the Applications menu on your Linux computer.

5.4 Installing R and RStudio on Mac and Linux using Homebrew

Homebrew is a package manager for Mac and Linux that makes it easy to install and manage software. Here’s how to install R and RStudio using Homebrew:

5.4.1 Mac:

  • If you don’t already have Homebrew installed, run the following command in your terminal to install it:

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

  • Once Homebrew is installed, run the following command to install R:

    brew install r

  • Next, run the following command in your terminal to install:

    brew install --cask rstudio

  • Once both R and RStudio are installed, you can launch RStudio from the Applications folder on your Mac.

5.4.2 Linux:

  • Same instruction as mac to install Homebrew on Linux.

  • Once Homebrew is installed, run the following command to install R:

    brew install r

  • Next, go to the RStudio website (https://rstudio.com) and download the latest version of RStudio Desktop for Linux.

  • Once the download is complete, open a terminal window and navigate to the directory where the downloaded file is located.

  • Run the following command to install RStudio:

    sudo dpkg -i rstudio-*.deb

  • Once both R and RStudio are installed, you can launch RStudio from the Applications menu on your Linux computer.

  • Launch RStudio.

  • Click on the “File” menu in the top left corner and select “New Project”.

  • Select “New Directory” and then “New Project”.

    Stats & R - How to install R and Rstudio (1)

  • Choose the type of project you want to create: a standard project, a package project, or a Shiny web application project.

    Stats & R - How to install R and Rstudio (2)

  • Choose the location for your project and give it a name.

  • Click “Create Project”.

    Stats & R - How to install R and Rstudio (3)

  • RStudio will create a new project directory with a specific structure, including a main R script file, a subdirectory for data, and a subdirectory for output.

  • You can now start writing code and working on your project.

    Stats & R - How to install R and Rstudio (4)

  • Whenever you want to save your project, simply go to the “File” menu and select “Save”. Your project will be saved as an RStudio project file, which you can reopen later to continue working on it.

  • Now test our installed R language environment
height <- c(145, 167, 176, 123, 150)weight <- c(51, 63, 64, 40, 55)cor(height, weight)
[1] 0.9893769
plot(height,weight, type = "p")

Stats & R - How to install R and Rstudio (5)

  • If R language environment is installed properly, then you will see a dot plot of height and weight.

Stats & R - How to install R and Rstudio (6)

Stats & R - How to install R and Rstudio (2024)
Top Articles
Latest Posts
Article information

Author: Lidia Grady

Last Updated:

Views: 5235

Rating: 4.4 / 5 (45 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Lidia Grady

Birthday: 1992-01-22

Address: Suite 493 356 Dale Fall, New Wanda, RI 52485

Phone: +29914464387516

Job: Customer Engineer

Hobby: Cryptography, Writing, Dowsing, Stand-up comedy, Calligraphy, Web surfing, Ghost hunting

Introduction: My name is Lidia Grady, I am a thankful, fine, glamorous, lucky, lively, pleasant, shiny person who loves writing and wants to share my knowledge and understanding with you.