GitHub pre-requisites
We assume the following
Have a decent README.md
In the first homework you created a top-level README.md
for your repository. Keep it in good shape! You are allowed to edit it!
Authoring Markdown files
Throughout this course, any basic text document should be written in Markdown and should always have a filename that ends in .md
. These files are pleasant to write and read, but are also easily converted into HTML and other output formats. GitHub provides an attractive HTML-like preview for Markdown documents. RStudio’s “Preview HTML” button will compile the open document to actual HTML and open a preview.
Whenever you are editing Markdown documents in RStudio, you can display a Markdown cheatsheet by clicking the question Mark ?
at the top of the editor pane.
Authoring R Markdown files
If your document is describing a data analysis, author it in R Markdown, which is like Markdown, but with the addition of R “code chunks” that are runnable. The filename should end in .Rmd
or .rmd
. RStudio’s “Knit HTML” button will compile the open document to actual HTML and open a preview.
Whenever you are editing R Markdown documents in RStudio, click the question Mark ?
at the top of the editor pane to display a Markdown cheatsheet or visit RStudio’s R Markdown website.
Here is our introductory tutorial on rendering R Markdown.
- Make sure to keep, commit, push the intermediate
.md
file and any figures.
- Expose your code, i.e. use chunk option
echo = FALSE
very sparingly.
Organization of your coursework repository
As the course goes on, you will accumulate many files in your repository. In due course, we will discuss the of use sub-directories to organize things.
BTW we truly mean directories or “folders” – NOT a Git branch or anything fancy like that!
You have a top-level README.md
for your repository. Once you create sub-directories, you may also want to have a README.md
file in each sub-directory to serve as a landing pages for, e.g., a homework assignment or a data directory.
As you get more advanced, here is more advice about making your GitHub repo very browsable.
Which files to commit
- Always commit the main source document, e.g., the R script or R Markdown or Markdown document. Commit early, commit often!
- For R Markdown source, also commit the intermediate Markdown (
.md
) file and any accompaying files, such as figures.
- Some purists would say intermediate and downstream products do NOT belong in the repo. After all, you can always recreate them from source, right? But here in reality, it turns out to be incredibly handy to have this in the repo.
- Commit the end product HTML (
.html
) file.
- See above comment re: version control purists vs. pragmatists.
- You may not want to commit the Markdown and HTML until the work is fairly advanced, maybe even until submission. Once these enter the repo, you really should recompile them each time you commit changes to the R Markdown source, so that the Git history reflects the way these files should evolve as an ensemble.
- Never ever edit the intermediate/output documents “by hand”. Only edit the source and then regenerate the downstream products from that.
How to submit homework
- Make sure you have
- Saved all the files associated with your solution locally.
- Commited all those files to your local Git repository.
- Pushed the current state of your local repo to GitHub.
- Open an issue, link to the latest commit, and tag the staff:
- Visit your GitHub repo in a web browser.
- Just above the file list, look for “latest commit” followed by ten numbers and letters (called the revision SHA) and a clipboard icon.
- Click the clipboard icon to copy the revision SHA to your clipboard.
- Click on “Issues”, then on “New Issue”. Name the issue “Mark homework x of firstname-lastname”, where x is, 1, 2, ….
- In the issue description, tag Jenny by including the text
@jennybc
, and paste the revision SHA. Include a link to exactly where you want a reviewer to go.
- Click “Submit new issue”. You’re done! Congratulations!
Make your work shine!
Here are some minor tweaks that can make a big difference in how awesome your product is.
Make it easy for people to access your work
Reduce the friction for TAs and profs to get the hard-working source code (the R markdown) and the front-facing report (HTML).
- Create a
README.md
in the homework’s subdirectory to serve as the landing page for your submission. Whenever anyone visits this subdirectory of your repo, this will be automatically rendered nicely! In particular, hyperlinks will work.
- With this
README.md
file, create annotated links to the documents TAs and profs will need to access. Such as:
- Your main R markdown document.
- The intermediate Markdown product that comes from knitting your main R markdown document. Remember GitHub will render this into pseudo-HTML automagically. Remember the figures in
figures/
need to be available in the repo in order appear here.
- The final pretty HTML report. Read instructions below on how access the pretty, not the ugly source.
If you want to see an example of a README.md
that links to and explains a bunch of files in the same repo + subdirectory, you can look at this example from STAT 545A 2013.
Make it easy for others to run your code
- In exactly one, very early R chunk, load any necessary packages, so your dependencies are obvious.
- In exactly one, very early R chunk, import anything coming from an external file. This will make it easy for someone to see which data files are required, edit to reflect their locals paths if necessary, etc. There are situations where you might not keep data in the repo itself.
- Pretend you are someone else. Clone a fresh copy of your own repo from GitHub, fire up a new RStudio session and try to knit your R markdown file. Does it “just work”? It should!
Make pretty tables
Instead of just printing an object with R, you could format the info in an attractive table. Some leads: