Reproducible and dynamic manuscripts/theses in R
More detailed explanation of Rmarkdown can be found at the RStudio Website or in the pandoc website (which is what R Markdown uses to convert to other documents).
This was the code shown for the session:
YAML Header
R Markdown files should have at the top a YAML header. YAML is just a series of settings to use for the document, like title, author, what document to create (Word, PDF, etc), where your bibliography is located etc.
---
title: "DNS session"
author: "Luke W. Johnston"
date: "November 30, 2016"
bibliography: sample.bib
csl: ama.csl
output: word_document
---
Code chunk
Code chunks allow you to insert R output (like results, plots, tables, numbers, etc) into the document. This is the primary strength of using R Markdown. Use Ctrl-Alt-I to insert a code chunk when using RStudio.
Headers
Inserting a header, such as Introductions or Methods, is easy:
# Header 1
## Header 2
### Header 3
Bolding and italics
To bold use **bold**
. To italicize use *italicize*
.
Some code used in the session:
If you want to see the results, see Table 1.
Estimate | Std. Error | t value | Pr(> | t | ) | |
---|---|---|---|---|---|---|
Education | -0.8624 | 0.1448 | -5.954 | 3.659e-07 | ||
(Intercept) | 79.61 | 2.104 | 37.84 | 9.302e-36 |
Table: Table 1: This is the caption for table 1. Looking at the regression from the swiss dataset.
Including Plots
You can also embed plots here (see Figure 1), for example:
Note that the echo = FALSE
parameter was added to the code chunk to prevent printing of the R code that generated the plot.
Inline numbers 70.14
Citations
According to certain authors blah blah [@Lash2007a]
These other authors say … [@An2013a; @Vandenbroucke2007a]
It’s good to have the last header be:
# References
… since the references will be inserted at the end.