1  R, RStudio, and Posit Cloud

You can skip all the whole of 1.1 if you already have R and RStudio installed. If not, proceed to the operating system loaded in your machine at 1.1.1.

1.1 Installing R and RStudio

R and RStudio are free to install and use softwares. To install them software, you need to download and install the right file for your machine’s operating system (OS). Below are the installation instructions based on operating system.

1.1.1 Installing R

Windows OS (10/ 11): To download R from CRAN visit this link https://cran.rstudio.com/bin/windows/base/R-4.4.1-win.exe and run the installer. This is the latest version at the time of writing this chapter

Mac OS: There are two versions of R for Mac users based on the processor in your computer.

Linux Users R installation on Linux depends on your distribution. Open terminal (Ctrl + Alt + T) and enter the command below based on your distribution.

  • Debian/Ubuntu distribution:
#| eval: false
$ sudo apt update
$ sudo apt install r-base r-base-dev
  • Redhat/Fedora distribution:
#| eval: false
$ sudo dnf install R

1.1.2 Installing RStudio

To install RStudio, visit the link https://posit.co/download/rstudio-desktop/ scroll down and download the package for your OS, and install. Installation of downloaded file is direct. If you prefer a video guide, choose the link based on your OS:

1.2 The RStudio Interface

When you open RStudio newly, you are presented with three panes by default. You can get a fourth pane like what is shown in Figure 1.1. To do this, click the + button at the top-left and select R Script, or use the keyboard shortcut Ctrl + Shift + N on Windows/Linux and Cmd + Shift + N on Mac. More details on the panes is provided in Section 1.2.1

Figure 1.1: R Studio Environment

You can change the arrangement of the panes by clicking Tools on the menu bar then navigate to Global Options and Pane Layout in the popup box.

1.2.1 RStudio Panes

The four components/panes shown in Figure 1.1 are:

  1. Source Pane: Located in the top-left. This pane shows after adding a R script. The R script is where you will do most of data analysis task. It is technically a plain text file containing a series of R commands that are executed in sequence. The source pane also shows your dataset in spreadsheet-like format.

Source window
  1. Console/Terminal/Background Jobs pane: Located in the bottom-left. It include the Console pane where outputs and results of your analysis are displayed. The console is also an interactive section where you can write code and carry out some analysis. All the codes written in the script are usually displayed and executed on the console. This pane also include the Terminal pane which provides direct access to your computer using command line. Lastly, we have the Background Jobs pane which allows you to run tasks in the background while you continue working on other tasks in the main R session. This pane is especially useful for long-running operations that might otherwise block your R session, such as data processing, simulations, or model fitting.

Console window
  1. Environment / History Pane: Located in the top-right. It includes the Environment pane which displays all objects created during a session, such as data and variables. We also have the History pane which stores the history of commands executed. This pane allows you to select previous commands and rerun them or add them back to console if you want. Located closely to History pane is the Connection pane which helps you interact with and manage connections to external data sources, such as databases, cloud services, or remote data systems. It provides a user-friendly interface for establishing and managing these connections directly from RStudio, without needing to write extensive code. After this is the Tutorial pane provides additional learning materials for R and RStudio. It is designed to be an interactive R tutorial.

An R session refers to the instance of R that is currently running, which includes everything that is active in memory and the state of your environment in RStudio or any R interface.

Environment window
  1. Files / Plots / Packages / Help / Viewer Window: This is located in the bottom-right and it consists of the Files pane which shows files and folders in your working directory. This pane also include tools for renaming, deleting, creating, copying and moving files and folders in your computer. Next is the Plots pane which displays visualizations. You can also export, zoom in or out, and copy to your clipboard the visuals created in this pane. The Packages pane follows closely and it helps to manage packages you have. It can also be used for updating old packages as well as installing new packages. Next is the Help pane which shows the documentation of packages different functions. This documentation include examples which can help understand the usage of the functions. Lastly, we have the Viewer pane which is used to display a variety of visual outputs including interactive web content, plots, maps, and web-based applications.

Files window

1.3 Posit Cloud

There’s an option to use R and RStudio online from your browser. This is through Posit Cloud (formerly RStudio Cloud). Posit cloud is owned by the same organization that made RStudio. To use posit cloud, visit https://posit.cloud/ and register. After registering, you get a page similar to Figure 1.2. After registering, click on new workspace on the left sidebar and create a new project.

Figure 1.2: posit cloud

The video series in this link is a good resource for starting with Posit Cloud.

Script vs Console

It is advised to use a script to ensure reproducibility. It ensures you can edit your work when you make errors, share with others your analysis, and also reproduce all steps in your analysis instantly.

1.4 Positron

There’s a new IDE that supports Python and R that is still under development by the company Posit PBC. This is called Positron. Positron is still in its early stage of development. Positron is a blend of the popular IDE VS Code and RStudio, with the major inspiration from VS Code, (Radečić 2024). What makes Positron different is the ease of using python, which is one of the most common programming language of choice for data professionals. To get more details about the development, click here and here for detailed introduction on Positron.

Positron IDE

1.5 Summary

In this chapter, we covered how to install R, and RStudio. We also introduced the different panes/windows of RStudio IDE which includes, the source, environment, console and files panes. Lastly, we introduced the Posit cloud platform, a cloud-based RStudio platform as well as Positron, which is the next iteration of IDE from Posit.co