|
|
xv | |
|
|
xvii | |
Preface |
|
xix | |
About the Authors |
|
xxvii | |
|
|
1 | (6) |
|
1.1 Use a Pandoc version not bundled with the RStudio IDE |
|
|
1 | (2) |
|
1.2 Install LaTeX (TinyTeX) for PDF reports |
|
|
3 | (1) |
|
1.3 Install missing LaTeX packages |
|
|
4 | (3) |
|
|
7 | (12) |
|
2.1 What happens when we render? |
|
|
7 | (2) |
|
|
9 | (7) |
|
|
9 | (2) |
|
|
11 | (1) |
|
|
12 | (1) |
|
|
13 | (3) |
|
2.3 What can we change to change the results? |
|
|
16 | (3) |
|
|
19 | (8) |
|
3.1 Code chunks and inline R code |
|
|
19 | (1) |
|
3.2 Write Markdown in the RStudio visual editor |
|
|
20 | (1) |
|
3.3 Render an R script to a report |
|
|
20 | (4) |
|
3.4 Convert R Markdown to R script |
|
|
24 | (2) |
|
|
26 | (1) |
|
|
27 | (32) |
|
|
27 | (1) |
|
4.2 Set the document title dynamically |
|
|
28 | (1) |
|
4.3 Access the document metadata in R code |
|
|
29 | (1) |
|
|
30 | (1) |
|
4.5 Bibliographies and citations |
|
|
31 | (3) |
|
4.5.1 Changing citation style |
|
|
32 | (1) |
|
4.5.2 Add an item to a bibliography without using it |
|
|
33 | (1) |
|
4.5.3 Add all items to the bibliography |
|
|
33 | (1) |
|
4.5.4 Include appendix after bibliography (*) |
|
|
33 | (1) |
|
4.6 Generate R package citations |
|
|
34 | (4) |
|
4.7 Cross-referencing within documents |
|
|
38 | (1) |
|
4.8 Update the date automatically |
|
|
39 | (3) |
|
4.9 Multiple authors in a document |
|
|
42 | (1) |
|
4.10 Numbered figure captions |
|
|
43 | (1) |
|
4.11 Combine words into a comma-separated phrase |
|
|
44 | (1) |
|
4.12 Preserve a large number of line breaks |
|
|
45 | (2) |
|
4.13 Convert models to equations |
|
|
47 | (1) |
|
4.14 Create an animation from multiple R plots |
|
|
48 | (1) |
|
|
49 | (3) |
|
|
50 | (1) |
|
4.15.2 Adding parameters to plots |
|
|
50 | (2) |
|
4.15.3 Other packages for making diagrams |
|
|
52 | (1) |
|
4.16 Escape special characters |
|
|
52 | (1) |
|
|
53 | (1) |
|
4.18 Omit a heading in the table of contents |
|
|
53 | (1) |
|
4.19 Put together all code in the appendix (*) |
|
|
53 | (2) |
|
4.20 Manipulate Markdown via Pandoc Lua filters (*) |
|
|
55 | (4) |
|
|
59 | (18) |
|
|
60 | (3) |
|
5.1.1 Using an R function to write raw HTML or LaTeX code |
|
|
60 | (1) |
|
5.1.2 Using a Pandoc Lua filter (*) |
|
|
61 | (2) |
|
|
63 | (1) |
|
5.3 Control the width of text output |
|
|
64 | (2) |
|
5.4 Control the size of plots/images |
|
|
66 | (2) |
|
|
68 | (1) |
|
|
68 | (2) |
|
5.6.1 Show a verbatim inline expression |
|
|
69 | (1) |
|
5.7 Line numbers for code blocks (*) |
|
|
70 | (1) |
|
5.8 Multi-column layout (*) |
|
|
71 | (6) |
|
|
77 | (20) |
|
6.1 Add LaTeX code to the preamble |
|
|
77 | (2) |
|
6.2 Pandoc options for LaTeX output |
|
|
79 | (2) |
|
6.3 Add logo to title page |
|
|
81 | (2) |
|
6.4 Include additional LaTeX packages |
|
|
83 | (1) |
|
6.4.1 Loading LaTeX packages |
|
|
83 | (1) |
|
|
84 | (1) |
|
6.5 Control the placement of figures |
|
|
84 | (3) |
|
6.5.1 Floating environments |
|
|
84 | (1) |
|
6.5.2 Prevent figures from floating |
|
|
85 | (1) |
|
6.5.3 Force floats forward |
|
|
86 | (1) |
|
6.5.4 Adjust LaTeX placement rules (*) |
|
|
86 | (1) |
|
|
87 | (2) |
|
6.7 Render documents containing Unicode characters |
|
|
89 | (1) |
|
6.8 Generate a LaTeX fragment |
|
|
90 | (1) |
|
6.9 Add custom headers and footers (*) |
|
|
90 | (2) |
|
6.10 Use a custom Pandoc LaTeX template (*) |
|
|
92 | (1) |
|
6.11 Write raw LaTeX code |
|
|
93 | (1) |
|
6.12 For hardcore LaTeX users (*) |
|
|
94 | (3) |
|
|
97 | (28) |
|
|
97 | (1) |
|
7.2 Center section headings |
|
|
98 | (1) |
|
7.3 Style code blocks and text output |
|
|
99 | (3) |
|
7.4 Scrollable code blocks (*) |
|
|
102 | (2) |
|
7.5 Fold all code blocks but show some initially |
|
|
104 | (2) |
|
|
106 | (2) |
|
7.7 Embed the Rmd source file in the HTML output file |
|
|
108 | (1) |
|
7.8 Embed arbitrary files in the HTML output file |
|
|
109 | (1) |
|
7.9 Use a custom HTML template (*) |
|
|
110 | (2) |
|
7.10 Include the content of an existing HTML file (*) |
|
|
112 | (2) |
|
7.11 Add a custom browser icon |
|
|
114 | (1) |
|
7.12 Use the <details> disclosure element |
|
|
115 | (2) |
|
7.13 Sharing HTML output on the web |
|
|
117 | (2) |
|
7.13.1 R-specific services |
|
|
117 | (1) |
|
7.13.2 Static website services |
|
|
118 | (1) |
|
7.14 Improve accessibility of HTML pages |
|
|
119 | (2) |
|
7.15 For hardcore HTML users (*) |
|
|
121 | (4) |
|
|
125 | (8) |
|
8.1 Custom Word templates |
|
|
125 | (2) |
|
8.2 The two-way workflow between R Markdown and Word |
|
|
127 | (3) |
|
8.3 Style individual elements |
|
|
130 | (3) |
|
9 Multiple Output Formats |
|
|
133 | (16) |
|
|
133 | (3) |
|
|
136 | (1) |
|
|
136 | (2) |
|
9.4 Multiple figures side by side |
|
|
138 | (1) |
|
9.5 Write raw content (*) |
|
|
138 | (1) |
|
|
139 | (10) |
|
|
140 | (2) |
|
9.6.2 Adding a shaded box |
|
|
142 | (2) |
|
|
144 | (5) |
|
|
149 | (26) |
|
10.1 The function knitr::kable() |
|
|
149 | (18) |
|
10.1.1 Supported table formats |
|
|
149 | (3) |
|
10.1.2 Change column names |
|
|
152 | (1) |
|
10.1.3 Specify column alignment |
|
|
153 | (1) |
|
10.1.4 Add a table caption |
|
|
154 | (1) |
|
10.1.5 Format numeric columns |
|
|
154 | (2) |
|
10.1.6 Display missing values |
|
|
156 | (1) |
|
10.1.7 Escape special characters |
|
|
157 | (1) |
|
10.1.8 Multiple tables side by side |
|
|
158 | (1) |
|
10.1.9 Generate multiple tables from a for-loop (*) |
|
|
159 | (2) |
|
10.1.10 Customize LaTeX tables (*) |
|
|
161 | (4) |
|
10.1.11 Customize HTML tables (*) |
|
|
165 | (2) |
|
10.2 The kableExtra package |
|
|
167 | (4) |
|
|
168 | (1) |
|
10.2.2 Style specific rows/columns |
|
|
168 | (1) |
|
10.2.3 Group rows/columns |
|
|
169 | (2) |
|
10.2.4 Scaling down wide tables in LaTeX |
|
|
171 | (1) |
|
10.3 Other packages for creating tables |
|
|
171 | (4) |
|
|
175 | (30) |
|
11.1 Use variables in chunk options |
|
|
175 | (1) |
|
11.2 Do not stop on error |
|
|
176 | (1) |
|
11.3 Multiple graphical output formats for the same plot |
|
|
177 | (1) |
|
11.4 Cache time-consuming code chunks |
|
|
178 | (1) |
|
11.5 Cache a code chunk for multiple output formats |
|
|
179 | (1) |
|
|
180 | (1) |
|
11.7 Hide code, text output, messages, or plots |
|
|
181 | (2) |
|
11.8 Hide everything from a chunk |
|
|
183 | (1) |
|
11.9 Collapse text output blocks into source blocks |
|
|
183 | (1) |
|
11.10 Reformat R source code |
|
|
184 | (2) |
|
11.11 Output text as raw Markdown content (*) |
|
|
186 | (3) |
|
11.12 Remove leading hashes in text output |
|
|
189 | (1) |
|
11.13 Add attributes to text output blocks (*) |
|
|
190 | (2) |
|
11.14 Post-process plots (*) |
|
|
192 | (2) |
|
11.15 High-quality graphics (*) |
|
|
194 | (3) |
|
11.16 Step-by-step plots with low-level plotting functions (*) |
|
|
197 | (1) |
|
11.17 Customize the printing of objects in chunks (*) |
|
|
197 | (3) |
|
|
200 | (5) |
|
|
205 | (16) |
|
|
208 | (2) |
|
12.2 Add line numbers to source code |
|
|
210 | (1) |
|
12.3 Scrollable text output |
|
|
211 | (3) |
|
12.4 Truncate text output |
|
|
214 | (3) |
|
12.5 Output figures in the HTML5 format |
|
|
217 | (4) |
|
|
221 | (12) |
|
|
223 | (2) |
|
|
225 | (1) |
|
13.3 Report how much time each chunk takes to run |
|
|
225 | (2) |
|
13.4 Show the chunk header in the output |
|
|
227 | (2) |
|
13.5 Embed an interactive 3D plot with rgl |
|
|
229 | (4) |
|
14 Miscellaneous knitr Tricks |
|
|
233 | (20) |
|
|
233 | (3) |
|
14.1.1 Embed one chunk in another chunk (*) |
|
|
233 | (1) |
|
14.1.2 Use the same chunk label in another chunk |
|
|
234 | (1) |
|
14.1.3 Use reference labels (*) |
|
|
235 | (1) |
|
14.2 Use an object before it is created (*) |
|
|
236 | (2) |
|
|
238 | (1) |
|
14.4 Generate a plot and display it elsewhere |
|
|
239 | (1) |
|
14.5 Modify a plot in a previous code chunk |
|
|
240 | (2) |
|
14.6 Save a group of chunk options and reuse them (*) |
|
|
242 | (1) |
|
14.7 Use knitr::knit_expand() to generate Rmd source |
|
|
243 | (1) |
|
14.8 Allow duplicate labels in code chunks (*) |
|
|
244 | (1) |
|
14.9 A more transparent caching mechanism |
|
|
245 | (8) |
|
14.9.1 Invalidate the cache by changing code in the expression |
|
|
246 | (1) |
|
14.9.2 Invalidate the cache by changes in global variables |
|
|
247 | (2) |
|
14.9.3 Keep multiple copies of the cache |
|
|
249 | (1) |
|
14.9.4 Comparison with knitr/s caching |
|
|
250 | (3) |
|
|
253 | (18) |
|
15.1 Register a custom language engine (*) |
|
|
254 | (3) |
|
15.2 Run Python code and interact with Python |
|
|
257 | (1) |
|
15.3 Execute content conditionally via the asis engine |
|
|
258 | (1) |
|
15.4 Execute Shell scripts |
|
|
259 | (1) |
|
15.5 Visualization with D3 |
|
|
260 | (1) |
|
15.6 Write the chunk content to a file via the cat engine |
|
|
261 | (4) |
|
15.6.1 Write to a CSS file |
|
|
262 | (1) |
|
15.6.2 Include LaTeX code in the preamble |
|
|
263 | (1) |
|
15.6.3 Write YAML data to a file and also display it |
|
|
264 | (1) |
|
|
265 | (1) |
|
|
265 | (1) |
|
15.9 Create graphics with Asymptote |
|
|
266 | (2) |
|
15.9.1 Generate data in R and read it in Asymptote |
|
|
267 | (1) |
|
15.10 Style HTML pages with Sass/SCSS |
|
|
268 | (3) |
|
|
271 | (20) |
|
16.1 Source external R scripts |
|
|
271 | (1) |
|
16.2 Read external scripts into a chunk |
|
|
272 | (1) |
|
16.3 Read multiple code chunks from an external script (*) |
|
|
273 | (1) |
|
|
274 | (3) |
|
|
277 | (1) |
|
16.6 The working directory for R code chunks |
|
|
278 | (4) |
|
|
282 | (2) |
|
16.8 R Markdown templates in R packages |
|
|
284 | (2) |
|
16.8.1 Template use-cases |
|
|
284 | (1) |
|
|
285 | (1) |
|
16.9 Write books and long-form reports with bookdown |
|
|
286 | (2) |
|
16.10 Build websites with blogdown |
|
|
288 | (3) |
|
|
291 | (10) |
|
17.1 Use RStudio keyboard shortcuts |
|
|
291 | (1) |
|
17.2 Spell-check R Markdown |
|
|
292 | (1) |
|
17.3 Render R Markdown with rmarkdown:: render () |
|
|
292 | (2) |
|
17.4 Parameterized reports |
|
|
294 | (2) |
|
17.5 Customize the Knit button (*) |
|
|
296 | (3) |
|
17.6 Collaborate on Rmd documents through Google Drive |
|
|
299 | (1) |
|
17.7 Organize an R Markdown project into a research website with workflowr |
|
|
300 | (1) |
|
17.8 Send emails based on R Markdown |
|
|
301 | (2) |
Appendix |
|
301 | (18) |
|
A knitr's Chunk and Package Options |
|
|
303 | (16) |
|
|
303 | (2) |
|
|
305 | (1) |
|
|
305 | (2) |
|
|
307 | (1) |
|
|
308 | (2) |
|
|
310 | (4) |
|
|
314 | (1) |
|
|
315 | (1) |
|
|
315 | (1) |
|
|
315 | (1) |
|
|
316 | (1) |
|
A.1.11 Extracting source code |
|
|
316 | (1) |
|
A.1.12 Other chunk options |
|
|
316 | (1) |
|
|
316 | (3) |
Bibliography |
|
319 | (6) |
Index |
|
325 | |