Course information

Download a pdf of the lecture slides covering this topic.

0.1 Course overview

This book is for Colorado State University’s R Programming for Research courses (ERHS 535, ERHS 581A3, and ERHS 581A4). The courses offer in-depth instruction on data collection, data management, programming, and visualization, using data examples relevant to data-intensive research.

0.2 Course syllabus

The syllabus for ERHS 535 is available for download by clicking here. The syllabus for ERHS 581A3 is available for download by clicking here.

0.3 Time and place

Students for ERHS 535, ERHS 581A3, and ERHS 581A4 will meet together. Students in ERHS 535 will meet for the entire semester, completing a three-credit course. Students in ERHS 581A3 will meet for the first five weeks of the semester, completing a one-credit course. Students in ERHS 581A4 will meet from the sixth week to the final week of the semester, completing a two-credit course.

The course meets in a mixed format, with about two hours of asynchronous video lectures per week and about two hours of in-person meeting time. Course lectures are provided through YouTube videos. These are embedded in the online course book, and the book also provides links to playlists for each chapter of all the videos for that chapter.

Exceptions to the regular live meeting times are:

  • There will be no meeting on Labor Day.
  • There are no course meetings the week of Thanksgiving.

0.4 Detailed schedule

Here is a more detailed view of the schedule for this course for Fall 2023:

Week Class date Videos In-class exercises Graded items
1 Aug. 21 None Ch 0: 0.7.1–0.7.3
1 Aug. 23 Ch 1, Videos 1–9 Ch 1: 1.10.3–1.10.10
2 Aug. 28 Ch 1, Video 10; Ch 2, Videos 1–4 Ch 2: 2.7.1–2.7.3
2 Aug. 30 Ch 2, Videos 5–10 Ch 2: 2.7.4–2.7.6 Quiz 1
3 Sept. 6 Ch 3, Videos 1–5 Ch 3: 3.8.1—3.8.3 Quiz 2
4 Sept. 11 Ch 3, Videos 6–10 Ch 3: 3.8.4–3.8.5 HW 1 due
4 Sept. 13 Ch 4, Videos 1–4 Ch 3: 3.8.6; Ch 4: 4.10.1 Quiz 3
5 Sept. 18 Ch 4, Videos 5–7 Ch 4: 4.10.2–4.10.3
5 Sept. 20 Ch 5, Videos 1–4 Ch 5: 5.6.1–5.6.4 Quiz 4
6 Sept. 25 Ch 5, Videos 5–6, Ch 6, Videos 1–3 Ch 6: 6.7.1–6.7.2
6 Sept. 27 Ch 6, Videos 4–8 Ch 6: 6.7.2–6.7.3 Quiz 5, HW 2 due
7 Oct. 2 Ch 6, Videos 9–12 Ch 6: 6.7.4–6.7.5
7 Oct. 4 No videos Work on Q4 from HW 3 Quiz 6
8 Oct. 9 Ch 7, Videos 1–3 Ch 7: 7.8.2–7.8.3
8 Oct. 11 Ch 7, Videos 4–5 Ch 7: 7.8.3 Quiz 7
9 Oct. 16 Ch 7, Videos 6 (Optional: Ch 7, Videos 7–8) Ch 7: 7.8.4–7.8.5
9 Oct. 18 Ch 7, Videos 9–11 Ch 7: 7.8.6 Quiz 8, HW 3 due
10 Oct. 23 Ch 7, Videos 12–14 Ch 7: 7.8.7
10 Oct. 25 Ch 8, Video 1 Ch 8: 8.5.1–8.5.2 Quiz 9
11 Oct. 30 Ch 8, Videos 2–3 Ch 8: 8.5.3
11 Nov. 1 No videos Ch 8: 8.5.4 HW 4 due
12 Nov. 6 Ch 9, Videos 1–5 Guest lecture
12 Nov. 8 Ch 9, Videos 6–9 Ch 9: 9.4.1–9.4.3
13 Nov. 13 No videos Group work on final project
13 Nov 15 Ch 12, Videos 1–3 Group work on final project
14 Nov. 27 Ch 12, Videos 4–5 Group work on final project HW 5 due
14 Nov. 29 Ch 10, Videos 1–3 Group work on final project
15 Dec. 4 Ch 10, Videos 4–5 Group work on final project
15 Dec. 6 No videos Group work on final project HW 6 due

Students in ERHS 581A3 will be in weeks 1–5 of this schedule. Students in ERHS 581A4 will be in weeks 6–16 of this schedule.

0.5 Final group project

You will do the final group project in groups of 3–4. The final product will be a flexdashboard (html created from RMarkdown file) that presents interesting facets of a dataset to viewers and allows them to interact in at least some of the panes. There is more information about flexdashboards available at https://rmarkdown.rstudio.com/flexdashboard/examples.html.

Your group’s dashboard should include a text block somewhere on the dashboard that explains the data (including the data source) as well as what the dashboard can be used to explore and how to navigate it (for example, see the left-most pane in this dashboard: https://walkerke.shinyapps.io/neighborhood_diversity/). Besides this text block, your dashboard show have at least three panes with output (figures or tables). At least one should be interactive (using htmlwidgets). You may include everything in a single page (like https://beta.rstudioconnect.com/jjallaire/htmlwidgets-waste-sites/htmlwidgets-waste-sites.html) or you can spread results and text across several tabs of a dashboard (like https://walkerke.shinyapps.io/neighborhood_diversity/#explore-metros and https://beta.rstudioconnect.com/jjallaire/htmlwidgets-showcase-storyboard/htmlwidgets-showcase-storyboard.html).

There is extensive documentation about building flexdashboards here: https://rmarkdown.rstudio.com/flexdashboard/using.html. To divide group work, you may find it helpful to have some group members work on designing and setting up the framework for the dashboard, and then other members focus on writing the code for the figures and tables that will go in specific panes of the dashboard. Everything can then be put together by moving the code for those figures and tables into the flexdashboard Rmarkdown file.

You will have in-class group work time to work on this during the in-person sessions. This project will also require some work with your group outside of class. I will provide feedback and help during the in-class group work time.

The final group project will be graded with A through F, with the following point values (out of 30 possible):

  • 30 points for an A
  • 25 points for a B
  • 20 points for a C
  • 15 points for a D
  • 10 points for an F

If you turn nothing in, you will get 0 points.

0.5.0.1 Final presentation

  • In total, the group’s presentation should last 15 minutes. There will then be 5 minutes for questions.
  • Split the presentation up into two parts: (1) an overview of your flexdashboard (about 7 minutes) and (2) a tutorial-style discussion of how you used R to do the project (about 8 minutes).
  • The overview of your flexdashboard should:
    • Explain the data sources for your dashboard
    • Explain what a user should be able to explore or understand by using your dashboard
    • Walk viewers through each pane in the flexdashboard and how any interactive elements can be used
  • The tutorial part should include the following sections:
    • Interesting packages / techniques: Spend a bit more time on any parts that you found particularly interesting or exciting. Were there packages you used that were helpful that we haven’t talked about in class? Did you find out how to do anything that you think other students could use in the future? Did you end up writing a lot of functions to use? Did you have an interesting way of sharing code and data among your group members?
    • Lessons learned: If you were to do this project again from scratch, what would you do differently? Were there any big wrong turns along the way? Did you find out how to do something late in the project that would have saved you time if you’d started using it earlier?

0.5.0.2 Flexdashboard

The grade for the flexdashboard will be based on the following criteria:

  • It should work.
  • It should include text that is clearly written, without grammatical errors or typos. Any graphics are easily to interpret and follow some of the principles of good graphics covered in class.
  • It includes at least three rendered outputs (e.g., plots, tables). At least one should be interactive.
  • It is self-contained—in other words, a user shouldn’t need to hear you explain the dashboard to understand it. It should include enough information on the app for a user to figure out how to use the app and interpret the output.

0.6 Course set-up

Please download and install the latest version of R and RStudio (Desktop version, Open Source edition) installed. Both are free for anyone to download.

Students in ERHS 535 and ERHS 581A4 will also need to download and install a version of LaTeX (MikTeX for Windows and MacTeX for Macs). They will also need to download and install git software and create a GitHub account.

Here are useful links for this set-up:

0.7 Coursebook

This coursebook will serve as the only required textbook for this course. I am still in the process of editing and adding to this book, so content may change somewhat over the semester (particularly for later weeks, which is currently in a rawer draft than the beginning of the book). We typically cover about a chapter of the book each week of the course.

This coursebook includes:

  • Embedded video lectures for the course
  • Links to the slides presented in video lectures for each topic
  • In-course exercises, typically including links to the data used in the exercise
  • An appendix with homework assignments
  • A list of vocabulary and concepts that should be mastered for each quiz

If you find any typos or bugs, or if you have any suggestions for how the book can be improved, feel free to post it on the book’s GitHub Issues page.

This book was developed using Yihui Xie’s wonderful bookdown framework. The book is built using code that combines R code, data, and text to create a book for which R code and examples can be re-executed every time the book is re-built, which helps identify bugs and broken code examples quickly. The online book is hosted using GitHub’s free GitHub Pages. All material for this book is available and can be explored at the book’s GitHub repository.

0.7.1 Other helpful books (not required)

The best book to supplement the coursebook and lectures for this course is R for Data Science, by Garrett Grolemund and Hadley Wickham. The entire book is freely available online through the same format at the coursebook. You can also purchase a paper version of the book (published by O’Reilly) through Amazon, Barnes & Noble, etc., for around $40. This book is an excellent and up-to-date reference by some of the best R programmers in the world.

There are a number of other useful books available on general R programming, including:

The R programming language is used extensively within certain fields, including statistics and bioinformatics. If you are using R for a specific type of analysis, you will be able to find many books with advice on using R for both general and specific statistical analysis, including many available in print or online through the CSU library.

0.8 In-course Exercise Chapter 0

Today, we’ll practice doing an in-course exercise. The purpose of this in-course exercise is to help you explore the online book and videos for this class to make sure that you are comfortable with navigating those resources. You will work on this for about 20 minutes.

The last prompt requires you to have RStudio installed. If nobody in the group has RStudio installed, you can read through this part without doing the activities.

0.8.2 Find the video lectures

  • Look through the book to find links to the YouTube video lectures for Chapter 1 (“R Preliminaries”). You should be able to find:
    • Embedded videos throughout the text
    • Links to download the pdfs for each video below each embedded video
    • A link to a YouTube playlist with all the video lectures for the chapter at the beginning of the chapter text.
  • Download the pdf copy of the slides for the first video lecture for Chapter 1.
  • Watch the very beginning of the first video lecture for Chapter 1.
  • You will need to watch the first nine video lectures for Chapter 1 before we meet on Wednesday.
    • What are the titles of these nine videos?
    • What is the title of the only video for Chapter 1 that you are not required to watch before Wednesday’s meeting?

0.8.3 Try coding a bit

  • Open RStudio
  • Open an R script by going to “File” -> “New File” -> “R Script”
  • Type the following code in the R script:
sample(c("Johnny", "Waylon", "Willie", "Kris"))
  • Highlight the code you just typed and then click the “Run” bottom on the top right of the script file. Look in the “Console” pane of RStudio. What output do you see?
  • In the script, replace each name with the name of a member of your group. Re-run the code by highlighting it again and the pressing the “Run” button. What output do you see in the console?
  • Without changing the code, highlight and run it three more times. Is the output the same each time?
  • Click your cursor in the R script pane and then save this R script by going to “File” -> “Save”. Save the file somewhere that’s easy to find, like on your Desktop (you can delete it after today). Save it with the name “example.R”.