Section 1 R and RStudio

The programming language that we are using is called R (R Core Team 2020), but we will use a separate program, called RStudio (RStudio Team 2020), known as an “Integrated Development Environment”, to work with R. You can use R without using RStudio, but you can’t use RStudio without using R.

1.1 Using R on campus

If you are using a computer on the university network, click on the Windows 10 icon in the bottom left corner of the screen, then search the list of programs and click on RStudio.

1.2 Using R at home

You can download both RStudio and R for free on your own computer.

1.3 The RStudio interface

When you first start RStudio, you should see something like this:

There are three windows (a fourth will appear later), and for now, we’ll just use the one on the left, which is called the Console. The red circle drawn in the console window shows the command prompt: this is where you type in commands.

1.4 Inputs and outputs

In these notes, input will be displayed in shaded boxes like this:

2 + 3

and output from R will be shown like this:

## [1] 5

(Ignore the ## symbols and the [1] for now: the output we want is the number 5: the result of the command 2 + 3.)

You can copy and paste input directly from these pages into RStudio (it’s helpful to know the keyboard shortcuts for copy and paste: these are usually ctrl c and ctrl v on windows PCs, and cmd c and cmd v on macs.)

You should try the commands you see here directly in RStudio, to check that they work and that you get the same results.



1.5 Get comfortable!

You will be using RStudio quite a lot, so you may wish to change the appearance. Some people find dark backgrounds more comfortable for reading.

  • From the menu bar, go to Tools > Global Options
  • Click on Appearance
  • Change the Editor font size if you want to
  • Try out a few themes in the Editor theme box. (The default is Textmate. I prefer Pastel on Dark).
  • Once you find something you like (or just stick with Textmate if you are happy with the default appearance), click on OK, and continue with this tutorial.


1.6 Change your Workspace settings

R has an optional setting, in which any variables and functions that you have defined are saved and reloaded each time you quit and restart. I suggest you don’t use this setting. To make sure it is switched off, go to Tools > Global Options…

  • Make sure the box Restore .RData into workspace on startup is not ticked;
  • Set Save workspace to .RData on exit to Never

The settings should look like this:

References

R Core Team. 2020. R: A Language and Environment for Statistical Computing. Vienna, Austria: R Foundation for Statistical Computing. https://www.R-project.org/.
RStudio Team. 2020. RStudio: Integrated Development Environment for r. Boston, MA: RStudio, PBC. http://www.rstudio.com/.