Wednesday, February 25, 2015

RMarkdown - making and using a general Rmd file for re-use

There are some tasks I do a lot and it'd be good to have general .Rmd documents available to report on the outcome of those tasks. Some examples would be a standard report on an ML experiment, or an overview from a data curation pipeline. I've been using rmarkdown for generating reports, but it has some limitations for this. I don't want to have a new Rmd file for every report. I'd like to have a configurable template file that lives in a shared location that I can run each time.

Unfortunately, if you try to do this you'll soon find that rmarkdown expects the Rmd file to be in your working directory - well, the working directory is set to the location of the Rmd file. See the following line in render.R: github-render.R_L96

My current work around for this (and please let me know if you have a better way) is to have a helper script which copies over the Rmd file to the current working directory, generates the report and then removes the temporary files: The Rmd file has a line for loading in the configuration:
library(yaml)
config <- yaml.load_file("model_report.yaml")

The YAML configuration file contains the project specific variables (e.g. output suffix, flags for adding/subtracting items from a report, important dir locations). This file could easily be generated on the fly via arguments to the bash script.

Wednesday, February 18, 2015

Rmarkdown: automatically select correct output type for xtable

I was initially setting the xtable output type manually - either globally or in each print statement. This got annoying very quickly when switching between HTML and PDF outputs. This is how you get xtable to automatically use the correct output format:

Wednesday, February 4, 2015

Fix Excel Office for Mac 2011 TSV output

RMarkdown: Setting global chunk options

The easiest way to do this is to have a chunk at the start of your document that isn't included in the output of the report: In this example I'm setting the default behaviour so that the code isn't printed (echo=FALSE) and no warning messages are reported in the output document (message=FALSE). I'm also setting some xtable options (for easily printing out nice tables in the report).