Introduction to Programming in R

Materials for Summer 2020 Course taught by Myfanwy Johnston and Matt Espe for Cramer Fish Sciences.

This course has two primary emphases: programming (i.e., preparation in writing your own functions), and plotting (specifically: visualization with ggplot2).

Course videos are posted here: https://www.youtube.com/playlist?list=PLOj5McD9FWIwhPoZ-AKBUl-zrP_CZKtnm

Weekly materials are found in the /docs subdirectories of this repository.

Weekly Topics and Exercises

Week 1: Installation and File Navigation from R

Videos: Installing R and RStudio, and File Navigation in RStudio.

Reading: Good Practices in R, and Ihaka & Gentleman 1996. It's okay if you don't understand much of the paper; the exposure to the concepts and vocabulary alone will help you later.

No formal exercises this week - just download and install R and RStudio, and watch the file navigation videos. I encourage you to try to mimic some of the navigation from your own computer.

Week 2: Scripting; Data types and vectors

Videos: Intro to Scripting in R, and Data Types and Vectors.

Scripting exercise: Download the zipped course repository, unzip it, and open the RStudio project file. Then run the sea_mammal_EDA.R script on your own machine. Hint: you may need to install the two required libraries; see the code at the end of the video (~22:40) for help on that.

Vectors and data types exercise: download the vectors.R script from the R/ folder, and work through it in RStudio. The script will prompt you to try things on your own.

Week 3: Lists and logicals; manipulating data frames

Watch this week's first video, and work through the lists_and_logicals.R script along with it.

Watch this week's second video and follow along or work through the accompanying script.

Reading: Tidy Data.

Week 4: Plotting tidy data with ggplot2

Watch this week's ggplot2 part I video and follow along with the ggplot2_part1.R script. Do the exercises in the script marked "On Your Own".

Reading: Chapter 1 and Chapter 2 of Dr. Hadley Wickham's ggplot2: Elegant Graphics for Data Analysis book.

Optional: work through the factors script on your own.

Week 5: Visualization with ggplot2 part II, and elementary function writing

ggplot2 Part II video and lecture slides

Reading: Chapters ten, eleven, and twelve of the ggplot2 book.

Work through the ggplot2 part II R script.

Week 6: Scripting case studies: functions to summarize data, and advanced visualization.

Complete the Week 6 scripting assignment.

Resources


Specific topics

Dates and times in R: Bonnie Dixon's d-rug tutorial


R communities and forums

MiR: A Community for Underrepresented Minority Users of R (MiR).

RStudio community forum - a place to post R questions, can be a friendly alternative to Stack Overflow (especially for beginners).