Last active
October 8, 2015 18:28
-
-
Save atbradley/3371257 to your computer and use it in GitHub Desktop.
Upload a file as a GitHub gist from R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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