knitr (version 0.3)

imgur_upload: Upload a image to imgur.com

Description

This function uses the RCurl package to upload a image to imgur.com, and parses the XML response to a list with XML which contains information about the image in the Imgur website.

Usage

imgur_upload(file, key = opts_knit$get("imgur.key"))

Arguments

file
the path to the image file to be uploaded
key
the API key for Imgur (by default uses a key created by Yihui Xie, which allows 50 uploads per hour per IP address)

Value

  • A list converted from the response XML file; see Imgur API in the references.

Details

When the output format from knit() is HTML or Markdown, this function will be used to upload local image files to Imgur when the package option upload is TRUE (opts_knit$get('upload')), so the output document is completely self-contained, i.e. it does not need external image files any more, and it is ready to be published online.

References

Imgur API: http://api.imgur.com/; a demo: http://yihui.name/knitr/demo/upload/

Examples

Run this code
f = tempfile(fileext = ".png")
png(f)
plot(rnorm(100), main = R.version.string)
dev.off()
res = imgur_upload(f)
res$links$original  # link to original URL of the image
if (interactive()) 
    browseURL(res$links$imgur_page)  # imgur page

Run the code above in your browser using DataLab