RMarkdown

Interchanging RMarkdown and "spinnable" R

Dean Attali wrote this nice post a few years ago describing knitr’s spin function. This function allows a regular R file, with comments written with the roxygen2-style comment tag #’ to be rendered as an HTML document with the comments rendered as text and the results of the R code rendered in place, much as a RMarkdown document would. The basic rules for this are (from Dean’s post): Any line beginning with #’ is treated as a markdown directive (#’ # title will be a header, #’ some bold text results in some bold text) Any line beginning with #+ is parsed as code chunk options Run knitr::spin on the file In effect, this “spinnable” R script is the complement of a RMarkdown document with respect to format, since the RMarkdown document is primarily a text (Markdown) document with code chunks, and the R script is primarily a code document with text chunks.