Tutorial: Hello, Quarto
You can work through this tutorial using R or Python code examples. Select your preferred language:
You’ve selected to see examples in R. You can toggle to Python whenever you like throughout the guide.
You’ve selected to see examples in Python. You can toggle to R whenever you like throughout the guide.
Overview
Quarto is an open-source scientific and technical publishing system that weaves together code and narrative to produce high-quality documents, presentations, websites, and more. In this tutorial, you’ll learn how to use Positron with Quarto.
Positron comes ready to work with Quarto out-of-the-box — it includes both the Quarto command line interface and the Quarto VS Code extension.
It includes many tools that enhance working with Quarto, including:
Integrated render and preview for Quarto documents
Completion and diagnostics for Quarto options
Positron’s full R and Python support for code that is inside a Quarto document, including interactive execution of code in the Console, code completion, help, and diagnostics.
Here’s a sample Quarto document, hello.qmd
, open in Positron, demonstrating the seamless side-by-side editing and preview experience:
On this page, you’ll learn:
The basic edit, then preview, workflow for Quarto documents in Positron.
The three components a Quarto document—header, code cells, and markdown—and how they combine to produce a rendered output.
Setup
If you would like to follow along with this tutorial in your own environment, follow the steps outlined below.
Be sure that you have installed the
rmarkdown
,tidyverse
andpalmerpenguins
packages:install.packages("rmarkdown") install.packages("tidyverse") install.packages("palmerpenguins")
Download the Quarto document (
hello.qmd
) below and open it in Positron.
Install the
jupyter
andplotnine
packages using your preferred method. For example, withpip
:pip install jupyter plotnine
Download the Quarto document (
hello.qmd
) below and open it in Positron.
Basic Workflow
Quarto documents with the extension .qmd
are a plain text format and will open in Positron’s Editor pane.
To preview the document, execute the Quarto: Preview command. You can alternatively use the keyboard shortcut , or the Preview button () in the editor toolbar:
Quarto will process the document, and the output will preview in the Viewer pane.
The preview will update whenever you rerun the Quarto: Preview command. For example, change the section heading ## Meet the penguins
to ## Meet the Palmer penguins
and rerun the Quarto: Preview command. The preview in the Viewer will update to reflect the change.
If you prefer the preview to update whenever you save the document, you can check the Render on Save box in the editor toolbar.
Rendering
The document, hello.qmd
, is a combination of markdown and executable code cells. Quarto uses the term render to describe the process of taking this source document and producing a new file that combines the output from the executed code cells with the markdown. When hello.qmd
is rendered, the new output is hello.html
, an HTML document, but it could be a PDF, MS Word document, presentation, website, book, interactive document, or other format.
This is the basic model for Quarto publishing—take a source document that combines code and narrative, and render it to a variety of output formats.
The Quarto: Preview command encompasses two actions: rendering the document, and previewing the resulting file. HTML and PDF formats will open in Positron’s Viewer pane resulting in a side-by-side preview. Other formats, like MS Word, will open externally.
You can also render the document without previewing it by executing the Quarto: Render Document command.
When you run the Quarto: Preview command, you will notice the Terminal executes quarto preview
:
The Quarto extension provides Positron commands as convenient alternatives to running quarto
commands in the Terminal, but you can also run the commands directly if you prefer.
How it works
When a Quarto document includes executable code cells, Quarto uses what is known as an engine to execute them. If you’re following along with this tutorial with R, you have been using the knitr
engine. If you’re following along with Python, you have been using the jupyter
engine. You can read more about how Quarto chooses an engine in Engine Binding.
Quarto supports other languages in addition to R and Python for code cells like Julia (via the julia
engine or the jupyter
engine) and Observable JS.
Next Up
You now know the basics of creating and authoring Quarto documents. The following tutorials explore Quarto in more depth:
Tutorial: Computations — Learn how to tailor the behavior and output of executable code blocks.
Tutorial: Authoring — Learn more about output formats and technical writing features like citations, crossrefs, and advanced layout.