John M. Drake
The concept of literate programming
R Studio can be used to create static and dynamic reports including:
This presentation was made in R Studio
R Studio is an integrated development environment for statistically literate programming in R
[Tour of the R Studio interface]
Simple
More complicated
It is good practice to load libraries and perform any other document setup in the first code chunk
Packages we will use in this course
Packages can be installed using install.packages('package_name')
Packages can be loaded using the code snippet library(package_name)
?
commandExample
?lm
Some common tasks
Conditional execution
if
else
Grouping with curly braces {}
a<-5
if(a<1){
b<-5
c<-4
} else {
b<-10
}
print(b)
[1] 10
Looping
for
apply
family of functionsa<-c() #Note: use of `c` to create an empty object
for(i in 1:10){
a[i]<-i^3
}
print(a)
[1] 1 8 27 64 125 216 343 512 729 1000
magrittr
)Recommended reading:
Wickham, H. & G. Grolemund. 2016. R for Data Science. O'Reilly.