ETC5513: Collaborative and Reproducible Practices

Tutorial 6

Author

Michael Lydeamore

Published

21 May 2024

🎯 Objectives

  • Create repos in GitHub and clone them into your local computer
  • Practice staging, commit and push workflow
  • Work in a GitHub project as a collaborator
  • Create branches in local and remote repositories
  • Merging branches and deal with conflicts
  • Practice pull requests.

Exercise 1: Working on reproducible reports as a collaborator

  1. Create a new private GitHub repository called Tutorial6-XX and replace XX with your initials. Include a README.md file.
  1. Invite one of your classmates to collaborate in your project. You can do that from GitHub
  1. Accept the invitation and clone your classmate’s repo in your local machine.
  1. Continue working in your classmate repo and create a new branch called newbranchXX (replace XX with your initials).
  1. In the new branch add a file called Tutorial6XX.qmd (replace XX with your initials). This file should render into html and should have title “Tutorial 6. Collaborating with others” and your name as author.
  1. Add global options for figures sizes and location.
    Hint: knitr::opts_chunk
  1. Stage, commit and push changes into your classmate repo
  1. Create a new section called “Libraries” and add an R code chunk to load the tidyverse and gridExtra libraries.
  1. Stage, commit and push data into your classmate repo
  1. Create another section with title “Generating data from a normal distribution with mean 0 and variance 1” and add the following code:
# Simulating data according to a normal distribution

x <- seq(1:100)
y <- rnorm(100)  # Generating data form a normal distribution with mean 0 and variance  1

data <- data.frame(x = x, y = y )    # Creating a data frame

p1 <- ggplot(data, aes(x = x, y = y)) +
   geom_line()

p2 <- ggplot(data, aes(x = x, y = y)) +
   geom_point()

grid.arrange(p1, p2)
  1. Stage, commit and push data into your classmate repo
  1. Merge your branch into the main.
  1. Stage, commit and push data into your classmate repo
  1. In your GitHub you should have both your repo and your classmate repo. Go to GitHub and have a look at the repos you have and the commits. You should have both your repo and your partner’s repo. In the last commit in both repos you should have the same content by the end of the exercise.

Collaborating with others using pull request (work in pairs for this exercise)

  1. Create a new public GitHub repository called Tutorial6fork-XX and replace XX with your initials. Include a README.md file.

  2. Clone this repo into your local machine.

  3. Create an R project from an existing directory using the directory/folder that you just cloned from GitHub. After you have created the project check that you have a new file in the folder with extension .Rproj. You can also use that file to open a new instance of Rstudio.

  1. Add Tutorial6XX.Rmd from the exercise above into this project. You can simply copy it from the other folder/directory into the new folder/directory that you have created for this new project.
  1. Stage changes, commit and push changes to the remote repository.
  1. Exchange your GitHub repo details with your classmate and fork each others project.
  1. Fork each others repository in your GitHub and clone a local copy.
  1. Create a new branch and work on this branch.
  1. Add a new section and a figure into the report.
  1. Stage, commit and push the changes into your remote repo in GitHub.
  1. Once you have finished with all the changes merge your new branch into main.
  1. Create a pull request explaining the changes.
  1. Revise the pull request and accept the proposed changes.
  1. Solve any possible conflict and merge the changes into your original repo that you created in exercise 1.
  1. If you have time repeat steps 8-14 adding more changes in your pull request.