-
Notifications
You must be signed in to change notification settings - Fork 586
/
007-text-output.Rmd
169 lines (107 loc) · 2.16 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# 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}
```
## Prompts, no evaluate or tidy
```{r demo, eval=FALSE, 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(formatR.blank = FALSE)
```
```{r demo, eval=FALSE}
```
Or locally in one chunk via `tidy.opts`. Do not keep comments:
```{r demo, eval=FALSE, tidy.opts=list(comment=FALSE)}
```
Move left braces to the next line:
```{r demo, eval=2, echo=2, tidy.opts=list(brace.newline=TRUE)}
```
Indent by 2 spaces:
```{r demo, eval=FALSE, tidy.opts=list(indent=2)}
```
See <http://yihui.org/formatR> for details.
## Empty chunks
```{r}
```
## Messages
Do not include messages:
```{r message=FALSE}
1+1
message('helloooo!')
```
No warnings:
```{r test-w, warning=FALSE}
1:2+1:3
warning('no no no')
```
Select warnings using numeric indices:
```{r test-w, warning=-1}
```
Invalid indices will select nothing:
```{r test-w, warning=3}
```
## The results option
Do not show text results:
```{r demo, results='hide'}
```
Flush all results to the end of a chunk:
```{r demo, results='hold'}
```
Output as is:
```{r results='asis'}
cat('_Markdown_,', 'oh yeah, **Markdown**')
```