-
Notifications
You must be signed in to change notification settings - Fork 0
/
05-writing.Rmd
141 lines (82 loc) · 3.34 KB
/
05-writing.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
# (PART) Writing {-}
# Writing
## Writing group
<!-- **TODO: (Eric)** -->
![](https://img.shields.io/badge/-WIP-yellow.svg)
# R Markdown
## Setup
See [Setup/R Markdown](#rmd-setup).
## Slides
October 21 2019 - Basic R Markdown
[Slides](https://slides.robitalec.ca/basic-rmd.html)
[Resources](https://gitlab.com/robit.a/workshops/-/archive/master/workshops-master.zip?path=basic-rmd)
```{r, echo = FALSE}
knitr::include_url('https://slides.robitalec.ca/basic-rmd.html')
```
## Basic markdown
Wrap a word with single asterisks for *italics* and double asterisks for **bold**.
```
Wrap a word with single asterisks for *italics* and double asterisks for **bold**.
```
Surround inline code chunks with single `` `backticks` `` or full code blocks with triple backticks:
````
```
yum <- is.delicious('gorgonzola')
yum
[1] TRUE
```
````
Tables can be made with a [markdown table generator](http://www.tablesgenerator.com/markdown_tables#) (or by hand), or with functions, for example: `knitr::kable`.
```{r, echo = TRUE, eval = FALSE}
knitr::kable(diamonds)
```
```{r, echo = FALSE, eval = TRUE}
library(data.table)
library(ggplot2)
data(diamonds)
setDT(diamonds)
knitr::kable(diamonds[1:5])
```
<!-- **TODO: images** -->
## YAML
![](https://img.shields.io/badge/-WIP-yellow.svg)
<!-- **TODO: link basic YAML Rmd** -->
<!-- **TODO: add classic error not working because tabs instead of spaces** -->
### Rendering multiple output formats {#rmd-multiple-output}
To render multiple output formats from the same R Markdown document, use this example. We remap the knit button / shortcut to rendering all the output formats specified.
<script src='https://gitlab.com/snippets/1976028.js'></script>
## BibTeX
### Setting italics in references
Setting italics in your `.bibtex` references is as simple as wrapping the words in `\emph{}`. For example:
```latex
\emph{Escherichia coli}
```
## Tables
![](https://img.shields.io/badge/-WIP-yellow.svg)
Lots of options are available for generating markdown tables from R objects,
or text.
Manually/copy-paste
* [Tables Generator](https://www.tablesgenerator.com/markdown_tables)
R packages
* `knitr::kable`
* [`pander`](http://rapporter.github.io/pander/)
* [`gt`](https://gt.rstudio.com/)
* [`flextable`](https://ardata-fr.github.io/flextable-book/)
* [`xtable`](https://cran.r-project.org/web/packages/xtable/vignettes/xtableGallery.pdf)
Note: differences between these packages are mainly in syntax but more importantly
also in the possible output formats. Some only work with HTML output, some only
PDF, etc.
## Reflow lines
If this is a manuscript, and you are noticing (especially in Git) everything is
on a few really long lines, simply reflow using the shortcut (CTRL+SHIFT+/) or
remember to hit enter at the end of a line.
<!-- **TODO: example image of this** -->
## Presentations with `xaringan`
Yihui Xie made a great package for generating HTML presentations in R Markdown: [`xaringan`](https://bookdown.org/yihui/rmarkdown/xaringan.html).
All of Alec's slides use this package, see [Slides](#slides).
### Incremental ggplot slides
An example for building your ggplots incrementally using this example `xaringan` document.
<script src='https://gitlab.com/snippets/1954903.js'></script>
<!-- ## Manuscript notes -->
<!-- use PDF for supplements, latex changes for fig caps -->
<!-- flextable for office tables -->