Extracts R code cells from a Quarto document and writes them to an R script
file that can be rendered with the same options. The Markdown text is not
preserved, but R chunk options are kept as comment headers using Quarto's
#|
syntax.
This function is still experimental and may slightly change in future releases, depending on feedback.
Value
Invisibly returns the path to the created R script file, or
NULL
if no R code cells were found.
Details
This function processes a Quarto document by:
Extracting only R code cells (markdown and cell in other languages are ignored)
Preserving chunk options as
#|
comment headersAdding the document's YAML metadata as a spin-style header
Creating an R script that can be rendered with the same options
File handling:
If the output R script already exists, the function will abort with an error
Non-R code cells (e.g., Python, Julia, Observable JS) are ignored
If no R code cells are found, the function does nothing and returns
NULL
Compatibility:
The resulting R script is compatible with Quarto's script rendering via
knitr::spin()
and can be rendered directly with quarto render script.R
.
See https://quarto.org/docs/computations/render-scripts.html#knitr for
more details on rendering R scripts with Quarto.
The resulting R script uses Quarto's executable cell format with #|
comments to preserve chunk options like echo
, eval
, output
, etc.