CAMH R-stats Workshops
2019-05-29
Chapter 1 Prerequisites
1.1 Installing software
Please have these both installed (come early if you need help):
- R: Download from here
- MacOS users
- Click on the “Download R for (Mac) OS X” link at the top of the page
- Click on the
.pkg
file containing the latest version of R (currently 3.6.0) and save it to your computer. Double-click this file to run it and follow the installation instructions
- Windows users
- Click on the “Download R for Windows” link at the top of the page
- Click on the “base” link
- Click the “Download R 3.6.0 for Windows” and save the
.exe
file to your computer. Double click this file to run it and follow the installation instructions
- MacOS users
- RStudio: Download from here
- MacOS users
- Click on the latest Mac OS X version and save the
.dmg
file on your computer. Double-click the file to run it and follow the installation instructions
- Click on the latest Mac OS X version and save the
- Windows users
- Click on the latest Windows 7+ version and save the
.exe
file on your computer. Double-click the file to run it and follow the installation instructions
- Click on the latest Windows 7+ version and save the
- MacOS users
You may also use R and RStudio in a web browser. This method requires you to login with either a Gmail or GitHub account.
1.2 Downloading sample data
This book works from the following files of fake clinical data, that can be downloaded from the following links:
1.3 RStudio environment
Welcome to RStudio! You should see 4 window panes:
- Source
- Your script! everything you do to your data should be typed here!! It saves what you are
doing in a file ending in
.R
- Console
- The place where the good stuff happens. When you run a command, you see the output here.
- Enviroment/History
- Environment: a list of everything in your “Workspace”
- History: a list of every command you have run
- Files/Plots/Packages/Help
- Files: a file browser (like Windows Explorer or Finder)
- Plots: your plots will show up here
- Packages: a list of all the packages you have installed with checkboxes indicating whether they are loaded
- Help: your help documentation with be shown here
1.4 Loading libraries / installing packages
For this tutorial, we are going to use the packages tidyverse, tableone, rms and car. Please install them if you haven’t done so already.
install.packages(c("tidyverse", "rms", "tableone", "car"))
- Look at the Packages Tab
- Click on the check box to the left of “ggplot2”
- Notice that a bunch of lines start running in Console window to show you that the package is loading
- Go to the History Tab (top right corner)
- Notice that you should
library(ggplot2)
has just run - Click on these lines to highlight them, then click on To Source at the top of the panel
- This moves the lines we just ran into our script so we can re-run this step tomorrow!
1.5 Cheat Sheets
There are several cheat sheets available online that provide a quick reference when working with functions in the tidyverse.