To distinguish these examples from the main text the entire block of raw and converted Markdown will be framed by horizontal lines. To better show the effect of Markdown examples on the output these will often be followed by the same text rendered in the output format. Throughout this document examples of R code and Markdown formatting will be presented in code blocks: message( "This is R code") It also facilitates the conversion between a large number of document formats, providing great flexibility. It comes with its own Markdown dialect that includes many extensions that fill some of the gaps in the Markdown syntax, including the ability to use bibliographic databases in a variety of formats, while trying to retain the text’s readability. Pandoc is a very useful tool that helps to alleviate this problem. The focus on simplicity and the fact that it was originally designed for authoring web content means that much of the requirements for scientific writing are not easily met by standard Markdown. However, when trying to use this to generate publication quality reports the limitations of the Markdown syntax quickly start to become apparent. A selection of tutorials and useful examples for knitr can be found on knitr’s homepage. The code will be executed and its output, including plots, can be included in the output. This R package provides functions that allow the processing of Markdown documents with embedded R code. Much, if not all, of what is needed to create a reproducible analysis is provided by knitr. Here we will mainly focus on a combination of two of these, namely knitr and pandoc. Several tools are available to produce dynamic documents in Markdown and convert them to various output formats. Writing Markdown is much easier than LaTeX, thus lowering the entry barrier, and its emphasis on maintaining readability of the raw text means that both writing and editing documents is faster than with LaTeX. More recently the use of Markdown has become popular. Of course they can be turned into beautiful PDFs but that doesn’t help while editing the text. More importantly, adding LaTeX commands to the text can be distracting and break the flow of writing and coding (at least for me) and the resulting LaTeX documents are not very readable. While LaTeX is a very powerful tool that allows great control over page layout, the learning curve can be steep. Traditionally dynamic R documents like this have been (and often still are) written in LaTeX using either Sweave or, more recently, knitr. As a result analyses become a lot easier to reproduce because the code and the presentation of results are closely linked and figures and tables can be updated automatically. This is useful to generate reports (or papers) that contain all the relevant R code to carry out the analysis and allows for automatic updates to the document if either the code or the data change. This is an introduction to the use of Markdown with embedded R code to create dynamic documents in multiple formats, e.g. HTML, PDF and Word.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |