Introduction

In a browser:

Benefits of version control

Version control using RStudio/Git/Github

Getting started

  1. File -> New Project -> New Directory -> Empty Project
  2. Choose where to put your project
  3. Select Create a git repository
  4. In the upper right window you’ll see a Git tab

Exercise 1

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)
}

Exercise 2

Setup a Github account and email me your username

Remotes

Draw origin-local figure throughout this section

Add a remote

Exercise 5

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)
}

Exercise 6

Partner quietly pushes the following code

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()
}

Collaborating

Exercise 7