Tutorial 5 - Introduction to Quarto

Digital Causality Lab

4/19/22

Introduction to Quarto

Introduction

  • Quarto is a relatively new framework to generate dynamic content, like
    • (Automated) Reports that involve Python, R, julia or other code
    • Blogposts, websites, pdf files, slideshow, jupyter notebooks, interactive apps, MS office documents
    • Documents including references (e.g. .bib files) and math formula (LaTeX)
    • Thereby, Quarto has a unified syntax that is based on markdown
  • In the Digital Causality Lab, we’ll use Quarto as a framework to develop causal data products

Introduction

  • The idea of Quarto can be summarized as

Weave together narrative text and code to produce elegantly formatted output (quarto.org)

  • Installation guidelines & getting started guide
    • Get Started
    • Go through the Quarto Guide to find out more
    • Topics: Basic syntax, computations, document types, output type (tables, figures, etc.)

Introduction: IDE

  • To work with Quarto, we need to use an Interactive Development Environment (IDE), for example
  • Both IDEs come with handy add-ons, features and templates that facilitate your start with Quarto

RStudio

VS Code

Figure 1: IDEs for Quarto.

Introduction: RStudio

  • In Digital Causality Lab, we highly recommend to use RStudio with Quarto.
  • Like R Markdown, Quarto uses Knitr to execute R code, and is therefore able to render most existing .Rmd files without modification.

Introduction: RStudio

Basic Workflow

  1. Use the File -> New File -> Quarto Document… command to create new Quarto documents.

Introduction: RStudio

Basic Workflow

  1. Use the Render button to preview documents as you edit them.
    • In the setting, you can freely choose whether you want to preview documents
      • in Window / Browsers or
      • in Viewer Pane of R (more convenient)

Introduction: RStudio

Basic Workflow

  1. Generate a basic model for Quarto publishing.
    • Take a source document and render it to a variety of output formats, including HTML, PDF, MS Word, etc.

Introduction: VS Code

Introduction: VS Code

Basic Workflow

  1. Open a new quarto document .qmd file and render

    • You can choose what output you want to render, .pdf, .html, .docx, \(\ldots\)
  2. Render using the VS Studio features (Ctrl + Shift + k) or command line Quarto Render

  3. View preview and/or open rendered file

Introduction: VS Code

  • See the example Hello Quarto
    • It contains a combination of markdown and executable code cells.
    • The document on the left is rendered into the HTML version. Its preview could be seen on the right.

Markdown Syntax

Basics of Markdown Syntax

  • The Quarto documentation has a chapter on Markdown Basics

  • Most importantly, you can use the syntax to format text

    • *italics* and **bold** \(\rightarrow\) italics and bold
    • superscript^2^ / subscript~2~ \(\rightarrow\) superscript2 / subscript2
    • ~~strikethrough~~ \(\rightarrow\) strikethrough
    • Use `verbatim code` \(\rightarrow\) verbatim code
  • Use # to format headers / section or slide titles

    • More #’s, the smaller the header

Basics of Markdown Syntax

  • Links and images
    • <digitalcausalitylab.github.io> \(\rightarrow\) <digitalcausalitylab.github.io>
    • [DigitalCausalityLab](digitalcausalitylab.github.io) \(\rightarrow\) DigitalCausalityLab
    • ![DCL Logo](logo.png) \(\downarrow\)

DCL Logo

Basics of Markdown Syntax

Lists

* unordered list
    + sub-item 1
    + sub-item 2
        - sub-sub-item 1
  • unordered list
    • sub-item 1
    • sub-item 2
      • sub-sub-item 1

Tables

| Right | Left | Default | Center |
|------:|:-----|---------|:------:|
|   12  |  12  |    12   |    12  |
|  123  |  123 |   123   |   123  |
|    1  |    1 |     1   |     1  |
Right Left Default Center
12 12 12 12
123 123 123 123
1 1 1 1

Basics of Markdown Syntax

Code

Include code as

```{r}

1 + 1

```

1 + 1
[1] 2

Basics of Markdown Syntax

Equations / formulae

  • Formualae work just the same as in latex

  • inline math: $E = mc^{2}$ \(\rightarrow\) inline math: \(E = mc^{2}\)

  • $$E = mc^{2}$$ \(\downarrow\)

\[E = mc^{2}\]