Skip to content

Instantly share code, notes, and snippets.

@atbradley
Last active October 8, 2015 18:28
Show Gist options
  • Save atbradley/3371257 to your computer and use it in GitHub Desktop.
Save atbradley/3371257 to your computer and use it in GitHub Desktop.
Upload a file as a GitHub gist from R
#options('gh_token') should be a GitHub API token with the 'gist' scope.
#(See http://developer.github.com/v3/gists/)
library(httr)
library(rjson)
gistify <- function(filename, desc=F, public=F) {
data <- list(public = public)
if ( desc != F ) data$description = desc
contents <- paste(readLines(filename), collapse="\n")
fname = sub(".*/", '', filename)
files = list()
files[[fname]] = list(content = contents)
data$files <- files
data <- toJSON(data)
gh_token <- options('gh_token')
url <- paste("https://api.github.com/gists?access_token=",
gh_token, sep='')
POST(url, body=data)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment