Skip to content

Latest commit

 

History

History
54 lines (37 loc) · 1.54 KB

010-upload.md

File metadata and controls

54 lines (37 loc) · 1.54 KB

This is an example of using knitr with extended markdown (e.g. GFM) and uploading images to imgur.com automatically. Note you should set the graphical device to create images that can be displayed in the web browser, e.g. dev = 'png' (it is the default for markdown output) works but 'pdf' does not.

First, the input file was named as knitr-upload.Rmd (source), and knitr will automatically determine the output filename to be knitr-upload.md.

I used the code below to make sure knitr will upload images and set some global chunk options.

library(knitr)
opts_knit$set(upload.fun = imgur_upload, base.url = NULL)  # upload all images to imgur.com
opts_chunk$set(fig.width = 5, fig.height = 5, cache = TRUE)

Now we write some code chunks in this markdown file:

## a simple calculator
1 + 1
## [1] 2
## boring random numbers
set.seed(123)
rnorm(5)
## [1] -0.56048 -0.23018  1.55871  0.07051  0.12929

We can also produce plots which are uploaded to imgur.com:

par(mar = c(4, 4, 0.1, 0.1))
plot(mpg ~ hp, data = mtcars, pch = 19)

plot of chunk md-cars

par(mar = c(3, 2, 0.1, 0.1))
matplot(t(scale(mtcars)), lty = 1, type = "l", xaxt = "n", ylab = "")
axis(1, seq(ncol(mtcars)), colnames(mtcars))

plot of chunk md-cars

So knitr is ready with GitHub with a single markdown file.