Skip to content

humburg/reproducible-reports

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

88 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Creating reproducible reports with knitr and pandoc

These are some examples on how to use Markdown with R and pandoc to create dynamic documents for multiple output formats. All examples and accompanying text are contained in example.Rmd.

Compiling the document

Creating PDF and HTML output from the R/Markdown source file is a two step process. First knitr is used to execute the R code and produce the corresponding Markdown output. This can be done either by starting an R session and executing knitr("example.Rmd") or from the command line:

Rscript --slave -e "library(knitr);knit('example.Rmd')" 

Either way this generates a Markdown file called 'example.md'. This can then be converted into PDF and HTML files by using the configuration file 'example.pandoc' by calling the pandoc function from the knitr package.

Rscript --slave -e "library(knitr);pandoc('example.md')"

The function automatically locates the configuration file and passes the requested parameters to pandoc.

Required software

In addition to installations of knitr and pandoc a few external tools are required to compile this document.

R is required to run knitr as well as other R packages to support additional functionality.

Additional R packages used:

  • animation (for animated figures)
  • pander (for Markdown formatting of R objects)

These can be installed via the install.packages command from within R. Animations also require ffmpeg and either ImageMagick or GraphicsMagick.

As one might expect a working LaTeX tool chain is required to generate PDF output from LaTeX documents. Several distributions are available online, including MiKTeX and TeX Live.

Python ($\geq$ 2.7) is required for the pandoc filters discussed in the latter parts of this document. This also requires the pandocfilters Python module, which can be installed via pip.