library(ggplot2)
ggplot(airquality, aes(Temp, Ozone)) +
geom_point() +
geom_smooth(method = "loess"
)
Literate programming in Quarto
Quarto, like R Markdown, allows you to do literate programming.
Literate programming is writing out the program logic in a human language with included (separated by a primitive markup) code snippets and macros.
Quarto is based on Pandoc and uses its variation of markdown as its underlying document syntax.
Autonomy of a Quarto document
Markdown basics
Quarto is based on Pandoc and uses its variation of markdown as its underlying document syntax:
Reminder that the visual editor mode in RStudio provides features for authoring in Markdown.
Text Formatting
Markdown Syntax | Output |
---|---|
|
italics and bold |
|
superscript2 / subscript2 |
|
|
|
verbatim code |
Headings
Markdown Syntax | Output |
---|---|
|
Header 1 |
|
Header 2 |
|
Header 3 |
|
Header 4 |
|
Header 5 |
|
Header 6 |
Links & Images
Images can be saved in the folder of your post.
Markdown Syntax | Output |
---|---|
|
https://quarto.org |
|
Quarto |
You can also create links between pages on your site:
[about](about.qmd)
[about](about.qmd#section)
Source Code
Use ```
to delimit blocks of source code:
```
code
```
Add syntax highlight code blocks by specifying a language:
```python
1 + 1
```
Fenced divs
You can add classes, attributes, and other identifiers to regions of content using divs and spans:
Borders
::: {.border}
This content can be styled with a border :::
This content can be styled with a border
Callout notes
:::{.callout-note}
Note that there are five types of callouts, including: `note`, `tip`, `warning`, `caution`, and `important`.
:::
Tabsets
::: {.panel-tabset}## Tab 1
Hello!
## Tab 2
Hello again! :::
Hello!
Hello again!
Using R/Python/Julia/Observable
Quarto supports executable code blocks within markdown.
```{r}
|> with(plot(hp, mpg))
mtcars ```
Calling engines
- Need to have the appropriate engine installed.
- Quarto can guess the engine or you can call it explicitly in the YAML.
---
title: "matplotlib demo"
format:
html:
code-fold: true
jupyter: python3
---
---
title: "ggplot2 demo"
author: "Norah Jones"
date: "5/22/2021"
format:
html:
fig-width: 8
fig-height: 4
code-fold: true
---
Code Blocks
Code blocks that use braces around the language name (e.g. {r}
) are executable, and will be run by Quarto during render.
Execution options
You can customize executed code with execution options. They can be specified globally:
---
title: "My Document"
execute:
echo: false
jupyter: python3
---
Or on a per-chunk basis:
```{python}
#| echo: true
import matplotlib.pyplot as plt
1,2,3,4])
plt.plot([
plt.show()```
Note the use of the hashpipe #|
at the top of the chunk.
Rendering documents
To render, options include:
- Use the RStudio “Render” button or the “Build” tab
- Use the command line interface
quarto render