Debian Codegraph @

inst/doc/knitr-markdown.Rmd

raw
1 ---
2 title: R Markdown Vignettes with litedown
3 author: Yihui Xie
4 date: "`{r} Sys.Date()`"
5 output:
6 html:
7 meta:
8 css: ["@default"]
9 ---
10
11 <!--
12 %\VignetteEngine{litedown::vignette}
13 %\VignetteIndexEntry{R Markdown Vignettes with litedown}
14 -->
15
16 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.
17
18 > Please note this example is for [litedown](https://cran.r-project.org/package=litedown). If you use [R Markdown v2](https://rmarkdown.rstudio.com), you should use the vignette engine `knitr::rmarkdown` instead of `litedown::vignette`.
19
20 ## Package vignettes
21
22 To enable Markdown vignettes in an R package, you need to
23
24 - add `*.Rmd` files under the `vignettes` directory
25 - add `VignetteBuilder: litedown` to the `DESCRIPTION` file
26 - specify the vignette engine `\VignetteEngine{litedown::vignette}` in the `Rmd` files (inside HTML comments)
27
28 ## View vignettes
29
30 And R will load the **litedown** package to build these vignettes to HTML files, and you can see them when you open the HTML help:
31
32 ```{r eval=FALSE}
33 help(package = 'YourPackage', help_type = 'html')
34 # or see a standalone list of vignettes
35 browseVignettes('YourPackage')
36 ```
37
38 ## Examples
39
40 Below are some code chunks as examples.
41
42 ```{r hello, results='asis'}
43 if (TRUE) cat('_hello_ **markdown**!', '\n')
44 ```
45
46 Normally you do not need any chunk options.
47
48 ```{r test, collapse=TRUE}
49 1+1
50 10:1
51 rnorm(5)^2
52 strsplit('hello, markdown vignettes', '')
53 ```
54
55 Feel free to draw beautiful plots and write math $P(X>x)=\alpha/2$.
56
57 ```{r}
58 n=300; set.seed(123)
59 par(mar=c(4,4,.1,.1))
60 plot(rnorm(n), rnorm(n), pch=21, cex=5*runif(n), col='white', bg='gray')
61 ```