R & GitHub Good Practices

Gábor Csárdi

R & GitHub Good Practices

Gábor Csárdi
gcsardi@mango-solutions.com

Continuous Integration

What is CI?

Continuous integration (CI) is the practice, in software engineering, of merging all developer working copies to a shared mainline several times a day.

Wikipedia https://en.wikipedia.org/wiki/Continuous_integration

What is CI?

Travis CI

https://travis-ci.org/

https://travis-ci.org/

Login with GitHub

Add a repository

Choose repository to add

Build history (empty)

Build history

Build output

Set up Travis for an R package

1. Create .travis.yml file:

language: R
sudo: false
cache: packages

2. Add it to the repository

3. Omit it from the R package, create .Rbuildignore:

^\.travis\.yml$

4. Commit and push

Add a README.md file, and a badge:

[![Build Status](https://travis-ci.org/<user>/<repo>.svg?branch=master)]
(https://travis-ci.org/<user>/<repo>)

Exercises

1. Register on https://travis-ci.org

2. Turn on Travis for your repository

3. Add a .travis.yml file to your repository

4. Push the new version to GitHub

5. Add a badge to your README.md file

Test coverage

What is test coverage?

Code coverage is a measure of the amount of code being exercised by the tests. It is an indirect measure of test quality.

Jim Hester, covr package author

Set up test coverage runs on Travis

Extend your .travis.yml file:

...
r_github_packages:
  - jimhester/covr

warnings_are_errors: true

notifications:
  email:
    on_success: change
    on_failure: change

after_success:
  - Rscript -e 'covr::codecov()'

Codecov

https://codecov.io/{user}/{repo}

Exercises

1. Add (dummy?) tests to your repository

2. Add code coverage support on Travis

3. Push the new version to GitHub

4. Add a badge for code coverage to README.md

Good Practices
for R packages

Tests

README.md file

NEWS.md file

Value busy maintainers’ time

GitHub API

Not just code

Pain points

Additional material

Software carpentry:

http://swcarpentry.github.io/git-novice/

GitHub help pages

https://help.github.com/

Hadley Wickham’s R packages book

http://r-pkgs.had.co.nz/git.html