Reading an R file from GitHub

Lets say that I want to read in this R file from GitHub into R.

The first thing you have to do is locate the raw file. You can do so by clicking on the Raw button in GitHub. In this case it’s https://raw.github.com/lcolladotor/ballgownR-devel/master/ballgownR/R/infoGene.R

One would think that using source() would work, but it doesn’t as shown below:

```r source("https://raw.github.com/lcolladotor/ballgownR-devel/master/ballgownR/R/infoGene.R") ``` ```r ## Warning: unsupported URL scheme ``` ```r ## Error: cannot open the connection ```

However, thanks again to Hadley Wickham you can do so by using the devtools (Wickham & Chang, 2013 ) package.

Here is how it works:

```r library(devtools) library(roxygen2) ## Needed because this file has roxygen2 comments. Otherwise you get a ## 'could not find function 'digest'' error source_url("https://raw.github.com/lcolladotor/ballgownR-devel/master/ballgownR/R/infoGene.R") ``` ```r ## SHA-1 hash of file is 6c32a620799eded5d6ff0997a184843d7964724a ``` ```r ## Note that you can specify the SHA-1 hash to be very specific about ## which version of the file you want to read in. ```

We can then check that infoGene has actually been sourced:

```r "infoGene" %in% ls() ``` ```r ## [1] TRUE ```

That’s it! Enjoy!

Citations made with knitcitations (Boettiger, 2013 ).

Reproducibility

```r sessionInfo() ``` ```r ## R version 3.0.0 (2013-04-03) ## Platform: x86_64-apple-darwin10.8.0 (64-bit) ## ## locale: ## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 ## ## attached base packages: ## [1] stats graphics grDevices utils datasets methods base ## ## other attached packages: ## [1] roxygen2_2.2.2 digest_0.6.3 devtools_1.2 ## [4] knitcitations_0.4-6 bibtex_0.3-5 knitr_1.2 ## ## loaded via a namespace (and not attached): ## [1] brew_1.0-6 evaluate_0.4.3 formatR_0.7 httr_0.2 ## [5] memoise_0.1 parallel_3.0.0 RCurl_1.95-4.1 stringr_0.6.2 ## [9] tools_3.0.0 whisker_0.3-2 XML_3.95-0.2 xtable_1.7-1 ```