knitr/RMarkdown

The R scientific workbook . knitr is the R-based entrant in the scientific workbook field.

It is frequently used with RMarkdown which supports the markdown input format instead of e.g. LaTeX. There are several pieces in this toolchain with a complicated relationship, but the user can ignore most of this complexity. The result is such fanciness as automatically rendering and caching graphs, an interactive notebook UI, nearly first-class support for python and julia plus mediocre support for other languages. Here are some guides:

For an intro to the various way to build this into a full reproducible research workflow, via, say, a scientific workbook see the excellent reproducible analysis workshop.

Pro tips

Multi-part documents are supported, even for LaTeX The keyword here

RMarkdown Tips

To execute it from the command-line you do

R -e "rmarkdown::render('script.Rmd', output_file='output.html')"

There are quirks depending on what markup format you use. LaTeX is just LaTeX. Markdown (Via the RMarkdown package) does not have a unified standard for all the bells and whistles you might want. You can include graphics via native markdown or via R itself. The latter is more powerful if more circuitous, doing e.g. automatic resizing.

knitr::include_graphics("../images/oesterreich_karte.jpg")

RMarkdown equation references are supported but weird.

See equation \@ref(eq:linear)

\begin{equation}
a + bx = c  (\#eq:linear)
\end{equation}

Some miscellaneous tips:

  • I constantly need the chunk options docs
  • How to customise the rmarkdown pandoc output by e.g. adding extensions? There are two ways, Markdown variants and md_extensions option.
  • Might stargazer be useful? It generates marked-up and formatted tables for tabular data, but seems not be generic about output formats.
  • tufte is an Edward-Tufte-compliant stylesheet. (cran link) tint is an alternate version.
  • For online web-friendly (e.g. teaching) purposes, there is literate interactive coding using shiny and LaTeX via shinyTex.

Tables

  • kable (plus possibly kableExtra) is recommended as a multiple-backend table creator.
  • pander is recommended for the same purpose; It targets pandoc.

Editor support

RStudio has intimate RMarkdown integration. AFAICT nothing else supports interactive editing nearly as well, though, but Yihui shows you how to make it work