Remind students to setup a GitHub account and email the instructor their username.

Arrange to have a teaching partner attend class and push the following code for the ‘Collaborating’ demo.

get_size_class_ts_data <- function(df){
  # Convert individual data to time-series data for each of a set of size classes
  # Input: data frame with a year column for time
  #        and a size_class column
  ts_data <-
    df %>% 
    group_by(year, size_class) %>% 
    summarize(counts = n())
  return(ts_data)
}

plot_ts_data <- function(df){
  # Plot time-series data by size class
  # Input: data frame with year, size_class, and counts columns
  ggplot(df, aes(x = year, y = counts, color = size_class)) +
    geom_line()
}

Open the following links in a browser and zoom in to make the images fill the screen.

Introduction

Motivation

Benefits of version control

Version control using RStudio & Git

Getting started

  1. File -> New Project -> New Directory -> Empty Project
  2. Choose where to put your project.
  3. Select Create a git repository.
  4. Check to make sure you have a you have a Git tab in the upper right window.

Do Exercise 1 - Set-up Git.

First commit

The following example uses the code from the problem decomposition lecture.

get_data <- function() {
  data <- read.csv("surveys.csv")
  return(data)
}

data <- get_data()

Building a history

get_size_class <- function(weight) {
  if (weight > 50){
    size_class = "large"
  } else {
    size_class = "small"
  }
  return(size_class)
}
get_size_class <- function(weight, threshold){
  if (weight > threshold){
    size_class = "large"
  } else {
    size_class = "small"
  }
  return(size_class)
}

Do Exercise 2 - First Commit.

GitHub Remotes

Draw diagram to link local machine with GitHub origin.

Add a remote

Do Exercise 5 - Adding a Remote.

Push to a remote

add_size_classes <- function(df) {
  # Add size class data to a data frame
  # Input: data frame with weight column containing size information
  data_size_class <-
    df %>% 
    na.omit() %>% 
    rowwise() %>% 
    mutate(size_class = get_size_class(weight, 50))
  return(data_size_class)
}

Do Exercise 6 - Pushing Changes.

Collaborating

Do Exercise 7 - Pulling and Pushing.