Skip to contents

Extracts code blocks from a Cassidy response and writes them to a file, while displaying the explanatory text (non-code parts) in the console. This allows you to see what was done while the actual code is saved to disk.

Usage

cassidy_write_code(
  x,
  path,
  open = interactive(),
  append = FALSE,
  show_explanation = TRUE
)

Arguments

x

A cassidy_chat or cassidy_response object.

path

Character. File path where to save the code.

open

Logical. Open file after writing (default: TRUE in interactive).

append

Logical. Append to existing file (default: FALSE).

show_explanation

Logical. Show explanatory text in console (default: TRUE).

Value

Invisibly returns the file path.

Examples

if (FALSE) { # \dontrun{
# Ask Cassidy to write code
result <- cassidy_chat(
  "Write the cassidy_app() function with UI and server logic",
  context = ctx
)

# Code goes to file, explanation to console
cassidy_write_code(result, "R/chat-ui.R")

# Quiet mode - no explanation shown
cassidy_write_code(result, "R/chat-ui.R", show_explanation = FALSE)
} # }