Quarto: The successor to R Markdown | R-bloggers

Quarto: The successor to R Markdown | R-bloggers

The Data SandboxR-bloggershereclick herehere [This article was first published on , and kindly contributed to R-bloggers ]. (You can report issue about the content on this page here Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

RMarkdown has been a staple for any Data Scientist that programs in . builds on that, with multiple language support and additional features. Because of its language independent design, requires an independent installation. (“Quarto,” n.d.) I have spent the past week moving my blog from to . There have been some challenges, but I am pretty happy with the new look. Let’s start with the setup, it’s a little more work than a regular package or module.

The setup for Quarto is pretty simple. You will need to visit the quarto website to download the Quarto Command Line Interface (CLI). There are step-by-step instructions for your selected text editor. I am most familiar with RStudio for and VSCode for . For Rstudio, it’s pretty much just plug and play now. I did install the package, but all the commands can be done by the command line interface. Switching from is as simple as saving them as file. The process for Quarto for RStudio can be described by the following process flow: It is not much more difficult for VSCode, all you need to do is download the Quarto extension. The process flow is similar to RStudio but uses Jupyter instead of knitr. With the setup complete, there should be no differences between text editors.

The first new feature to explore the support for code chuck options within the code chunks. These options would usually live within the code chunk title line. Any supported option can be added with the tag. This feature is useful for situations with many options, as it does increase readability.

One of the neat new features is code-folding. When this feature is enabled in the qmd YAML, the person viewing the document can hide/unhide code chunks. This can make it easier for them to read the document. Only the code will be hidden, and not the results. This feature is enabled by making the following addition to the YAML. You would change the format from HTML to your required format, such as PDF. With the addition of the parameter, the reader can decide to hide all code chunks from the top of the document.

Quarto provides a bunch of additional tools for displaying figures. You can assign values for captions, sub-captions, width and height. You can even create a figure with multiple plots with separate sub-captions. ```{r}
#| label: fig-sleep
#| fig-cap: "Sleeping habits of animals"
#| fig-subcap:
#| - "Scatter plot of body weight by total sleep"
#| - "Violin plot of REM sleep by vore"
#| layout-ncol: 2

msleep %>%
drop_na(sleep_total, bodywt) %>%
ggplot(aes(y= sleep_total, x = bodywt)) +
geom_point(color = "blue") +

msleep %>%
group_by(vore) %>%
drop_na(sleep_rem, vore) %>%
ggplot(aes(y= sleep_rem, x = vore)) +
geom_violin(aes(fill = vore)) +
``` You can now use cross-referencing for the figure by referencing the figure. This means that in your text, you can refer to the figure number and link to the figure. This will automatically update your figure numbers and is achieved by typing the ‘@’ symbol followed by the figure label. As an example, ‘@fig-sleep’ turns into Figure 1. There is an additional option to let the figures take up the width of the entire page, but I would not recommend using it as it extends beyond the width of the body of your page. It requires the following code:

A reader may not be familiar with all the functions that you use in your document, so it may be useful to enable code linking. With code linking, a function in a code chunk will have a hyperlink to the documentation for that function. To work in , this feature requires the and packages.

I think the best feature for is the floating table of contents. I can’t describe how much time and effort I’ve spent trying to get a floating table of contents in a blog. It didn’t work for me, it would require getting deep into the weeds changing the CSS layout for my HUGO theme. It was not worth the effort. Adding a floating table of contents in is simple. Just use the following code in the document YAML: One simple line of code in the YAML and your document has a floating table of contents. There is some additional customization such as the level of headers, location and title.

With my experimentation with Quarto, I decided to move my blog to . In theory, this should be a simple switch, with just copying all post from folder to another. can use rmd files, but they can easily be changed over to qmd files. I decided to switch all my post to the qmd format and include some additional features. The Quarto site has extensive reference information for creating a blog. (“Quarto,” n.d.-) I did have an issue with one of my post not rendering correctly. This maybe an issue with compatibility with the package. In the end, I decided to just remove the post altogether as I could get it to render correctly, and I prefer the over the package for creating good-looking tables.

Images Powered by Shutterstock