3  Notebooks

3.1 What are notebooks?

Notebooks are documents that allow the mixture of code and text, allowing for literate programming. These documents can be converted to various output formats such as HTML, PDF, Slides, Word documents, books, etc.

They first appeared in Wolfram Mathematica and later popularized by Jupyter notebooks, formally IPython and used extensively in R as R notebooks and R Markdown documents.

Mixing code and its output with text, equations and images, allows us to create a powerful data analysis narrative, that details what we are performing and allows us to explain why we are doing it this way.

Many of this programming notebooks allow the mix of several languages in the same document, that facilitates polyglot programming tasks.

3.2 What is Markdown?

Markdown is a simple markup language created by John Gruber that allows to convert text to formatted HTML content. It was created to be easy to read and to write in text format. You can read more about it here.

Over time the format gained popularity and is now widely used. Several Markdown flavors exist nowadays.

The markdown syntax used R Markdown documents and R Notebooks is described here.

3.3 What is R Markdown?

You can find detailed documentation on R Markdown on the RStudio R Markdown website.

The R Markdown: The Definitive Guide book is an excellent resource to deep dive into these notebooks and learn what you can do with them.

R Markdown documents can be used to create websites (blogdown), or books (bookdown), static documentation (pkgdown), dashboards (flexdashboard), interactive documents, among many other formats.

These two presentations show the flexibility and usefulness of R Markdown documents:

3.4 The difference between R Markdown documents and R Notebooks

When we want to convert an R Markdown notebook to a given output format we need to knit the document first, and by doing so all the code will be executed in a seperate environment than the current user environment.

When using R notebooks you can preview the HTML output of the document, without needing to knit it first. Any time you save the notebook the HTML file will be updated, but no code is run, so the preview will show the results of the last execution of each chunk.

It is easy to change from an R Markdown notebook to an R Notebook document and vice-versa. So if you started with an R Notebook, just change the header from:

---
output: html_notebook
---

to:

---
output: html_document
---

The formatting syntax of both formats is the same.

The following presentation introduced R notebooks, and describe them in detail:

3.5 Quarto

Quarto is a command line tool and a notebook format that is able to convert notebooks in different formats PDF, HTML, MS Word, presentations and many other formats.

Quarto is not tied to R and can be used with many other languages, for instance Python, Julia and Observable.

Quarto can render R Markdown notebooks without modification in most cases, so the transition should be painless. There is a Quarto - FAQ for R Markdown Users that explains what is the planned future for R Markdown.

In addition to the Quarto official guide and Quarto official Reference, the awesome-quarto website provides a curated list of Quarto talks, tools, examples & articles, it is an excelent resource to learn more about Quarto.

Quarto features can be extended by extensions and filters.

The R for Data Science book has a chapter with a brief introduction to Quarto. The website A Quarto tip a day is also a great resourse to learn more about Quarto.

The following videos provide a good introduction to Quarto: