Custom Output Directory

Overview

This document demonstrates the output-dir option, which saves generated scripts to a separate directory instead of alongside the source document.

The document configuration is:

---
title: "Custom Output Directory"
format: html
extensions:
  ripper:
    output-dir: scripts
filters:
  - ripper
---

With this configuration, the extracted scripts will be saved to a scripts/ folder relative to this document’s location. The directory is created automatically if it doesn’t exist.

Common Patterns

Save to a scripts folder next to the document:

output-dir: "scripts"

Save to project root when document is in a subdirectory:

# If document is in docs/, this saves to project-root/scripts/
output-dir: "../scripts"

Combine with custom output name:

output-dir: "scripts"
output-name: "analysis"  # Creates scripts/analysis.R, scripts/analysis.py

R Code

data <- mtcars
summary(data$mpg)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  10.40   15.43   19.20   20.09   22.80   33.90 

Python Code

numbers = [1, 2, 3, 4, 5]
print(f"Sum: {sum(numbers)}")
Sum: 15

Script files

The code for this document can be found here: