Statistics Tutorial
1 Part 1: Intro to R and RStudio

1.1 Intended Learning Outcomes
- Be introduced to R and RStudio
- Be able to load add-on packages
- Be able to get help for packages and functions
- Be able to create objects by writing and running R code
1.2 R and RStudio
R is a programming language that you will write code in and RStudio is an Integrated Development Environment (IDE) which makes working in R easier. Think of it as knowing English and using a plain text editor like NotePad to write a book versus using a word processor like Microsoft Word. You could do it, but it would be much harder without things like spell-checking and formatting and you wouldn't be able to use some of the advanced features that Word has developed. In a similar way, you can use R without RStudio but we wouldn't recommend it. RStudio serves as a text editor, file manager, spreadsheet viewer, and more. The key thing to remember is that although you will do all of your work using RStudio for this course, you are actually using two pieces of software which means that from time-to-time, both of them may have separate updates.
1.3 RStudio Quickstart Guide
The R software gives the computer the ability to process the R programming language. We will never use that software directly. Instead, we will use RStudio, an integrated development environment (IDE) which runs R for us via a graphical user interface (GUI) .
Once you have opened RStudio, to create a text file (called an "R script") to write your R code in select from the menu:
> File > New File > R Script
To save the R script file, go to
> File > Save
A dialogue box will appear asking where (on which drive) you would like to save the code.
Save this R script file with a relevant filename, e.g. "Statistics_Tutorial".
Once saved in a .R script file, you can use your code again, so there's no need to type it in a second time. If you close RStudio and then open it again you can read in your code by going to
> File > Open File…
and find the code file from the location where you saved it.
The RStudio IDE is arranged with four window.
Figure 1.1: The RStudio IDE
By default, the upper left pane is the source pane, where you view, write, and edit code from files and view data tables in a spreadsheet format. When you first open RStudio, this pane won't display until we open a script file (like we did above) or load in some data. We 'run' (i.e. execute) code in the script file by selecting the row(s) we want to run and then clicking the Run icon OR by holding down the ctrl key and Enter key at the same time. The results of executing the code (if any) appear in the lower left pane.
The lower left pane is the console pane, where you can type in commands and view output messages. You can write code in the console to test it out. The code will run and can create objects in the environment, but the code itself won't be saved. You need to write your code into a script in the source pane to save it.
The right panes have several different tabs that show you information about your code. The most used tabs in the upper right pane are the Environment tab and the Help tab. The environment tab lists some information about the object that you have defined in your code. We'll learn more about the Help tab in Section 2.1.5.
In the lower right pane, the most used tabs are the Files tab for directory structure, the Plots tab for plots made in a script, the Packages tab for managing add-on packages, and the Viewer tab to display reports created by your scripts.
1.4 Credit where credit is due
This introductory lab incorporates and adapts materials from:
Nordmann, E. & DeBruine, L. (2022) Applied Data Skills. v1.0. Retrieved from https://psyteachr.github.io/ads-v1/ doi: 10.5281/zenodo.6365077 and
Hill, A. (2022) Data Visualization in the Tidyverse: The Great Tidy Plot Off. Retrieved from https://alison.netlify.app/uo-tidy-bakeoff