The engine
The dashboard
A tour of RStudio
R is awaiting your instructions
Type code here, press enter, and R will run it
Type 2 + 2
in the console
Press enter
2 + 2
## [1] 4
This is ephemeral though.
If you want to run this again, you'll have to type it again.
Store R code in a document instead
All the files in your current working directory
Find 01_getting-started.Rmd
Click on its name to open the file
Documents
open here
Document format that
combines text and code
Acts like a notebook
for your analysis
Text
Text
Code
Text
Code
Output
Read the instructions
Run the code chunk by
clicking the play button
Add a new chunk
Put 2 + 2
in the chunk and run it
"Knit" an R Markdown document into a standalone sharable file
The best way to combine R code and narrative
We'll use it throughout the class:
I'll provide starter code
You'll complete "Your turns"
In the end, you'll have an annotated record for yourself
Spot the difference:
filter(mtcars, cyl == 4)
four_cyls <- filter(mtcars, cyl == 4)
Find these chunks in the notebook and run them.
What's different about what happens?
<-
assigns the output from the righthand side to a variable with the name on the lefthand side
four_cyls <- filter(mtcars, cyl == 4)
List of all the
variables you've created
Find four_cyls
in the environment pane.
Click on the name four_cyls
What happens?
Clicking on an object in the environment panel opens it an interactive viewer tab
four_cyls <- filter(mtcars, cyl == 4)
Functions do things
four_cyls <- filter(mtcars, cyl == 4)
Functions do things
Functions take arguments, output results
four_cyls <- filter(mtcars, cyl == 4)
Functions do things
Functions take arguments, output results
If you want to keep the output, assign it to a variable
To look up the help page for an R function,
type this in the console:
?function_name
(Or google it!)
These help pages prove details about the arguments you can supply a function
Often full of examples
at the bottom
Look at the help page for seq
Add a chunk that uses seq()
to create a
list of numbers from 5 to 100, spaced by 5
(so 5, 10, 15, 20, …)
02:00
seq(from = 5, to = 100, by = 5)
## [1] 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95## [20] 100
Missing closing parentheses or quotes
mean(mtcars
"Oops this is wrong
Surrounding something in quotes when it should be (or vice versa)
mean("mtcars")
## Warning in mean.default("mtcars"): argument is not numeric or logical: returning## NA
## [1] NA
There are three chunks under "Syntax gone wrong"
Run each, read the error message, and try to fix the syntax
Go to Help > Cheatsheets to find quick
reference guides to different packages
Data basics
The engine
The dashboard
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
o | Tile View: Overview of Slides |
Esc | Back to slideshow |
The engine
The dashboard
A tour of RStudio
R is awaiting your instructions
Type code here, press enter, and R will run it
Type 2 + 2
in the console
Press enter
2 + 2
## [1] 4
This is ephemeral though.
If you want to run this again, you'll have to type it again.
Store R code in a document instead
All the files in your current working directory
Find 01_getting-started.Rmd
Click on its name to open the file
Documents
open here
Document format that
combines text and code
Acts like a notebook
for your analysis
Text
Text
Code
Text
Code
Output
Read the instructions
Run the code chunk by
clicking the play button
Add a new chunk
Put 2 + 2
in the chunk and run it
"Knit" an R Markdown document into a standalone sharable file
The best way to combine R code and narrative
We'll use it throughout the class:
I'll provide starter code
You'll complete "Your turns"
In the end, you'll have an annotated record for yourself
Spot the difference:
filter(mtcars, cyl == 4)
four_cyls <- filter(mtcars, cyl == 4)
Find these chunks in the notebook and run them.
What's different about what happens?
<-
assigns the output from the righthand side to a variable with the name on the lefthand side
four_cyls <- filter(mtcars, cyl == 4)
List of all the
variables you've created
Find four_cyls
in the environment pane.
Click on the name four_cyls
What happens?
Clicking on an object in the environment panel opens it an interactive viewer tab
four_cyls <- filter(mtcars, cyl == 4)
Functions do things
four_cyls <- filter(mtcars, cyl == 4)
Functions do things
Functions take arguments, output results
four_cyls <- filter(mtcars, cyl == 4)
Functions do things
Functions take arguments, output results
If you want to keep the output, assign it to a variable
To look up the help page for an R function,
type this in the console:
?function_name
(Or google it!)
These help pages prove details about the arguments you can supply a function
Often full of examples
at the bottom
Look at the help page for seq
Add a chunk that uses seq()
to create a
list of numbers from 5 to 100, spaced by 5
(so 5, 10, 15, 20, …)
02:00
seq(from = 5, to = 100, by = 5)
## [1] 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95## [20] 100
Missing closing parentheses or quotes
mean(mtcars
"Oops this is wrong
Surrounding something in quotes when it should be (or vice versa)
mean("mtcars")
## Warning in mean.default("mtcars"): argument is not numeric or logical: returning## NA
## [1] NA
There are three chunks under "Syntax gone wrong"
Run each, read the error message, and try to fix the syntax
Go to Help > Cheatsheets to find quick
reference guides to different packages
Data basics