Chapter 4 Version Control with Git and GitHub

Version Control is not required but highly recommended. Make sure Git is installed on your computer.

4.1 Git for version control

To add Git support, execute:

use_git()

It will ask a few questions (answer Yes to them) and will restart RStudio:

use_git()
> ✔ Initialising Git repo
> ✔ Adding '.Rhistory', '.Rdata', '.httr-oauth', '.DS_Store' to '.gitignore'

4.2 GitHub for sharing package with others

Let’s publish our package on a GitHub:

> use_github()
✓ Creating GitHub repository 'katgit/myutils'
✓ Setting remote 'origin' to 'https://github.com/katgit/myutils.git'
✓ Setting URL field in DESCRIPTION to 'https://github.com/katgit/myutils'
✓ Setting BugReports field in DESCRIPTION to 'https://github.com/katgit/myutils/issues'
There is 1 uncommitted file:
* 'DESCRIPTION'
Is it ok to commit it?

1: Absolutely not
2: Yup
3: No way

Selection: 2
✓ Adding files
✓ Making a commit with message 'Add GitHub links to DESCRIPTION'
✓ Pushing 'master' branch to GitHub and setting 'origin/master' as upstream branch
✓ Opening URL 'https://github.com/katgit/myutils'

Once the package is ready, others can install your package using install_github() function:

devtools::install_github("katgit/myutils")

4.3 .gitignore file

We generally want the following entries to be added to the project’s .gitignore file:

# History files
.Rhistory
.Rapp.history

# Session Data files
.RData
.RDataTmp

# User-specific files
.Ruserdata

# Example code in package build process
*-Ex.R

# Output files from R CMD build
/*.tar.gz

# Output files from R CMD check
/*.Rcheck/

# RStudio files
.Rproj.user/

# produced vignettes
vignettes/*.html
vignettes/*.pdf

# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
.httr-oauth

# knitr and R markdown default cache directories
*_cache/
/cache/

# Temporary files created by R markdown
*.utf8.md
*.knit.md

# R Environment Variables
.Renviron

# pkgdown site
docs/

# translation temp files
po/*~

# RStudio Connect folder
rsconnect/