Writing academic papers with RMarkdown and friends
Cynthia Huang
ECC4860/ETC4860 Workshop, 9 Aug 2022
Today's Agenda
Key Concepts
- Reproducible documents
- R Markdown
- LaTex, Bookdown
- Quarto, pandoc and more
Try it Yourself
- Hands-on authoring in RStudio
- Render a .pdf
- Choose your own adventure
Getting Help
- Search queries
- Good questions
- Further Resources
![](https://s3.amazonaws.com/media-p.slid.es/uploads/2196364/images/9756703/pasted-from-clipboard.png)
- Why reproducible authoring?
- How does R Markdown work?
- What about Bookdown, LaTex, Quarto and more?
Key Concepts
Why Reproducibility?
![](https://intro2r.com/images/workflow1.png)
Image source: An Introduction to R
Why R Markdown?
according to the internet...
![Two fuzzy round monsters dressed as wizards, working together to brew different things together from a pantry (code, text, figures, etc.) in a cauldron labeled “R Markdown”. The monster wizard at the cauldron is reading a recipe that includes steps “1. Add text. 2. Add code. 3. Knit. 4. (magic) 5. Celebrate perceived wizardry.” The R Markdown potion then travels through a tube, and is converted to markdown by a monster on a broom with a magic wand, and eventually converted to an output by pandoc. Stylized text (in a font similar to Harry Potter) reads “R Markdown. Text. Code. Output. Get it together, people.”](https://s3.amazonaws.com/media-p.slid.es/uploads/2196364/images/9758870/pasted-from-clipboard.png)
Source: Stats Illustrations by Allison Horst
Anatomy of .Rmd
![](https://s3.amazonaws.com/media-p.slid.es/uploads/2196364/images/9750410/pasted-from-clipboard.png)
metadata
about the document
natural language text
with formatting
"instructions"
procedural code
with options on how to
evaluate the code
![](https://s3.amazonaws.com/media-p.slid.es/uploads/2196364/images/9757393/pasted-from-clipboard.png)
Image source: Applied R code
Under the Hood
![](https://s3.amazonaws.com/media-p.slid.es/uploads/2196364/images/9756703/pasted-from-clipboard.png)
Quarto: R Markdown 2.0
![](https://s3.amazonaws.com/media-p.slid.es/uploads/2196364/images/9750427/pasted-from-clipboard.png)
Useful Links:
- Render a .Rmd
- Add code chunks
- Add equations with LaTex
- Add images, tables and citations
Try It Yourself
![](https://s3.amazonaws.com/media-p.slid.es/uploads/2196364/images/9756714/pasted-from-clipboard.png)
- Make a new .Rproj in RStudio
- Add a new .Rmd document to your project
- Render the default content
- Change the title of the document and render again
- Add a table of contents
Render This
output:
pdf_document:
toc: TRUE
- Write a sentence that contains inline R code
- What's the difference between these two examples?
Add Content: Code
I ate `r 2 + 5` pieces of chocolate.
```{r}
n_choc <- 7
```
I ate `r n_choc` pieces of chocolate.
- Add a sentence with a Greek Letter in it
- Add an equation block
- Switch to Visual Mode and back
Add Content: Math
This is the symbol for the greek letter lambda: $\lambda$
This is an equation:
$$
x + y = 17
$$
- Stay in Visual Mode
- Add a table using the Table menu
- Include a math symbol inside your table
- Change the caption of your table
Add Content: Table
- Stay in Visual Mode
- Drag and drop any image into your document
- Copy and paste an image into your document
- Insert a image using a link or local path
Add Content: Images
![local image](path/to/image)
![image from internet](image_url)
- Stay in Visual Mode
- Add a citation using the Insert -> Citation menu
- Use the Cross-Ref search to find a paper you know
- Add a sentence using that citation
Add Content: Citation
- Add cross-refs with {bookdown}
- Make advanced tables with {gt}
- Use templates to produce prettier documents (.docx)
What about..?
![](https://s3.amazonaws.com/media-p.slid.es/uploads/2196364/images/9756714/pasted-from-clipboard.png)
{bookdown} for more
Bookdown: Install
Bookdown: Cross-Refs
{gt} for beautiful tables
MS Word .docx
- RStudio's Visual mode
- Asking good questions
Getting Help
![](https://s3.amazonaws.com/media-p.slid.es/uploads/2196364/images/9756721/pasted-from-clipboard.png)
Tutorials and How-Tos:
- R Markdown Cookbook
- Almost any Intro to R course or textbook
Quick References:
Into the weeds: