Skip to content

Instantly share code, notes, and snippets.

@astatham
Created August 19, 2010 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astatham/537259 to your computer and use it in GitHub Desktop.
Save astatham/537259 to your computer and use it in GitHub Desktop.
imguRupload <- function(filename, title=NULL, caption=NULL, name=basename(filename), apikey="4feb29d00face5bc1b9dae536e15c373") {
require(RCurl)
require(RJSONIO)
if (length(filename)>1) stop("'filename' must be length 1.")
if (!file.exists(filename)) stop(filename, "does not exist!")
params <- list(key=apikey, image=fileUpload(filename), name=filename)
if (!is.null(title)) params[["title"]] <- title
if (!is.null(caption)) params[["caption"]] <- caption
fromJSON(rawToChar(postForm("http://api.imgur.com/2/upload.json", .params=params)))$upload
}
imguR <- function(title=NULL, caption=NULL, name=NULL, ...) {
tmpfile <- tempfile()
pdf(tmpfile, ...)
list(dev=dev.cur(), filename=tmpfile, title=title, caption=caption, name=name)
}
imguR.off <- function(imguR.dev) {
dev.off(imguR.dev$dev)
imguRupload(imguR.dev$filename, imguR.dev$title, imguR.dev$caption, imguR.dev$name)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment