Notes from a guest lecture I delivered in March 2019 at the Department of Computer Science at Stella Maris College, Chennai, offering a simple introduction to GitHub with R and R Markdown.
But what is version control?
- Simple analogy: Google Drive for developers - Track and manage changes to your code - Version control lets developers safely work through branching and merging - Work with online Git repository - Make changes in your own branch - Merge with online cloud branch - Changes are tracked and can be reverted if needed
Make your account and install into RStudio
install.packages("devtools")- If this doesn't work, you might need to update your R - Update at https://www.r-project.org/
Start your first project
More information: https://www.datacamp.com/community/tutorials/git-setup
Very simple guide on the workflow: http://rogerdudler.github.io/git-guide/
A more detailed guide: https://happygitwithr.com/rstudio-git-github.html
man git in Shell for help
git commit -m "Commit message"
git push origin master
“R Markdown is a file format for making dynamic documents with R. An R Markdown document is written in markdown (an easy-to-write plain text format) and contains chunks of embedded R code, like the document below.” - https://rmarkdown.rstudio.com/articles_intro.html
Very simple. Next time you make a new file, make it a R Markdown file instead of a R script and save it as
A mini-R-script in the middle of your text, headings, etc. in Markdown
library(tidyverse) # Making a random dummy dataframe x <- data.frame(replicate(5,sample(0:1,1000,rep=TRUE))) # Print three rows of our dummy df x[1:3,]
## X1 X2 X3 X4 X5 ## 1 1 0 0 0 0 ## 2 1 1 0 1 0 ## 3 0 1 1 1 0
You might not want to show your code, the warnings, and messages but show the output—Rmd let's you control that.
E.g.: There's a hidden chunk below but you'll only see the table it outputs:
You can also initialize a setup chunk with global chunk options like below.
knitr::opts_chunk$set(include = TRUE, warning = FALSE) # Random chunk options
Here's a cheat sheet!
Cmd or Ctrl + Shift + Kto knit to chosen format
Alternately, edit the YAML header at the top of the file. Options include:
pdf_document: default word_document: default html_document: default