forked from yihui/knitr-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path007-text-output.Rmd
120 lines (76 loc) · 1.56 KB
/
007-text-output.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Testing text output
See if chunk options like `tidy`, `prompt` and `echo`, etc work as expected.
## A normal chunk
```{r demo}
1+1
for (i in 1:10) {
# nothing before 10
if(i>=10)print(i)
}
# two blank lines below
dnorm(0)
```
## Do not evaluate
```{r demo, eval=FALSE}
```
## Add prompts
```{r demo, prompt=TRUE}
```
## No evaluate or tidy
```{r demo, eval=FALSE, tidy=FALSE}
```
## Do not tidy
```{r demo, tidy=FALSE}
```
## Do not echo
```{r demo, echo=FALSE}
```
## Do not comment out results
```{r demo, comment=NA}
```
## Do not echo the 2nd expression
```{r demo, echo=-2}
```
## Do not evaluate, echo the 2nd expression
```{r demo, eval=FALSE, echo=2}
```
## Only evaluate the first two expressions
```{r demo, eval=1:2}
```
## Add prompts but no tidy
```{r demo, tidy=FALSE, prompt=TRUE}
```
## Change prompts
```{r}
options(prompt='R> ', continue='+ ')
```
```{r demo, prompt=TRUE}
```
## Backslashes
```{r}
{
# can you deal with \code{foo} or \n, \a?
gsub('\\.', '\\\\', 'a.b.c') # \link{bar}
}
cat('a\tb\nc')
```
## Other formatR options
We can set **formatR** options globally:
```{r}
options(keep.blank.line=FALSE)
```
```{r demo, eval=FALSE}
```
Or locally in one chunk via `tidy.opts`. Do not keep comments:
```{r demo, eval=FALSE, tidy.opts=list(keep.comment=FALSE)}
```
Move left braces to the next line:
```{r demo, eval=2, echo=2, tidy.opts=list(left.brace.newline=TRUE)}
```
Indent by 2 spaces:
```{r demo, eval=FALSE, tidy.opts=list(reindent.spaces=2)}
```
See <http://yihui.name/formatR> for details.
## Empty chunks
```{r}
```