```{r}
#| label: readin-csv
#| code-line-numbers: false
#| eval: false
# regular comment, not a hash pipe
<- read_csv("wine.tsv")
wine ```
Literate programming
University of Luxembourg
Tuesday, the 4th of March, 2025
You will learn to:
Absolute paths are NOT portable
Relative paths are
Create the practicals
RStudio project
Source data ➡️
Intermediate ➡️
Analysis ➡️
Manuscript ➡️
One workflow
Literate programming is the practice of mixing code and descriptive writing in order to execute and explain a data analysis simultaneously in the same document.
— William Landau Developer of {targets}
For a bioinformatician, pure programming is barely happening, we need reports/websites where content and formatting are disconnected
Even better to separate content and rendering, outsourced to continuous integration/development.
Source: {targets} user manual
Predecessor of Quarto. Files are .Rmd
.
Version 1 in 2016, the idea was to have text and code in one document, execute code and let the final markdown converted to different formats by pandoc
.
Credit: Artwork by Allison Horst
Extended Rmarkdown. Languages and IDE agnostic
.qmd
) document to various formats (PDF, HTML…)<!DOCTYPE html>
<html>
<body>
<h1>This is a heading</h1>
<p>This is some text in a <b>paragraph</b></p>
<h2>This is a second level heading</h2>
<ul>
<li><a href="http://exa.com"><code>site</code></a>
<li><img src="https://images.computerhistory.org/revonline/images/500004391-03-01.jpg?w=200">
</ul>
</body>
</html>
#
, ##
, ###
…http://example.com
is auto-linked[site](http://example.com)


for alternative descriptionUse the 140 language syntax pandoc
knows
code
with backticks (`code`
)```
This is *verbatim* code
# Even headers are not interpreted
```
rendered as:
This is *verbatim* code
# Even headers are not interpreted
knitr
YAML header
Free text in Markdown
Code chunks to be interpreted
knitr
for jupyter
for QuartoNotebookRunner.jl
package for julia
Observable
Under File, pick Quarto Document
```
)#|
#| echo: true
#| eval: true
#| fig-width: 9
Use backticks (`
) followed by the keyword {r}
:
`{r} some code`
1 + 1 = `{r} 1 + 1`
=> renders as 1 + 1 = 2 .
More useful:
swiss dataset:`{r} nrow(swiss)`
rows
=> renders as swiss dataset: 47 rows.
docx
)Dataset | # rows | Description
----------|------------------:|-------------------
swiss | `{r} nrow(swiss)` | Swiss Indicators
datasaurus| 1846 | 13 datasets of same mean
Dataset | # rows | Description |
---|---|---|
swiss | 47 | Swiss Indicators |
datasaurus | 1842 | 13 dataset of same mean |
knitr::kable()
as_tibble(swiss, rownames = "Province") |>
select(Province:Agriculture) |>
slice_head(n = 5) |>
knitr::kable(caption = "Swiss Socioeconomic Indicators (1888)")
Province | Fertility | Agriculture |
---|---|---|
Courtelary | 80.2 | 17.0 |
Delemont | 83.1 | 45.1 |
Franches-Mnt | 92.5 | 39.7 |
Moutier | 85.8 | 36.5 |
Neuveville | 76.9 | 43.5 |
How to add equations
Enclose in $
for in-line equations
$a^2+b^2=c^2$
renders as \(a^2+b^2=c^2\).
Double ($$
) for separate equations.
$$G_{\mu v}=8 \pi G (T_{\mu v} + \rho _\Lambda \ g_{\mu v}) $$
renders as:
\[G_{\mu v}=8 \pi G (T_{\mu v} + \rho _\Lambda \ g_{\mu v})\]
You learned to:
Quarto
(qmd
)Markdown
render
to different output formatsAcknowledgments 🙏 👏
Thank you for your attention!