Rendering professional documents with Quarto

Quarto
code
LaTeX
Author

Edwin Alvarado-Mena

Published

November 15, 2024

Photo: Bob Demers/UA News

Producing high-quality documents and reports is of paramount importance during your PhD life.

Even if you are not minoring in methods, you must take a few statistics courses along your doctoral journey at the SGPP.

Methods courses’ assignments are especially tricky as you must combine plain text, code, and results.

In general, instructors will expect to see, say, a fancy table with regression coefficients and other statistics. But you must also discuss your data, methods, and findings.

OK. You’ll then look for a text editor. Microsoft Word or Google Docs may be your immediate choices.

So, you create a new Microsoft Word document, write some paragraphs about research design, insert screenshots of the relevant figures and tables, etc. 

Screenshots, however, do not look very professional…

To make things worse, instructors will often want you to showcase your programming thinking. Technical questions will be asked. How did you wrangle the data? How did you set the relevant variables? How did you fit the models?

Therefore, you must add code to your prose.

You might be tempted to take screenshots of the R console and insert them into the document.

Once again, copy-pasting screenshots is not very professional…

We need tools that are better than Microsoft Word or Google Docs for high-quality scientific writing.

A model Quarto document

Luckily, we have Quarto documents!

Quarto is an open-source software for scientific publishing. It is included in RStudio—You don’t have to install anything else.

Quarto documents can combine plain text, code, and code output. No need for screenshots.

Plus, Quarto documents can be rendered into multiple formats, including PDF, which makes them great for PhD assignments.

You can create Quarto documents in RStudio by clicking File > New File > Quarto Document.

RStudio will open a Quarto document where you can write, program, and render into a professionally-looking PDF document.

You’ll see a block of YAML metadata at the top of the Quarto document. YAML metadata provides a lot of room for customization. You can modify those parameters at will.

To make things easier, I have granted you access to a GitHub repository with a model Quarto document ready to be rendered into a PDF file. Feel free to use this repository as a model for your grad school submissions.

Notice that this GitHub repository follows the guidelines for working directory organization I listed in another blog post.

As you’ll see, Quarto makes it possible to do cool things such as printing both code and code output, managing references, and inserting \(\LaTeX\) math.

R or Python? Why not both!

You can even combine R and Python chunks in Quarto! Have a look:

## This is R
toupper("hola")
[1] "HOLA"
Install package

You must install and load the reticulate package prior to running Python code: library(reticulate).

## This is Python
"hola".upper()
'HOLA'

Furthermore, you can call objects from an R environment while programming in a Python chunk, and vice-versa, which means that you can build bilingual workflows:

## This is R
string <- "hola"
## This is Python calling an object from the R environment
r.string.upper()
'HOLA'

So you can switch between R and Python, making the most of both languages. This feature is truly awesome! It has dramatically enhanced my productivity.

Let’s say that your data-wrangling skills are quite good in R because of your mastery of the dplyr package. It may be the case that you’re working on a project that requires Natural Language Processing (NLP) libraries that exist in Python only. Quarto lets you combine both languages! There’s no need to make tough decisions.

Other uses

Of course, you can render fancy documents in Quarto even if equations or programming are not involved.

You could write your comprehensive examination or your prospectus in Quarto. Those documents will have a unique look that speaks volumes about your professionalization (trust me, demonstrating professionalization is critical in grad school).

And you could create your personal website in Quarto. Actually, this blog is made with Quarto—The GitHub repository is public, so please feel free to fork it.

There’s a detailed user guide to Quarto. You can visit it here. If you have questions about Quarto’s many uses, this is the first place you should look. 

I hope you fall in love with Quarto as much as I have.