# nanocHome / assets / blog / a_simple_bootstrap-based_knitr_template / knitr-minimal.html

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99  knitr with bootstrap

A Minimal Example for Markdown

This is a minimal example of using knitr to produce an HTML page from Markdown.

R code chunks

# set global chunk options: images will be 7x5 inches opts_chunk\$set(fig.width = 7, fig.height = 5)

Now we write some code chunks in this markdown file:

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

We can also produce plots:

par(mar = c(4, 4, 0.1, 0.1)) with(mtcars, {     plot(mpg ~ hp, pch = 20, col = "darkgray")     lines(lowess(hp, mpg)) })

Inline code

Inline R code is also supported, e.g. the value of x is 2, and 2 × π = 6.2832.

Math

LaTeX math as usual: $$f(\alpha, \beta) \propto x^{\alpha-1}(1-x)^{\beta-1}$$.

Misc

You can indent code chunks so they can nest within other environments such as lists.

1. the area of a circle with radius x

pi * x^2
## [1] 12.57
2. OK, that is great

To compile me, use

library(knitr) knit("knitr-minimal.Rmd")

Conclusion

Markdown is super easy to write. Go to knitr homepage for details.