I’ll be using github to give you your homeworks, you’ll be using it to submit homeworks. Today in lab, you’ll practice this workflow in preparation for your first homework.
By the end of lab you should be able to:
Sign up for github. Remember this advice about picking a username. Remember your username and password, you’ll need them again soon.
Sign up for rstudio.cloud, then join the ST541 Fall 2018 workspace by following this link
Your Turn:
README.md
. What’s in this file?To actually to do some work on your homework, you’ll “clone” this repository to rstudio.cloud as a project.
In github, click the “Clone or Download” button, then copy the URL given to the clipboard.
Head to the ST541 Fall 2018 workspace on RStudio Cloud, click the small arrow next to “New Project” and select “New project from Git repo”.
Paste in the Clone URL you copied earlier. You’ll be prompted for your github username and password. RStudio Cloud will then clone your repo into an RStudio Project.
Take a look through the files in the Files pane. How do these compare to those on github?
There are a few things we need to do to tell git who we are before working on this project. (You’ll need to do this with each new project in RStudio Cloud).
In the Terminal in your RStudio Cloud project, copying the following, but substituting in your name and email address:
git config --global user.email "your email here"
git config --global user.name "your name here"
git config --global credential.helper 'cache --timeout 3600'
The last line extends the time interval that our github username and password are valid for, so you should only be asked for it once more in lab. You can use the line:
git config --global --list
to check you’ve set them correctly.
The link between your project in RStudio and the files on github isn’t dynamic. The files on github are only updated when you ask them to be. The workflow I encourage is:
Let’s work through those steps to complete the first task on Homework 1.
In your project in RStudio Cloud open up README.md
. You might like to compare the contents of this file to that shown in your repo on github.com.
README.md is a Markdown file, a plain text format that allows for simple formatting like section headings and lists. On Github Markdown files get rendered into a nice formatted preview.
Do some work Edit README.md
in RStudio Cloud to add your name after Name:
in the file. Save the file.
Right now this edit just lives in your project on RStudio cloud, for me to be able to see you’ve completed this task, you’ll have to commit the change to git, then push the change to github.
Commit In the Git pane, you’ll see the file README.md
because it has changed since from the most recent version committed. To commit this change, we need to stage the file (check the box next to its name), then commit.
A new window will open. You can browse any changed file here and see what has changed (although only those that are staged will be commited). In the “Commit message” area, describe the change you’ve made then hit the Commit button.
Push This change still only lives here in RStudio, to send it to github, hit Push.
Head back to Github and see your change is now recorded there.
Your Turn: Practice this workflow again by editing README.md
to check off the first task. Add an x
between the [ ]
next to the first task, commit, and push. Take a look on github to see the result.
Markdown only adds formatting for plain text. It doesn’t recognize R code. For that we need Rmarkdown.
Open 03-vectors-in-R.Rmd, an Rmarkdown file. If you haven’t seen RMarkdown before you should work though this set of lessons.
Take a look at the YAML header, the bit between the ---
. Here, we are asking for an HTML output, but also to keep the intermediate Markdown (md) file.
Knit the file and verify it produces both 03-vectors-in-R.md and 03-vectors-in-R.html.
Commit and push both 03-vectors-in-R.md and 03-vectors-in-R.html
Head to Github and compare the three documents. Which file looks best on github? Which file do you need to edit to complete the assignment?
Completing the homework now just involves completing all the tasks as set out in README.md.
When you are done and are ready to submit, first check you’ve pushed all your changes to github. Head to github and check the files there reflect what you want to be graded.
When you are ready, head to canvas and submit your github repository URL in the Homework 1 assignment. This signals that you are ready for your work to be graded.
We will grade all commits up to the due date.
If you have time, you might want to read through the other tasks in Homework 1 and pick one to get started on.
You are welcome to complete all your work on your local computer without using RStudio Cloud, however you will need to get git installed and talking to RStudio. Follow chapters 4 through 13 in Happy Git and GitHub for the useR to get there.
Why are we using git/github? It’s a fantastic way to organize the myriad of files we generate in any data analysis project and facilitates sharing and collaboration.
If you want to know more, I’d read Sections 1-4 of:
Bryan J. (2017) Excuse me, do you have a moment to talk about version control? PeerJ Preprints 5:e3159v2 https://doi.org/10.7287/peerj.preprints.3159v2