An introduction to R Markdown / Quarto
BIO 8940 - Lecture 2
2024-09-19
Credit: Ignasi Bartomeus, PhD
R
, Python
, etcmulti-language, next generation version of R Markdown
include many new new features and capabilities
Like R Markdown, Quarto uses knitr to execute R code, and is therefore able to render most existing Rmd files without modification.
| header A | header B | header C |
|:---------:|:--------:|---------:|
| left | center | right |
Table: This is a title
header A | header B | header C |
---|---|---|
left | center | right |
A bit of a hassle…
Wait for next section to learn how to generate tables from R
https://rstudio.com/wp-content/uploads/2015/03/rmarkdown-reference.pdf
R
codeRmd (R markdown) and qmd (quarto) differ:
echo = FALSE
or #| echo: false
hides code.eval = FALSE
or #| eval: false
prevents code from being runmessage = FALSE
or #| meassage: false
prevents messages from appearing in outputRepeating chunk options can be painful
If you have echo = FALSE
in every single chunk, how to set the default chunk option to echo = FALSE
?
Use knitr::opts_chunk$set(echo = FALSE)
You may overwrite the default for each chunk
For chunk options, check out https://yihui.name/knitr/options/
# cars is a built-in-to-R data set of cars and their stopping distances
cars %>%
head(4) %>%
knitr::kable(format = "html", caption = "A kable table")
speed | dist |
---|---|
4 | 2 |
4 | 10 |
7 | 4 |
7 | 22 |
kable
package is often used with the kableExtra
packagegt
using similar approach to table that ggplot
has to figureshttps://rstudio.com/wp-content/uploads/2015/03/rmarkdown-reference.pdf
Contains the metadata of the document
Starts and ends by three dashes
Comes first in the document
Rmd
In HTML output, you can use theme
or a custom .css style sheet
theme
options (bootswatch.com) : “cerulean”, “journal”, “flatly”, “darkly”, “readable”, “spacelab”, “united”, “cosmo”, “lumen”, “paper”, “sandstone”, “simplex”, “yeti”
You may also use LaTeX templates with R Markdown, and write reproducible scientific paper
qmd
this is were Quarto is leaps beyong R markdown
excellent doc on the website
betterbibtex
extension for dynamic file)*@article{Shea2014,
author = {Shea, Nicholas and Boldt, Annika},
journal = {Trends in Cognitive Sciences},
pages = {186--193},
title = {{Supra-personal cognitive control}},
volume = {18},
year = {2014},
doi = {10.1016/j.tics.2014.01.006},
}
Blah blah (Shea2014?, Lottridge2012?).
Blah blah (Shea et al. 2014; Lottridge et al. 2012).
Blah blah (Shea et al. 2014; Lottridge et al. 2012).
Shea et al. (2014) says blah.
Blah blah (see Shea et al. 2014, 33–35; also Wu 2016, ch. 1).
For an easy way to insert citations, try the citr
RStudio add-in.
If you are using Zotero
, then RStudio can link directly for both Rmd and qmd files (same for VScode)
In Rstudio, Rmarkdown file = notebook
Meaning that R output:
If you don’t like the notebook and want the console, add to YAML header
editor_options:
chunk_output_type: console
https://rstudio.com/wp-content/uploads/2015/03/rmarkdown-reference.pdf
Most of what works for R markdown works for Quarto
BIO 8940 - Lecture 2