Quarto Vignette Example

Code

1 Introduction

This vignette demonstrates how to use Quarto (.qmd) files as vignettes in R packages. Quarto is the next-generation version of R Markdown, offering enhanced features and better integration with multiple programming languages.

2 Why Use Quarto?

Quarto offers several advantages over traditional R Markdown:

  1. Enhanced features: Better support for cross-references, callouts, and other advanced formatting
  2. Multiple engines: Works with R, Python, Julia, and Observable
  3. Modern syntax: Cleaner YAML and chunk options using #| syntax
  4. Better publishing: Improved website and book publishing capabilities

3 Basic Example

Here’s a basic example using the package:

Code
# Create some sample data
sample_data <- c(1, 2, 3, 4, 5, 10, 15, 20)

# Use the example function
result <- example_function(sample_data)
result
#> [1] 4.5

4 Quarto Features

4.1 Callouts

Note

This is a callout block that highlights important information.

Tip

Quarto supports multiple types of callouts: note, tip, warning, important, and caution.

4.2 Code Chunks with Modern Syntax

You can use the modern #| syntax for chunk options:

Code
# Create a simple plot
plot(sample_data, 
     main = "Sample Data", 
     xlab = "Index", 
     ylab = "Value",
     pch = 19,
     col = "steelblue")
Figure 1: Example plot showing data distribution

5 Theorem Environments

Quarto supports theorem and proof environments that integrate with the callouty-theorem extension to render as styled callout blocks.

Definition 1 (Sample Mean) The sample mean of observations \(x_1, x_2, \ldots, x_n\) is:

\[\bar{x} = \frac{1}{n}\sum_{i=1}^{n} x_i\]

Theorem 1 (Unbiasedness of the Sample Mean) The sample mean \(\bar{x}\) is an unbiased estimator of the population mean \(\mu\):

\[E[\bar{x}] = \mu\]

Proof. By linearity of expectation: \[E[\bar{x}] = E\!\left[\frac{1}{n}\sum_{i=1}^{n} x_i\right] = \frac{1}{n}\sum_{i=1}^{n} E[x_i] = \frac{1}{n} \cdot n\mu = \mu. \qquad \square\]

Example 1 (Computing the Sample Mean) For the data \(\{1, 2, 3, 4, 5\}\): \[\bar{x} = \frac{1+2+3+4+5}{5} = 3\]

6 Equations

Quarto has excellent support for mathematical equations using LaTeX syntax:

Inline equation: \(E = mc^2\)

Display equation:

\[ \bar{x} = \frac{1}{n}\sum_{i=1}^{n} x_i \]

7 Tables

Table 1: Comparison of R Markdown and Quarto
Feature R Markdown Quarto
YAML Standard Enhanced
Chunks {r, option=value} #| option: value
Publishing Good Excellent
Cross-refs Limited Native

8 Summary

Quarto vignettes provide a modern, feature-rich way to document R packages. They integrate seamlessly with documentation systems and offer enhanced capabilities for technical documentation.

9 References

For more information, see:

References

R Core Team. 2024. R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing. https://www.R-project.org/.
UCD-SERG. 2024. Rpt: R Package Template. https://github.com/UCD-SERG/rpt.