<- 30 surv.diff
13/01/2025
Prepare data (spreadsheet)
Analyse data (R)
Write report/paper (Word)
However, this workflow can unchain a maelstrom of email attachments …
How did you get these values? What analysis is behind this figure? Did you account for …?
What dataset was used? Which individuals were left out? Where is the clean dataset?
Oops, there is an error in the data. Can you repeat the analysis? And update figures/tables in Word!
Transcribing numbers from stats software by hand was the largest source of errors - Eubank 2006
You can find difficulties when resuming your own work and you can struggle to reproduce your own results from a few weeks/months/years ago…
Also, revising non-reproducible manuscripts can be very messy
Artwork by @allison_horst
Rmd = code (R, Python, etc) + text (Markdown)
Fully reproducible (trace all results including tables and plots)
Dynamic (can be regenerated with 1 click)
Multiple outputs:
Where does this value come from?
You can write inline code using the syntax `r `
In Rmarkdown:
Survival in population A was `r surv.diff`
% higher
Output:
Survival in population A was 30
% higher
You can write inline code using the syntax `r `
In Rmarkdown:
We measured `r nrow(data)`
individuals
Output:
We measured 150
individuals
The knitr package provides a lot of chunk options for customizing nearly all components of code chunks, such as the source code, text output, plots, and the language of the chunk
{r echo=FALSE, eval=TRUE, fig.height=3} plot(iris)
Chunk options can also be embbeded with #|
Not only R, but also:
…etc
# Header
## Subheader
*italic*
**bold**
[a link](https://example.com)
Can use Visual Markdown Editor
Or R package “Remedy” to facilitate writing in markdown with RStudio: https://thinkr-open.github.io/remedy/
With just one click (Knit
):
Spotted error in the data? Want to make new changes? No problem!
Make changes in Rmarkdown document
Click Knit
🧶 in Rstudio
The report will update automatically!
PDF generation requires LaTeX
Estimate | Std. Error | t value | Pr(>|t|) | |
---|---|---|---|---|
(Intercept) | 1.462 | 0.0608585 | 24.02294 | 0 |
Speciesversicolor | 2.798 | 0.0860669 | 32.50960 | 0 |
Speciesvirginica | 4.090 | 0.0860669 | 47.52118 | 0 |
Alternatives: gtsummary
, modelsummary
, huxtable
, etc
equatiomatic
describes model structureWe fitted a linear model:
\[ \operatorname{Petal.Length} = \alpha + \beta_{1}(\operatorname{Species}_{\operatorname{versicolor}}) + \beta_{2}(\operatorname{Species}_{\operatorname{virginica}}) + \epsilon \]
Using LaTeX:
$$
y \sim N(\mu, \sigma^2)
$$
\[ y \sim N(\mu, \sigma^2) \]
https://rstudio.github.io/visual-markdown-editing/citations.html
Many Citation Styles:
The are several R packages with Rmd templates for scientific journal:
rticles
papaja
rrtools
pinp
rmdTemplates
pagedreport
GitHub
R package: gramr https://github.com/ropenscilabs/gramr
wellspell.addin: https://github.com/nevrome/wellspell.addin
Synonym finder: https://github.com/gadenbuie/synamyn
Word count and readability: https://github.com/benmarwick/wordcountaddin
bookdown
Declare parameters:
https://bookdown.org/yihui/rmarkdown/parameterized-reports.html
Render thousands of individual reports from Rmd template
Google Docs - trackdown R package
https://raw.githubusercontent.com/rstudio/cheatsheets/main/rmarkdown.pdf
Try visual markdown editor
Parameterised reports (e.g. different iris or penguin species)
Add bibliography
Try templates (rticles, rmdTemplates)