Introduction

What is Markdown?

“R markdown is a simple and easy to use plain text language used to combine your R code, results from your data analysis (including plots and tables) and written commentary into a single nicely formatted and reproducible document…” [Douglas et. al. 2026]

Online Resources and Textbooks

Source Name Link
Markdown Basics https://rmarkdown.rstudio.com/authoring_basics.html
An Introduction to R https://intro2r.com/
R Markdown: The Definitive Guide https://yihui.org/rmarkdown/
R for Data Science: R Markdown https://r4ds.had.co.nz/r-markdown.html
Getting Started with R Markdown - Guide and Cheatsheet https://www.dataquest.io/blog/r-markdown-guide-cheatsheet/

Setting up Markdown

R Markdown must first be installed:

{r} install.packages('rmarkdown')

If you want to export your document as a PDF, you will need to install TinyTeX.

install.packages('tinytex')
tinytex::install_tinytex()

2 Ways to Code

When working in a Markdown document, you should see two options: Source and Visual.

Source allows you to work in the classic R fashion. Visual creates a working area that is almost like a Word document. You can insert tables, code chunks, images and so much more just as you would in Word or Google Docs!


Setting up your document

To create a document as a Markdown:

\[File -\> New File -\> R Markdown\]

Type in the name of your document in the ‘Title’ tab and your name in the ‘Author’ tab. Select HTML as the default option.

When you first open a Markdown document, some text should appear. It will provide some basic Markdown information. Feel free to delete this text.

YAML HEADINGS

A YAML header is where all the important document-relevant information goes. It is created with with three dashes, as shown below.

---
title: "THIS IS AN R SCRIPT!"
author: "Spiderman"
date: "25/02/2004"
output: pdf_document
---

You may also change the output to be: html_document.


Some Basic Notation

Headings

In a markdown document, the “#” symbol generates a heading. More “#” will result in smaller text. For example:

##### Drink
### more
# water

yields headings in increasing size order

Drink

more

water!!

Text

To add text (like this sentence you are reading right now), simply type your code into the script:

Hello world! :)

Code Chunk

To insert a code chunk, you must surround relevant code with three back-ticks (```). Additionally, add {} to the end of your first set of back-ticks.

```{r}

cool_numbers <- c(69, 420, 67, 21) print(cool_numbers)

```

You can also add further specifications to your code chunk. For example:

{r, chunk-label, fig.width=2}

Here is a table of specifiers:

Code action
include = FALSE prevents code and results from appearing
echo = FALSE prevents the code, but not the results from appearing
message = FALSE prevents messages generated by code from appearing
warning = FALSE prevents warnings generated by code from appearing
fig.cap = “…” adds caption to graphical results
fig.align = Center centers your figure caption
fig.width = defines figure width
fig.height = defines figure height
fig.show = ‘hide’ hides the figure in the final document

to include figures generated in ggplot, you will need to load the library within your code chunk!

{r, simple-ggplot, echo = FALSE}
x <- 1:10
y <- 10:1
dataf <- data.frame(x = x, y = y)

library(ggplot2)
ggplot(dataf, aes(x = x, y = y)) + geom_point()

Commenting within code

To comment out text WITHIN your script that you do NOT want to show in the final document:

<!-- SECRET CODING NOTES -->

Lists

- item 1 
- item 2 
  + sub-item 2 
  + sub-item 3 
- item 3 
- item 4 
  • item 1
  • item 2
    • sub-item 2
    • sub-item 3
  • item 3
  • item 4

Ordered Lists

1. item 1 
2. item 2 
    + sub-item 2 
    + sub-item 3 
3. item 3 
4. item 4 
  1. item 1
  2. item 2
    • sub-item 2
    • sub-item 3
  3. item 3
  4. item 4

Tables

To insert a table, here is the basic code:

| Syntax      | Description | Test Text     |
| :---        |    :----:   |          ---: |
| Header      | Title       | Here's this   |
| Paragraph   | Text        | And more      |
Syntax Description Test Text
Header Title Here’s this
Paragraph Text And more

Images

Fish?
Fish?

To insert an image from your computer into your Markdown document:

![Image Description](images/huh.jpg)