Importing data into R (rdata) from Github

I want to put some R code plus the associated data file (RData) on Github.

So far, everything works okay. But when people clone the repository, I want them to be able to run the code immediately. At the moment, this isn’t possible because they will have to change their work directory (setwd) to directory that the RData file was cloned (i.e. downloaded) to.

  • Test multiple repos in travis ci
  • Git PullRequest job failed. Couldn't find any revision to build. Verify the repository and branch configuration for this job
  • Git add branch on one single directory?
  • git: create tag and push to remote: why tag is behind master on remote?
  • git public key for more repositories
  • error: git-credential-osxkeychain died of signal 11
  • Therefore, I thought it might be easier, if I changed the R code such that it linked to the RData file on github. But I cannot get this to work using the following snippet. I think perhaps there is some issue text / binary issue.

    x <- RCurl::getURL("")
    y <- load(x)

    Any help would be appreciated.


  • Slidify doesn't render rCharts in browser after publishing on GitHub or RPubs
  • How do you upload images to a gist?
  • Heroku app seems to be pulling from wrong Git respository/branch
  • How to change git repository using android studio
  • git push authentication fails
  • Github doesn't show the right author of a commit
  • 3 Solutions collect form web for “Importing data into R (rdata) from Github”

    This works for me:

    githubURL <- ""
    #          X        Y        Z
    # 1 16602794 -4183983 94.92019
    # 2 16602814 -4183983 91.15794
    # 3 16602834 -4183983 87.44995
    # 4 16602854 -4183983 83.79617
    # 5 16602874 -4183983 80.19643
    # 6 16602894 -4183983 76.65052

    EDIT Response to OP comment.

    From the documentation:

    Note that the https:// URL scheme is not supported except on Windows.

    So you could try this:


    which works for me as well, but this will clutter your working directory. If that doesn’t work, try setting method="curl" in the call to download.file(...).

    load takes a filename.

    x <- getURL("")
    writeLines(x, tmp <- tempfile())
    y <- load(tmp)

    I’ve had trouble with this before as well, and the solution I’ve found to be the most reliable is to use a tiny modification of source_url from the fantastic [devtools][1] package. This works for me (on a Mac).

    load_url <- function (url, ..., sha1 = NULL) {
      # based very closely on code for devtools::source_url
      stopifnot(is.character(url), length(url) == 1)
      temp_file <- tempfile()
      request <- httr::GET(url)
      writeBin(httr::content(request, type = "raw"), temp_file)
      file_sha1 <- digest::digest(file = temp_file, algo = "sha1")
      if (is.null(sha1)) {
        message("SHA-1 hash of file is ", file_sha1)
      else {
        if (nchar(sha1) < 6) {
          stop("Supplied SHA-1 hash is too short (must be at least 6 characters)")
        file_sha1 <- substr(file_sha1, 1, nchar(sha1))
        if (!identical(file_sha1, sha1)) {
          stop("SHA-1 hash of downloaded file (", file_sha1, 
               ")\n  does not match expected value (", sha1, 
               ")", call. = FALSE)
      load(temp_file, envir = .GlobalEnv)

    I use a very similar modification to get text files from github using read.table, etc. Note that you need to use the “raw” version of the github URL (which you included in your question).


    Git Baby is a git and github fan, let's start git clone.