knitr logo

knitr: elegant, flexible, and fast dynamic report generation with R

Upload images

Publish images from chunks in the web


The function imgur_upload() in the knitr package enables one to upload images to the image host in R using the RCurl package. If the package option is a function (e.g. imgur_upload) that uploads files to a certain server/host, all plots generated in chunks will be uploaded automatically when the output format is HTML or Markdown.

This allows you to publish web pages quickly without worrying about image files; you only need to upload a single HTML (to any web servers) or Markdown file (to GitHub, for example).

Brave professors may encourage their brave students to write homeworks with a simple Markdown file, instead of MS Word (which is usually difficult to reproduce and frustrating to format elegantly).

The package option opts_knit$get('') is customizable so that you can use your own function to upload an image. See the script custom_knit.R by Carl for examples.