Skip to Content
Course content

76: Quarto as the Successor to R Markdown

Click on the "Edit" button in the top corner of the screen to edit your slide content.

A few years ago, I was helping a colleague who had spent three days trying to polish a 40-page R Markdown report for a board meeting. They needed the report in both PDF and HTML, but the layout requirements were completely different for each. They ended up with a YAML header that looked like a chaotic mess of conditional logic and custom CSS hacks just to get a few images to sit side-by-side in the browser. They were spending more time fighting the rendering engine than actually analyzing the data. That's the exact moment I realized that while R Markdown was a revolution, we had finally hit the ceiling of what a purely R-centric package could do.

Enter Quarto. If you've spent any time with R Markdown, Quarto will feel like home, but with the training wheels removed. Essentially, Quarto is the next-generation version of R Markdown. The biggest shift is that Quarto isn't just another R package; it's a standalone open-source scientific publishing system. It uses the same underlying logic—Pandoc and knitr—but it moves the "brain" of the operation outside of R. This means you get a consistent experience whether you are using R, Python, Julia, or Observable JS.

Moving Beyond the .Rmd File

You'll notice the file extension changes from .Rmd to .qmd. At first glance, they look identical. You still have your YAML header at the top and your code chunks in the middle. But under the hood, Quarto handles the rendering process much more efficiently. In the old R Markdown workflow, you were heavily dependent on the rmarkdown package being updated and compatible with your specific version of R.

With Quarto, the rendering is handled by the Quarto CLI (Command Line Interface). I personally find this much more robust. It allows you to render documents from the terminal without even opening RStudio if you want to. More importantly, it means the core publishing features—like cross-referencing, citations, and layout controls—are standardized across different languages. You aren't just writing an "R document"; you're writing a "Quarto document" that happens to execute R code.

The Power of Polyglot Notebooks and Modern Layouts

One of the things that really sells me on Quarto is how it handles "polyglot" workflows. In the R Markdown days, mixing Python (via reticulate) and R felt like a bit of a kludge. In Quarto, it's a first-class citizen. You can have an R chunk that cleans a dataset and a Python chunk that runs a specific machine learning library on that same data, all within one .qmd file, without the usual headache of environment mismatches.

But the real "quality of life" improvement is in the layout. Remember those CSS hacks my colleague was using? Quarto introduces "Layout Panels." Instead of writing complex HTML or fighting with knitr options, you can use a simple div syntax to create columns or tabsets. For example, if you want two plots side-by-side, you can wrap them in a ::: {layout-ncol=2} block. It's a small change, but when you're building a professional dashboard or a technical report, it saves you hours of frustration.

---
title: "Quarterly Analysis"
format: html
---

## Data Comparison

::: {layout-ncol=2}
```{r}
#| label: plot1
plot(cars)
```

```{r}
#| label: plot2
hist(cars$speed)
```
:::

Notice the #| syntax inside the chunk? Those are "hash-pipe" options. They replace the old comma-separated arguments in the {r, fig.width=5} header. I highly recommend switching to this style immediately; it's much cleaner and makes your code chunks look like actual code rather than a mixture of R and metadata.




📋 Practical Task

Building a Comparative Analysis Report with Quarto Tabsets

Your task is to create a .qmd file that demonstrates Quarto's superior layout capabilities over standard R Markdown. Instead of a long scrolling page, you will build a report that uses tabsets to organize different views of the same data.

Requirements:

  • Create a new Quarto document (.qmd) titled "Iris Dataset Exploration".
  • In the YAML header, set the format to html.
  • Create a section heading called "Visualizations".
  • Use a Quarto div (::: {.panel-tabset}) to create three tabs: "Scatter Plot", "Boxplot", and "Summary Stats".
  • Inside the "Scatter Plot" tab, use a hash-pipe option (#|) to set the figure caption to "Sepal Length vs Width".
  • Inside the "Boxplot" tab, create a plot of Sepal.Length grouped by Species.
  • Inside the "Summary Stats" tab, print the summary() of the Iris dataset.
  • Render the document to HTML and verify that you can toggle between the three views without reloading the page.
Rating
0 0

There are no comments for now.

to be the first to leave a comment.