3 R and R studio

This training program is tailored to equip you with the skills needed for multivariate data analysis using R and RStudio. In this introductory section, we will provide you with a brief overview and guide you through the process of installing R and RStudio.

3.1 R

R is a programming language for statistical computing and graphics supported by the R Core Team and the R Foundation for Statistical Computing. Created by statisticians Ross Ihaka and Robert Gentleman. R is an implementation of the S programming language. R is used among data miners, bioinformaticians and statisticians for data analysis and developing statistical software. Users have created packages to augment the functions of the R language. According to user surveys and studies of scholarly literature databases, R is one of the most commonly used programming languages used in data mining. The official R software environment is an open-source free software environment within the GNU package, available under the GNU General Public License. It is written primarily in C, Fortran, and R itself (partially self-hosting). R has a command line interface. Multiple third-party graphical user interfaces are also available, such as RStudio, an integrated development environment.

R logo

Figure 3.1: R logo

3.2 Rstudio

RStudio is an integrated development environment (IDE) for R. It includes a console, syntax-highlighting editor that supports direct code execution, as well as tools for plotting, history, debugging and workspace management. RStudio is available in open source and commercial editions and runs on the desktop (Windows, Mac, and Linux) or in a browser connected to RStudio Server. RStudio is a free and open-source integrated development environment (IDE) for R, a programming language for statistical computing and graphics. JJ Allaire, creator of the programming language ColdFusion, founded RStudio. RStudio is available in two editions: RStudio Desktop, where the program is run locally as a regular desktop application; and RStudio Server, which allows accessing RStudio using a web browser while it is running on a remote Linux server.

RStudio is written in the C++ programming language and uses the Qt framework for its graphical user interface. Work on RStudio started at around December 2010, and the first public beta version (v0.92) was officially announced in February 2011.

R studio logo

Figure 3.2: R studio logo

Typical RStudio window has four panes as explained below

R studio window

Figure 3.3: R studio window

  1. Console

This is where the action happens. Here any authentic R code typed after the ‘>’ prompt will be executed after pressing ‘Enter’ to generate the output. This is where we are going to type our single call function to start our app for data analysis.

  1. Source Editor

This is where R scripts (collection of code) can be created and edited. New R script can be opened by clicking File –> New File –> R Script or using short cut ctrl+shift+N. You can type your codes here. To run a code in console or execute, place the cursor in the line which code is written and press ctrl+enter or highlight the code you wish to evaluate and clicking on the “Run” button on the top right of the Source. You can save your R codes, written in script.

  1. Environment|History|Connections

All of the data objects (such as vectors, matrices, and dataframes) that you have defined in your current R session are listed under the Environment tab of this panel. In data objects, you may also examine details like the quantity of observations and rows. A few other clickable options are available on the tab, such as Import Dataset, which will launch a graphical user interface (GUI) for inputting data into R.

This panel’s History tab only provides a history of all the code that you have previously evaluated in the Console.

The Environment / History panel could be helpful as you become more accustomed to R. However, you can ignore it right now. You can simply just reduce the window by clicking the minimise button in the panel’s upper right corner if you wish to clear up space on your screen.

  1. Files|Plots|Packages|Help|Viewer

You can find a collection of useful information in the Files|Plots|Packages|Help panel. Let’s examine each tab in more detail:
- The file directory on your hard disc is accessible through the files panel. You can utilise the “Files” panel to set your working directory by clicking “More” and then “Set As Working Directory” once you’ve navigated to the folder where you wish to read and save files.

  • All of your plots are displayed in the Plots panel. There are buttons to export the plot as a pdf or jpg and to open the plot in a separate window.
    We are interested in the install button in this pane, to install packages required for our analysis.

3.3 Installing R

Follow below steps in correct order for installation of R

3.3.1 First install R latest version

To install R on Windows OS:

Go to the CRAN website.

Click on “Download R for Windows”.

Click on “install R for the first time”.

Click on “Download R-4.3.1 for windows” link to download the R executable (.exe) file.(By the time of writing this manual R version was 4.3.1, it may change in future)

After downloading the file. Run the R executable file by double clicking on the downloaded file to start installation, and allow the app to make changes to your device.

Select the installation language.

Follow the installation instructions.
Click next and wait for the installation to complete.
Click on “Finish” to exit and complete the installation setup.
You can now run R from the start menu or the shortcut created on your desktop

R studio is GUI for R, so keep this in mind. Before installing R studio you should install R.

3.4 Installing Rstudio

After installing latest version of R. Go to the Rstudio website.

Click on “DOWNLOAD RSTUDIO DESKTOP FOR R”

Now like you have completed the installation of R, complete the installation setup of Rstudio. After installation you can now run R from the start menu or the shortcut created on your desktop.

Now you are ready to explore the world of data analysis and unleash the potential of R and RStudio to unlock valuable insights from your datasets. Happy Statistics with R!