5 RStudio, What and Why
5.1 Overview
- Teaching 5 minutes
- Exercises 2 minutes
5.2 Questions
- What is RStudio?
- Why should I use RStudio?
- What features should I change?
5.3 Objectives
- Get familiarised with RStudio
- Get set up with not storing the RStudio workspace
- Download the course materials for the workshop
5.4 What is RStudio, and why should I use it?
If R is the engine and bare bones of your car, then RStudio is like the rest of the car. The engine is super critical part of your car. But in order to make things properly functional, you need to have a steering wheel, comfy seats, a radio, rear and side view mirrors, storage, and seatbelts.
The RStudio layout has the following features:
- On the upper left, the R Markdown script
- On the lower left, the R console
- On the lower right, the view for files, plots, packages, help, and viewer.
- On the upper right, the environment / history pane
We saw a bit of what an R Markdown script does.
The R console is the bit where you can run your code. This is where the R code in your R Markdown document gets sent to run.
The file/plot/pkg viewer is a handy browser for your current files, like finder, or file explorer, plots are where your plots appear, you can view packages, see the help files. And the environment / history pane contains the list of things you have created, and the past commands that you have run.
5.5 Exercise: RStudio default options
To first get set up, I highly recommend changing the following setting
Tools > Global Options (or Cmd + ,
on macOS)
Under the General tab:
- For workspace
- Uncheck restore .RData into workspace at startup
- Save workspace to .RData on exit : “Never”
- For History
- Uncheck "Always save history (even when not saving .RData)
- Uncheck “Remove duplicate entries in history”
This means that you won’t save the objects and other things that you create in your R session and reload them. This is important for two reasons
- Reproducibility: you don’t want to have objects from last week cluttering your session
- Privacy: you don’t want to save private data or other things to your session. You only want to read these in.
Your “history” is the commands that you have entered into R.
Additionally, not saving your history means that you won’t be relying on things that you typed in the last session, which is a good habit to get into!