R Language Creating packages with devtools Creating vignettes


Example

A vignette is a long-form guide to your package. Function documentation is great if you know the name of the function you need, but it’s useless otherwise. A vignette is like a book chapter or an academic paper: it can describe the problem that your package is designed to solve, and then show the reader how to solve it.

Vignettes will be created entirely in markdown.

Requirements

  • Rmarkdown: install.packages("rmarkdown")
  • Pandoc

Vignette creation

devtools::use_vignette("MyVignette", "MyPackage")

You can now edit your vignette at ./vignettes/MyVignette.Rmd.

The text in your vignette is formatted as Markdown.

The only addition to the original Markdown, is a tag that takes R code, runs it, captures the output, and translates it into formatted Markdown:

```{r}
# Add two numbers together
add <- function(a, b) a + b
add(10, 20)
```

Will display as:

# Add two numbers together
add <- function(a, b) a + b
add(10, 20)
## [1] 30

Thus, all the packages you will use in your vignettes must be listed as dependencies in ./DESCRIPTION.