add_spin_preamble | R Documentation |
Adds a minimal spin preamble to an R script file if one doesn't already exist.
The preamble includes a title derived from the filename and is formatted as
a YAML block suitable preprended with #'
for knitr::spin()
.
add_spin_preamble(script, title = NULL, preamble = NULL, quiet = FALSE)
script |
Path to the R script file |
title |
Custom title for the preamble. If provided, overrides any title
in the |
preamble |
Named list of YAML metadata to include in preamble.
The |
quiet |
If |
This is useful to prepare R scripts for use with Quarto Script rendering support. See https://quarto.org/docs/computations/render-scripts.html#knitr
Invisibly returns the script path if modified, otherwise invisible NULL
For a script named analysis.R
, the function adds this preamble by default:
#' --- #' title: analysis #' --- #' # Original script content starts here
This is the minimal preamble required for Quarto Script rendering, so that Engine Bindings works.
## Not run:
# Basic usage with default title
add_spin_preamble("analysis.R")
# Custom title
add_spin_preamble("analysis.R", title = "My Analysis")
# Custom preamble with multiple fields
add_spin_preamble("analysis.R", preamble = list(
title = "Advanced Analysis",
author = "John Doe",
date = Sys.Date(),
format = "html"
))
# Title parameter overrides preamble title
add_spin_preamble("analysis.R",
title = "Final Title", # This takes precedence
preamble = list(
title = "Ignored Title",
author = "John Doe"
)
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.