-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathknitr-spin.Rmd
43 lines (32 loc) · 980 Bytes
/
knitr-spin.Rmd
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
This is a special R script which can be used to generate a report. You can
write normal text in roxygen comments.
First we set up some options (you do not have to do this):
```{r setup, include=FALSE}
library(knitr)
opts_chunk$set(fig.path='figure/silk-')
```
The report begins here.
```{r test-a, cache=FALSE}
# boring examples as usual
set.seed(123)
x = rnorm(5)
mean(x)
```
Now we continue writing the report. We can draw plots as well.
```{r test-b, fig.width=5, fig.height=5}
par(mar = c(4, 4, .1, .1)); plot(x)
```
Actually you do not have to write chunk options, in which case knitr will use
default options. For example, the code below has no options attached:
```{r }
var(x)
quantile(x)
```
And you can also write two chunks successively like this:
```{r test-chisq5}
sum(x^2) # chi-square distribution with df 5
```{r test-chisq4}
sum((x - mean(x))^2) # df is 4 now
```
Done. Call spin('knitr-spin.R') to make silk from sow's ear now and knit a
lovely purse.