TAGS :Viewed: 1 - Published at: a few seconds ago

[ Markdown and outline an R script ]

I am using Emacs for an R-script with markdown using oxygen comments. With rmarkdown::render() I produce either a HTML or pdf file. Works great.

However, it would be great if I could use outline mode for headings in this file (coloured differently and collapsing or showing stuff). I have searched the internet but haven't found a solution, how to make this work.

An example would be (R-File):

#' # Heading 1
#' some test
t <- c(1,2)
#' ## Heading 2
#' some more text
s  <- c(1,2)

It would be nice, if I could collapse it and have different colors for the heading levels.

Answer 1


HTML

One possibility is to use knitr package to render the R markdown.

In addition it is possible to feed it a CSS file that will allow you to style headings (like colors). This answer Custom CSS with knitr and markdown in R may be useful to help you achieving this. If you are familiar with css, you can always add the collapsing effect. If you aren't I suggest to have a look at this: http://www.webdeveloper.com/forum/showthread.php?77389-Expand-Collapse-Paragraph

Twisting the idea around would be to use Shinypackage to create an interactive page with R code, however it is a bit far-fetched considering that it started from a Markdown.