R for Reproducible Scientific Analysis

an introduction to R for non-programmers using gapminder data

The goal of this lesson is to teach novice programmers to write modular code and best practices for using R for data analysis. R is commonly used in many scientific disciplines for statistical analysis and its array of third-party packages. We find that many scientists who come to Software Carpentry workshops use R and want to learn more. The emphasis of these materials is to give attendees a strong foundation in the fundamentals of R, and to teach best practices for scientific computing: breaking down analyses into modular units, task automation, and encapsulation.

Note that this workshop will focus on teaching the fundamentals of the programming language R, and will not teach statistical analysis.

The lesson contains more material than can be taught in a day. The instructor notes page has some suggested lesson plans suitable for a one or half day workshop.

A variety of third party packages are used throughout this workshop. These are not necessarily the best, nor are they comprehensive, but they are packages we find useful, and have been chosen primarily for their usability.


Understand that computers store data and instructions (programs, scripts etc.) in files. Files are organised in directories (folders). Know how to access files not in the working directory by specifying the path.


Setup Download files required for the lesson
00:00 1. Introduction to R and RStudio What is R?
How to find your way around RStudio?
How to manage projects?
How can I do calculus?
What are objects and packages?
What are data types and data structures?
How do I access subsets of my data?
How do I read and write data?
01:30 2. Loops and functions How can I iterate over (specific) tasks?
How can I write a new function in R?
What tools does R provide to debug my code?
03:00 3. Dataframe Manipulation with tidyr How can I change the format of dataframes?
03:45 4. Dataframe Manipulation with dplyr How can I manipulate dataframes without repeating myself?
04:40 5. Creating Publication-Quality Graphics with ggplot2 How can I create publication-quality graphics in R?
06:00 Finish

The actual schedule may vary slightly depending on the topics and exercises chosen by the instructor.