
Recover R source from a knitted R Markdown / Quarto HTML file
Source:R/html-output.R
dot-html_export_r_source.RdExtracts every input-code chunk pandoc/knitr rendered into the document
(<pre class="r"><code>...</code></pre> or <div class="sourceCode r">),
in document order, and writes them — separated by a blank line, matching
how code_read() already treats whitespace between statements — as a
sibling .R file. This is the HTML analogue of .smcl_export_syntax() /
.spv_export_syntax(): the ORIGINAL analysis code sits verbatim inside the
rendered document (HTML-entity-escaped only, never altered), so it is
exactly recoverable, not reconstructed or guessed.
Arguments
- html_path
path to a local
.htmlfile already confirmed (by.html_sniff_kind()) to be"rmd"- code_dir_name
the sibling folder to write into, same convention as
.spv_export_syntax()/.smcl_export_syntax()(default"code"). A file of the user's own gets this folder in the temporary folder instead, so the user's folder is not changed (see .recovered_code_dir()).
Value
the path to the written .R file, or NA_character_ if the
document could not be read or contained no recoverable R chunk
Details
Printed console OUTPUT (## -prefixed lines pandoc/knitr interleave after
each chunk) is deliberately NOT included: this produces a re-runnable .R
script for code_check/reproducibility_check (the modules in
inst/modules/), and a ##-prefixed line is a comment in R syntax anyway,
so leaving it out changes nothing a parse would see — it is dropped here
only to keep the recovered file to actual code.