Install R and RStudio [optional]
If you’re working with your own data, install the software on your computer
Installation links
If you do wish to install R and RStudio, please follow the instructions on the R and Posit websites respectively
R | Download link | Installation guide |
RStudio | Download link | We suggest a websearch for a guide for your Operating System |
If you are having difficulty installing R or RStudio on your own computer, you are welcome to ask for help in our private discussion space
However, please be aware that we may not be able to help, given the complexity of different1s, foibles of individual computers, and number of people on the course
Create an RStudio project
If you’re using R and RStudio on your own computer, first create a new RStudio project, to help us keep our data, code and outputs organised:
- Open RStudio
- Go to Project > Create Project
- Click on New Project
- Type in a directory name, e.g. ExploreData
- Click the Browse button to choose where to save your ExploreData folder
- Click Create Project
- Go to File > New R Script to create a blank text file in which to type and save your code
This is what your RStudio window should look like, with the different panels labelled:
Run code in RStudio
Once you have typed some code into your new script, you need to run it to see the output in the Console panel
The easiest way to run the functions from RStudio is by using the keyboard, because using the mouse slows you down (and fatigues your hands)
- Move your cursor to the first line
- To run the entire line of code where your cursor is, press Ctrl+R. RStudio will send the function(s) to the R window below, and R will process it
- R gives you the answer immediately you run the code
- The cursor will jump to the next line of code automatically, so you can keep pressing Ctrl+R to run multiple lines
- You can also
- Run multiple lines by highlighting a block of text and pressing Ctrl+R
- Run just part of a line by selecting only the code you want to run
Your code is shown in blue text, the R output (answers) in black text, and error messages in red
Footnotes
OS: Operating Systems↩︎