R development using GitHub

Gábor Csárdi

R development using GitHub

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

Outline

1. Reading code

2. Collaboration #1

3. Collaboration #2

4. Version control & git

5. Best practices, CI

Five parts, 30 minutes each, 5 minutes for exercises.

Goals

1. Understand GitHub, start using it

2. Understand how git works, what it can do for you

3. Have an R package on GitHub, with CI, code coverage

4. Make you confident that you can do it again!

1. Reading code

The hardest part of coding: the right way

Sort a data frame? correct solution? Depends.

dd[with(dd, order(-z, b)), ]
library(plyr)
arrange(dd, desc(z), b)
library(data.table)
data.table(dd)[order(-z, b)]
library(taRifx)
sort(dd, f= ~-z+b)
doBy::orderBy(~ - z + b, data = dd)

http://stackoverflow.com/questions/1296646

Reading code

Programs must be written for people to read, and only incidentally for machines to execute.

Harold Abelson, Structure and Interpretation of Computer Programs

Open Source

The GitHub UI

https://github.com/gaborcsardi/praise

Files

Files

README.md

Commits

Commit ids

Browse files at another version

Browse files at another version

Diffs

Diffs

History of files

History of files

Blame

Blame

Star

Star

Star

Search: find users

Search: within repository

Search: all R code

Search: all CRAN packages

Reading R code

R source code, including base packages

https://github.com/wch/r-source

CRAN packages

https://github.com/cran/*

BioConductor packages

https://github.com/bioconductor-mirror

R-Forge packages

https://github.com/rforge

Installing packages from GitHub

remotes::install_github("gaborcsardi/praise")
Downloading GitHub repo gaborcsardi/praise@master
Installing package into ‘/Users/gaborcsardi/r_pkgs’
(as ‘lib’ is unspecified)
* installing *source* package ‘praise’ ...
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (praise)
praise::praise()
## [1] "You are finest!"

Install remotes using itself

https://github.com/mangothecat/remotes#readme

base <- "https://raw.githubusercontent.com/"
repo <- "MangoTheCat/remotes/"
file <- "master/install-github.R"
url <- paste0(base, repo, file)
source(url)$value("mangothecat/remotes")
Downloading GitHub repo mangothecat/remotes@master
Installing package into ‘/Users/gaborcsardi/r_pkgs’
(as ‘lib’ is unspecified)
* installing *source* package ‘remotes’ ...
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (remotes)

Dependencies to GitHub packages

Use the Remotes field in DESCRIPTION

...
Suggests:
    testthat
Imports:
    description,
    rcmdcheck
Remotes:
    metacran/description,
    mangothecat/rcmdcheck
...
❯ remotes::install_github("mangothecat/goodPractice")
Downloading GitHub repo mangothecat/goodPractice@master
Downloading GitHub repo metacran/description@master
...

Exercises

1. Find your favorite R developer on GitHub.

2. Find your favorite R package on GitHub.

3. Star it.

4. Look at the commit history.

5. Find out when it was last updated.

6. Find out who updated it.

7. Find out what changed.

8. Install your favorite R package using remotes.