Skip to content

Source Cpp code from online source #830

Description

@coatless

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions