Debian Codegraph @

inst/examples/knitr-minimal.Rmd

raw
1 # A Minimal Example for Markdown
2
3 This is a minimal example of using **knitr** to produce an _HTML_ page from _Markdown_.
4
5 ## R code chunks
6
7 ```{r setup}
8 # set global chunk options: images will be 7x5 inches
9 knitr::opts_chunk$set(fig.width=7, fig.height=5)
10 options(digits = 4)
11 ```
12
13 Now we write some code chunks in this markdown file:
14
15 ```{r computing}
16 x <- 1+1 # a simple calculator
17 set.seed(123)
18 rnorm(5) # boring random numbers
19 ```
20
21 We can also produce plots:
22
23 ```{r graphics}
24 par(mar = c(4, 4, .1, .1))
25 with(mtcars, {
26 plot(mpg~hp, pch=20, col='darkgray')
27 lines(lowess(hp, mpg))
28 })
29 ```
30
31 ## Inline code
32
33 Inline R code is also supported, e.g. the value of `x` is `r x`, and 2 &times; &pi;
34 = `r 2*pi`.
35
36 ## Math
37
38 LaTeX math as usual: $f(\alpha, \beta) \propto x^{\alpha-1}(1-x)^{\beta-1}$.
39
40 ## Misc
41
42 You can indent code chunks so they can nest within other environments such as lists.
43
44 1. the area of a circle with radius x
45 ```{r foo}
46 pi * x^2
47 ```
48 2. OK, that is great
49
50 To compile me, use
51
52 ```{r compile, eval=FALSE}
53 library(knitr)
54 knit('knitr-minimal.Rmd')
55 ```
56
57 ## Conclusion
58
59 Markdown is super easy to write. Go to **knitr** [homepage](https://yihui.org/knitr/) for details.