Intermediate-level programming with R

This lesson is for learners that are comfortable programming in R and want to learn some of R’s powerful tools for analyzing and visualizing data, literate programming, and debugging code.

The data used in this lesson are the citations and altmetrics for the PLOS journals from 2003-2010. The data set was compiled by Priem et al. 2012 (publication, code).

This lesson starts with a quick review of the basics of the Unix shell and programming with R.


Learners should be familiar working in the Unix shell and basic programming with R, e.g. writing functions.

Getting ready

You’ll need to install the following packages: rmarkdown, dplyr, ggplot2, and testit.


  1. Setting up a project
  2. Inspecting a file
  3. Using RStudio
  4. Importing and inspecting data
  5. R conditional statements
  6. R loops
  7. Functions in R

  8. Writing in Markdown
  9. Writing in R Markdown
  10. Using knitr chunk options
  11. R Markdown output options

  12. Subsetting data with dplyr
  13. Using pipes with dplyr
  14. Summarizing data with dplyr

  15. Starting with ggplot2 - Map data to plot aesthetics
  16. Control data mapping with scales
  17. Creating subplots with facets
  18. Creating different plots with geoms
  19. Customizing plot appearance with themes

  20. Debugging with debug
  21. Debugging with browser
  22. Debugging with recover

  23. Defensive programming with stopifnot
  24. Testing with testit

Other Resources