Assignment 1: Using Git & GitHub

ENV 872 - EDA   |   Spring 2024   |   Instructors: Luana LimaJohn Fay  |  

– Due: 16-Jan –

:exclamation: Prior to tackling this assignment, you should have completed Module 0 (course setup) and Module 1 (intro to data analyitics).

Overview

In this assignment, you’ll experience the typical workflow of all future assignments:

  • Copying the assignment document, typically an R-markdown (.rmd) file, into your local Git-enabled workspace
  • Editing the R-markdown file in accordance with instructions provided
  • Knitting your completed R-markdown file into a PDF
  • Staging and committing all changes to your local Git repository
  • Pushing those changes to your remote GitHub repository

Completing this assignment will also reveal any issues you might have in your coding workspace setup, so please don’t hesitate to ask if you run into any questions or even if you are curious or uncertain about any of the steps in this workflow.


Task 1: Upload the assignment to your R project workspace

We distribute assignments as RMarkdown files (.rmd) that you will upload to your RStudio workspace and complete. Here is the process as applied to the Assignment01.Rmd file.

  • Download A01_Introduction.Rmd and move it into your local workspace, putting into the Assignments folder.

    :point_right: If you are using a container, navigate to the Files window in the Outputs pane (lower right). There you’ll see an Upload button which you can use to upload local documents into your containerized workspace. Note the other menu options you can use to manage (copy, move, delete) files from within RStudio.

    :point_right: If you are using a personal computer, you can access your project workspace easily from the Files window in the Outputs pane (lower right), by selecting :gear: More>Show Folder in New Window

  • Stage and commit the new document to your local Git repository.

    • Select the Git tab from the Environments Pane. You should any documents you added to your workspace listed with two gold “?” icons to the right of them. These icons indicate the file are not being tracked by Git: Git sees them, but it’s not received any instructions what to do with them.
    • Click the box under the “Staged” column to the right of any untraced files. The icon changes to a green “A” indicated the file has been added to Git’s staging area.
    • Now click the Commit button at the top of the Git pane. This will open a new Commit window. There you’ll see a list of the files in the staging areas (you can add and remove files from the staging area here as well.) And if you click on a file, you see changes to the file (if it’s a text file). Additions are in green, deletions are in red.
    • In the Commit Message area, type in a brief message that will identify this change to your repository. For example: “Initial commit of assignment 1”.
    • Then hit the Commit button: The files in the staging are have been committed to your local repository.
    • Close the Commit window.
  • Push the local commits to your remote GitHub repository.

    • Click the Push button in the Git window. This pushes the commits you just made in your local repository to your remote GitHub repository.
      *NOTE: If you are asked to provide your GitHub password, supply your PAT, not your password
    • Now open up your personal GitHub repository, and you should see that the local changes now appear on your remote repository.

    This is your introduction to Git’s versioning workflow: Basically, all files are in one of four states:

    • Untracked: files that are in your Git repository but are not actively being tracked by Git
    • Modified: files that have either been freshly added to the repository or have been changed since last being committed
    • Staged: one or more modified files that are being bundled to be committed to the Git repository under a single commit
    • Committed: files that have been committed and have not been changed since the last commit

    Once a file has been committed, we can revert to that file to the state it in which it was committed through other Git commands. Or, if we modify the file again, it will reappear as a “modified” file, awaiting to again be staged and committed.


    It’s also important to distinguish between changes in the local and the remote repository. Until you hit the Push button, changes are only saved locally. However once you push files, those changes are synchronized with your remote GitHub repository, and you can pull those changes to a different machine if you happen to be working with the same repository on multiple machines.

Task 2 - Open & edit the assignment Rmd file

  • Open the A01_Introduction.Rmd in RStudio by double clicking it in the Files window. This opens a new pane, the Source pane, with the RMarkdown file contents.

    :point_right: When you open an R-Markdown (Rmd) document, you may see a message requesting that to install some packages. You are encouraged to do so via the link provided, but that’s not the only way to install packages…

  • Follow the directions contained in the document. Pay attention to the instructions provided and be sure to answer all parts of each question asked! If anything is confusing or unclear, check Slack for updates or post your own question.

  • Stage and commit changes to your document whenever you make a significant change that you might want to roll back. Commits are cheap! Be sure to add useful messages to each commit.

    :point_right: Whenever you take a pause from your work, e.g. when you leave your computer for a prolonged time, stage, commit, and push your changes so that you have a remote backup of your work.


Task 3 - Knit & submit the document

When you’ve completed your assignment, you’ll convert your Rmd document into a professional looking PDF using the knitting process.

  • To knit the document, click the Knit button at the top of the Source pane window. After a few moments, you’ll see a new PDF document in your folder.

  • Submit this PDF to Sakai’s assignments section.

    :point_right: To download a document from your container, use the Export option under the :gear:More dropdown menu in the File Window.

  • You may want to stage, commit, and push your new PDF as well.