Converts R scripts (.R) into 'Quarto' markdown documents (.qmd) with automatic formatting. Recognizes 'RStudio' code sections, preserves comments as narrative text, extracts metadata from special comments, and provides both programmatic functions and an interactive 'RStudio' add-in for easy conversion.
quartify 
π«π· Version franΓ§aise
quartify is an R package that automatically converts R scripts into Quarto markdown documents (.qmd).
The package facilitates the transformation of your R analyses into reproducible and well-structured Quarto documents, preserving the logical structure of your code through RStudio code sections. It recognizes the standard RStudio code section syntax (####, ====, ----) to create properly indented navigation structures.
knitr::spin() and Quarto's render-scripts feature both allow rendering R scripts, but they require inserting Markdown structure directly into comments (#', headers, chunk options, etc.).
quartify takes a different philosophy: it imposes no Markdown syntax in comments and works on completely standard R scripts. Comments remain comments, code remains code.
The goal is to keep clean, conventional scripts while making them convertible to .qmd β and when multiple scripts are selected, to automatically assemble them into a structured Quarto book without any source code rewriting.
If you have a working R script that contains comments, you may want to generate a Quarto document from this script that will allow you to automatically produce displayable HTML documentation. This is particularly useful for:
####, ====, ----) and converts them to proper markdown headers with correct indentation levels#') into callout-note sections with function names_book)quartify_app_web() for deploying on web servers with file upload/download capabilitiesYou can install the development version of quartify from GitHub:
# install.packages("devtools")
devtools::install_github("ddotta/quartify")
No installation required! Use quartify directly in your browser:
The web version allows you to:
quartify also provides an interactive Shiny interface that works in any R environment:
library(quartify)
quartify_app() # Opens in your default web browser
This launches a browser-based interface where you can:
Perfect for users of Positron, VS Code, or any IDE that supports R!
If you use RStudio, you can also access the same interface through:
The interface automatically detects your R session language preferences and displays all labels in English or French accordingly. You can change the language at any time using the EN/FR buttons. The output format is always HTML.
library(quartify)
# Convert an R script to a Quarto document and render to HTML
rtoqmd("my_script.R", "my_document.qmd")
# Convert only, without rendering to HTML
rtoqmd("my_script.R", "my_document.qmd", render = FALSE)
# With title and author customization
rtoqmd("my_script.R",
output_file = "my_document.qmd",
title = "My statistical analysis",
author = "Your name",
format = "html",
theme = "cosmo", # Quarto theme (optional)
render = TRUE, # Render to HTML
output_html_file = "docs/my_analysis.html", # Custom HTML location
open_html = TRUE, # Open HTML in browser
number_sections = TRUE) # Number sections automatically
Example files are included in the package to test the function:
# Locate the basic example file
example_file <- system.file("examples", "example.R", package = "quartify")
# Convert the example file
rtoqmd(example_file, "test_output.qmd")
# Try the Mermaid diagrams example
mermaid_file <- system.file("examples", "example_mermaid.R", package = "quartify")
rtoqmd(mermaid_file, "test_mermaid.qmd", render = TRUE)
In quartify_app_web() (or the online app), you can:
This is perfect for converting entire projects without writing any R code!
Convert all R scripts in a directory (including subdirectories):
# Convert all R scripts in a directory
rtoqmd_dir("path/to/scripts")
# Convert and render all scripts to custom HTML directory
rtoqmd_dir("path/to/scripts",
render = TRUE,
output_html_dir = "docs/html")
# With custom settings
rtoqmd_dir("path/to/scripts",
author = "Data Team",
exclude_pattern = "test_.*\\.R$")
quartify optionally integrates with styler and lintr to help you improve code quality:
use_styler: Shows formatted code according to the tidyverse style guideuse_lintr: Identifies code quality issues and potential problemsapply_styler: Directly applies styling to your original R script (β οΈ modifies source file)When quality issues are detected, quartify creates interactive tabsets in the HTML output with:
use_styler = TRUE and changes detected)use_lintr = TRUE and issues found)These packages are optional and only needed if you want to use code quality features:
install.packages(c("styler", "lintr"))
# Show styling suggestions in tabs
rtoqmd("my_script.R", "output.qmd",
use_styler = TRUE)
# Show both styling and lint issues
rtoqmd("my_script.R", "output.qmd",
use_styler = TRUE,
use_lintr = TRUE)
# Apply styling directly to source file (β οΈ modifies original)
rtoqmd("my_script.R", "output.qmd",
apply_styler = TRUE)
All three Shiny applications (rtoqmd_addin(), quartify_app(), and quartify_app_web()) include checkboxes for these options in the interface.
π For detailed information, see:
For the conversion to work properly, structure your R script using RStudio code sections:
# Title : Iris Data Analysis
#
# Author : Jane Doe
#
# Date : 2025-11-28
#
# Description : Explore differences between iris species
#
library(dplyr)
## Title 2 ####
### Title 3 ====
# Start of statistical processing
# Counting the number of observations by species
iris |>
count(Species)
### Title 3 ====
# Filter the data.frame on Species "setosa"
iris |>
filter(Species == "setosa")
#### Title 4 ----
# Select column Species
iris %>%
# Select a column
select(Species)
You can define metadata directly in your R script using special comments at the beginning:
# Title : My title or # Titre : Mon titre# Author : My name or # Auteur : Mon nom# Date : YYYY-MM-DD# Description : Your descriptionπ‘ RStudio Snippet: Use install_quartify_snippets() function to install quartify's snippets or create a snippet for quick metadata insertion (Tools > Edit Code Snippets > R):
snippet header
# Title : ${1}
#
# Author : ${2}
#
# Date : ${3}
#
# Description : ${4}
#
Type header + Tab in your script to insert the metadata structure.
Behavior:
π Note: The
Descriptionfield can span multiple lines. To continue the description, start the next line with#followed by at least one space. Continuation lines are automatically concatenated. Example:# Description : This analysis explores differences between iris species # using various statistical methods and visualization techniques # to identify patterns and correlations.
quartify recognizes three types of lines in your R script:
RStudio code sections become markdown headers. Critical: trailing symbols must be at least 4 characters long:
## Title ---- β Level 2 header (at least 4 #, = or - at the end)### Title ---- β Level 3 header (at least 4 #, = or - at the end)#### Title ---- β Level 4 header (at least 4 #, = or - at the end)Note: You can use #, =, or - interchangeably as trailing symbols (e.g., ## Title ==== or ### Title ---- will work).
Single # comments at the start of a line (no leading space) with a space after # become explanatory text:
# This is a standalone comment
# It becomes plain text in the Quarto document
Hidden Comments: Comments that start with # immediately followed by a non-space character (e.g., #NOTE:, #TODO:, #DEBUG) are completely ignored and will not appear in the output. This allows you to include private development notes:
# This comment appears in output
#TODO: Fix this later - NOT visible in output
#NOTE: Internal reminder - NOT visible
# This comment appears again
β οΈ Important: For a comment to be converted to text, the line must start with
#followed by a space. Indented comments (with spaces before#) remain in the code.
π‘ Tip: To split a long chunk into multiple parts, insert a comment at the start of a line (no space before
#) between two code blocks. This comment will be converted to text and naturally create two separate chunks.
Tip: Use RStudio's Comment/Uncomment shortcut (Ctrl+Shift+C on Windows/Linux or Cmd+Shift+C on Mac) to quickly add or remove comments.
Uncommented lines become executable R code chunks:
iris |> filter(Species == "setosa")
Comments within code blocks are preserved inside the R code chunk:
iris %>%
# This comment stays in the code block
select(Species)
Callouts are special blocks that highlight important information. Five types are supported: note, tip, warning, caution, important.
Syntax in R script:
# callout-note - Important Note
# This is the content of the callout.
# It can span multiple lines.
# Empty line or code ends the callout
x <- 1
Converts to Quarto:
::: {.callout-note title="Important Note"}
This is the content of the callout.
It can span multiple lines.
:::
Without title:
# callout-tip
# This is a tip without a title.
Callouts end when encountering an empty line, code, or another section.
Create flowcharts, sequence diagrams, and other visualizations using Mermaid syntax.
Syntax in R script:
#| mermaid
#| eval: true
# flowchart TD
# A[Start] --> B[Process]
# B --> C{Decision}
# C -->|Yes| D[End]
# C -->|No| B
Converts to Quarto Mermaid chunk with proper formatting for diagram rendering in HTML output.
Supported diagram types:
flowchart TD, flowchart LR)sequenceDiagram)classDiagram)Rules:
#| mermaid comment#| (e.g., #| eval: true)# prefix on each line (keeps valid R syntax)# prefix is automatically removed in Quarto outputSee complete example in inst/examples/example_mermaid.R
Organize related content in interactive tabs for better presentation and navigation.
Syntax in R script:
# tabset
# tab - Summary
# Display summary statistics
summary(data)
# tab - Structure
# Show data structure
str(data)
# tab - Preview
# First rows of data
head(data)
Converts to Quarto tabset with interactive tabs in HTML output.
Rules:
# tabset comment to begin the tabset container# tab - Tab TitleSee complete example in inst/examples/example_tabset.R
Important rules:
# for comments# at line start β become text outside code blocks# callout-TYPE or # callout-TYPE - Title#| mermaid followed by options and diagram content# tabset then # tab - Title for each tabThis follows the RStudio code sections convention which provides proper indentation in the RStudio document outline navigation.
Customize the appearance of your HTML documents with Quarto themes. The package supports all available Bootswatch themes:
Light themes: cosmo, flatly, journal, litera, lumen, lux, materia, minty, morph, pulse, quartz, sandstone, simplex, sketchy, spacelab, united, vapor, yeti, zephyr
Dark themes: darkly, cyborg, slate, solar, superhero
Example:
# Use the "flatly" theme
rtoqmd("my_script.R", theme = "flatly")
# Use the dark "darkly" theme
rtoqmd("my_script.R", theme = "darkly")
For more information about themes, see the Quarto documentation.
The generated .qmd document contains:
π For a complete example of the generated output, see the Getting Started vignette
Use quartify in your CI/CD pipelines to automatically generate documentation:
GitHub Actions (.github/workflows/generate-docs.yml):
- name: Generate documentation
run: |
library(quartify)
rtoqmd_dir("scripts/", render = TRUE, author = "Data Team")
shell: Rscript {0}
- uses: actions/upload-artifact@v4
with:
name: documentation
path: |
scripts/**/*.qmd
scripts/**/*.html
GitLab CI (.gitlab-ci.yml):
generate-docs:
image: ddottaagr/quartify:latest
script:
- R -e "quartify::rtoqmd_dir('scripts/', render = TRUE, author = 'Data Team')"
artifacts:
paths:
- scripts/**/*.qmd
- scripts/**/*.html
π Full CI/CD guide with complete examples: CI/CD Integration
MIT