Don't forget to install knitr package.
install.packages("knitr")
This is an .Rmd document. Maybe you have heard of Sweave? Well,
knitr is like modern Sweave.
- can work with markdown files (simpler) and LaTeX.
- more flexible re: graphics
- caching
- fancy look and feel.
Let's get R to do some simple maths.
x <- 1:3
y <- 4:6
outer(x, y)
## [,1] [,2] [,3]
## [1,] 4 5 6
## [2,] 8 10 12
## [3,] 12 15 18
As well as having chunks in separate paragaphs, you can have some inline computation. For example, the mean of x is 2 and the sum of x and y is 5, 7, 9. Chunks can be named and then referred to later.
x <- seq(from=0, to=2*pi, length=1000)
y <- cos(3*x)
plot(x, y, type='l', col='blue')
See also the xtable package.
library(knitr)
kable(head(iris[,1:3]), format='html')
| Sepal.Length | Sepal.Width | Petal.Length |
|---|---|---|
| 5.1 | 3.5 | 1.4 |
| 4.9 | 3.0 | 1.4 |
| 4.7 | 3.2 | 1.3 |
| 4.6 | 3.1 | 1.5 |
| 5.0 | 3.6 | 1.4 |
| 5.4 | 3.9 | 1.7 |
-
What is markdown syntax? Orignally here, promoted for
Rby Rstudio. -
What can
knitrdo? Knitr home page
