Code
# Example Code Chunk
# This is an R code chunk that generates a scatter plot
<- c(1, 2, 3, 4, 5)
x <- c(2, 4, 1, 3, 5)
y plot(x, y, main = "Scatter Plot Example", xlab = "X-Axis", ylab = "Y-Axis")
Quarto is an open-source, multi-language, publishing system created by Posit (formerly known as RStudio). It is designed to enable the creation of dynamic documents, including reports, presentations, websites, books, and more. Quarto builds upon the foundation of RMarkdown, extending its capabilities to support multiple programming languages and various output formats. Quarto integrates code, text, and media into a single document that can be rendered into various formats. It supports languages like R, Python, Julia, and JavaScript, making it ideal for scientific writing, data analysis, and technical documentation. This chapter introduces the basics of Quarto, its features, and how to get started using it for your projects.
Multi-language support: Quarto allows the integration of code from different programming languages in a single document.
Output formats: Quarto can generate HTML, PDF, Word documents, presentations (using reveal.js or PowerPoint), and even websites.
Integration with RStudio: Quarto is deeply integrated with RStudio, making it easy to create and render documents within this IDE.
Articles and Reports: Quarto is widely used for creating dynamic articles and reports that can include code, figures, and references.
Websites: You can use Quarto to build entire websites, integrating multiple pages and even blogs.
Presentations: Quarto allows you to create interactive presentations with support for multimedia content.
Books: You can use Quarto to write and publish online books, with support for multiple chapters, references, and more.
To begin using Quarto, you need to have an appropriate text editor installed. Quarto supports various editors, including RStudio, Jupyter, Neovim, Visual Studio Code (VS Code), and even plain text editors like e.g. Vim.
Install RStudio: Download and install the latest version of RStudio from the Posit website.
Create a Quarto file: Open RStudio and navigate to “File” > “New file” > “Quarto Document” to create a new .qmd
file.
Quarto documents can be rendered into different formats using either the command line or the RStudio GUI.
quarto preview
This command opens a live preview of your document in a web browser. The preview automatically updates each time you save the document. If you open your quarto file in Rstudio there is also a render
button at the top of the GUI.
quarto render
This command generates the final output based on the specified format in the YAML header (e.g., HTML, PDF).
Where to run these commands: Open your terminal or command prompt and navigate to the directory where your Quarto file (e.g., your-document.qmd) is located.
Quarto uses Markdown, a lightweight markup language, for formatting text. Markdown is easy to learn and widely used in various platforms, including GitHub, Slack, and RStudio.
Markdown allows you to easily format text. Here are some common formatting options:
**bold text**
*italicized text*
`code`
> blockquote
Markdown supports both ordered and unordered lists:
Unordered list:
- Item 1
- Item 2
- Item 3
Ordered list:
1. First item
2. Second item
3. Third item
You can create tables in Markdown using the following syntax:
| Header 1 | Header 2 |
|----------|----------|
| Cell 1 | Cell 2 | | Cell 3 | Cell 4 |
Quarto supports LaTeX syntax for rendering mathematical equations:
Inline math: $E = mc^{2}$
Display math:
$$E = mc^{2}$$
You can easily add links and images in Markdown:
[Link Text](http://example.com)
![Alt Text](http://example.com/image.jpg)
The YAML header at the beginning of a Quarto document contains metadata that controls how the document is rendered. This includes the title, author, date, and output format.
---
title: "Document Title"
author: "Your Name"
format: html
theme: default
---
One of the key features of Quarto is the ability to include executable code chunks within your document. These chunks can be written in various programming languages and are executed during rendering.
Code
# Example Code Chunk
# This is an R code chunk that generates a scatter plot
<- c(1, 2, 3, 4, 5)
x <- c(2, 4, 1, 3, 5)
y plot(x, y, main = "Scatter Plot Example", xlab = "X-Axis", ylab = "Y-Axis")
This code will be executed when the document is rendered, and the output (a scatter plot) will be included in the final document.
Quarto documents (.qmd
files) are plain text, making them ideal for version control using Git. You can take advantage of Git’s branching and merging capabilities to manage complex document edits and resolve conflicts efficiently. Check out our Version Control Book for more information about hwo to use Git.
Quarto is a powerful tool that brings together the best features of Markdown, RMarkdown, and modern programming environments to create dynamic, reproducible documents. Whether you’re writing a research paper, building a website, or preparing a presentation, Quarto provides the tools you need to streamline your workflow and enhance your output. By mastering the basics covered in this chapter, you’ll be well on your way to using Quarto effectively in your own projects.