This is an example of Markdown vignettes in R. Before R 3.0.0, only Sweave/PDF vignettes were supported in R. Markdown is gaining popularity over the years due to its simplicity, and R 3.0.0 starts to support package vignettes written in R Markdown.

Package vignettes

To enable Markdown vignettes in an R package, you need to

View vignettes

And R will load the knitr package to build these vignettes to HTML files, and you can see them when you open the HTML help:

help(package = "YourPackage", help_type = "html")

Examples

Below are some code chunks as examples.

cat("_hello_ **markdown**!", "\n")

hello markdown!

Normally you do not need any chunk options.

1 + 1
## [1] 2
10:1
##  [1] 10  9  8  7  6  5  4  3  2  1
rnorm(5)^2
## [1] 0.9484 0.1952 1.0010 0.5577 4.1624
strsplit("hello, markdown vignettes", "")
## [[1]]
##  [1] "h" "e" "l" "l" "o" "," " " "m" "a" "r" "k" "d" "o" "w" "n" " " "v"
## [18] "i" "g" "n" "e" "t" "t" "e" "s"

Feel free to draw beautiful plots and write math \(P(X>x)=\alpha/2\).

n = 300
set.seed(123)
par(mar = c(4, 4, 0.1, 0.1))
plot(rnorm(n), rnorm(n), pch = 21, cex = 5 * runif(n), col = "white", bg = "gray")

plot of chunk unnamed-chunk-3

You can use your own CSS file instead of the built-in style in the markdown package – just set the option markdown.HTML.stylesheet, e.g.

options(markdown.HTML.stylesheet = "path/to/a/custom/style.css")

For this vignette, I use the markdown.HTML.header option to modify a few CSS rules in the default CSS style:

options(markdown.HTML.header = system.file("misc", "vignette.css", package = "knitr"))