Hello R Markdown
R Markdown is a way of generating fully reproducible and dynamic documents, in which both text and code can be combined. This means no more copying of results or images from other sources into a Word document, instead, these are generated from the document itself!
This is valuable for reducing the human errors that can emerge from copying data around (and save you lots of time!), and it makes it much clearer where the results are coming from, both of which greatly enhance reproducibility. One can render a R Markdown file into HTML pages, or PDFs, or Word documents, slides or even whole websites!
This website is acutally make with R Markdown via a great little package called blogdown
This website houses the resources to accompany the session “Introduction to R Markdown”, first presented at the Researcher Summer school at Keele University 2022. The session and this site aims to provide a gentle introduction to using R Markdown, with a focus on scientific writing.
It should be noted that the next-generation R Markdown, called Quarto has very recently had it’s version 1.0 release, so for newcomers it may be worth learning the Quarto syntax. It is very similar to R Markdown, and is backwards compatible, but I will highlight the differences as they come up. Please see the further resources page for more info on this.
Some quick examples
Here’s a quick preview of some R code and what the results can look like:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
fit <- lm(dist ~ speed, data = cars)
fit
##
## Call:
## lm(formula = dist ~ speed, data = cars)
##
## Coefficients:
## (Intercept) speed
## -17.579 3.932
Including Plots
You can also embed plots. See Figure 1 for example:
par(mar = c(0, 1, 0, 1))
pie(
c(280, 60, 20),
c('Sky', 'Sunny side of pyramid', 'Shady side of pyramid'),
col = c('#0292D8', '#F7EA39', '#C4B632'),
init.angle = -50, border = NA
)