Recently, there was an interesting StackOverflow question that came up regarding how to source code from GitHub. Sourcing code from an online repository has precedents in other R packages. Most notably, shiny implements several ways to run an app from shiny::runGist() to shiny:: runUrl().
Dirk wrote a nice little five liner to solve this issue:
library(Rcpp)
remurl <- "https://github.com/slwu89/MCMC/blob/master/adaptMCMC_source.cpp"
locfile <- "/tmp/mcmc.cpp"
download.file(url=remurl, destfile=locfile)
sourceCpp(locfile) # dozens of error for _this_ file
I think it may be helpful to wrap this up into three functions:
compileGist()
compileGitHub()
compileURL()
The pros of this approach:
- Easier way to run code found online
- Allows for examples to just "work" without copy paste errors.
The cons of this approach:
sourceCpp() has already diluted the need to learn how to package compiled code. By adding this, there is a risk of further neglecting package builds.
- This adds a new feature to the package.
Recently, there was an interesting StackOverflow question that came up regarding how to source code from GitHub. Sourcing code from an online repository has precedents in other R packages. Most notably,
shinyimplements several ways to run an app fromshiny::runGist()toshiny:: runUrl().Dirk wrote a nice little five liner to solve this issue:
I think it may be helpful to wrap this up into three functions:
compileGist()compileGitHub()compileURL()The pros of this approach:
The cons of this approach:
sourceCpp()has already diluted the need to learn how to package compiled code. By adding this, there is a risk of further neglecting package builds.