Goals

  • You know what markdown is.
  • You know what you can do with Quarto and Rmarkdown.
  • You can create your own Quarto and Rmarkdown files.

What is markdown?

  • It is a very simple document markup language. That is, it is a way to format a text.
  • Similar but much simpler than html, or rtf.
  • E.g. putting an asterisk around the text will make it italic and two asterisks bold:
    *example* becomes example
    **another example** becomes another example
  • markdown was developed in 2004 by John Gruber as an easy way to create texts on websites.

  • Texts in markdown are rendered (translated) to other markup languages before they are turned to webpages or documents.
  • The idea is: You type a text with basic format tags and later let the computer render it to a more complex format.
  • Due to its simplicity, markdown can be converted to html, latex, docx, rtf, ect. files.
  • Markdown is widely applied on various sites (e.g., GitHub, Reddit, Diaspora, OpenStreetMap, sourceForge).

Markdown

A text like this:

# Chaper 1

> If something is true, no amount of wishful thinking will change it *-Richard Dawkins*

We will discuss the following ideas:

1. The meaning of **life**
2. The end of **suffering**
3. The **noble eightfold path**

| Sanskrit| Meaning                                                           |
|---------|-------------------------------------------------------------------|
| dukkha  | suffering is an innate characteristic of existence.               |
| samudaya| together with *dukkha* arises *taṇhā* (craving).                  |
| nirodha | *dukkha* can be ended or contained by letting go of this *taṇhā.* |
| magga   | The *noble eightfold path* leads to the confinement.              |

Tabel 1: [The four noble truths](https://en.wikipedia.org/wiki/Four_Noble_Truths)

Three outputs:

Rmarkdown

  • Rmarkdown is an extension to markdown.
  • Specifically developed to combine data analyses (scripts and output) within a document.
  • Think of it as an integration of a text-processing program and R code.
  • You can write a text and implement tables, plots, figures etc. analysed with R.

Why use Rmarkdown?

  • Rmarkdown helps to make your research:
    • Transparent
    • Reproducible
    • Organized
    • Communicable

Why use Rmarkdown?

  • You can create individualized reports
    • E.g. results with a standard text for each participant in a study comprising their own data
    • E.g. individual analyses for each single school or classroom but with a common text.
    • You can even adapt text blocks depending on parameters and specific results (e.g. skip certain passages for special schools but not for primary schools)

Task

Before we go on, you have to start your first Rmarkdown document:

  • Create a new source file in R. Choose “Text File” as the format.
    File New File Text File
  • Save it under the name “first_mardown.qmd”
    (you can name it as you like as long as it ends with “.qmd” –> Quarto Markdown).
  • Now, at the lower right corner of your source panel you should find “Quarto” as an indicator of the file type.
  • Also, at the top of the source file you should find

Basic markdown: header

  • Normally written text appears as unformatted text.
  • You can format text into a header with the # symbol:
# A level one header
## A level two header
### A level three header
#### A level four header

Basic markdown: Emphasise

  • Italic text is put between * symbols (or _).
  • Bold text between ** symbols.
  • Italic and bold text between *** symbols.

This is *italic* this is **bold**, and ***this is both!!!***.

This is italic this is bold, and this is both!!!.

Basic markdown: Lists

An unordered list:

- Helmut
- Gerhard
- Angela

An ordered list:

1. Bush
2. Obama
3. Trump

Combined:
  
1. Sour
  - Lime
  - Envy
2. Sweet
  - Honey
  - love

Chunks

  • Chunks are portions of R code within a markdown file.
  • A chunk for R has the following structure:
# Here comes the R code
  • An empty chunk can be inserted directly through the button .

Chunk Options

  • Chunk options specify the “behaviour” of a chunk.
  • They start with #| and each option in set in a separate line.

e.g.:

```{r}

#| echo: false

#| include: false

# Here comes the R code
```

  • echo: false suppresses the inclusion of the original R code and only output is reported.
  • include: false executes the R code but does not report anything
  • message: false excludes additional messages given by a function.
  • warning: false exclude warnings created by a function.

Task

  • Create a Quarto document with a “meaningful” header:

    ---
    title: "My first document"
    author: "Your name"
    date: today
    abstract: This is an interesting paper
    format: html
    ---
  • Add the example markdown code from above: Markdown

  • Render the document

Additional resources for Rmarkdown