Adding Rich R Content

written in HelloWorld

With a bit of tweaking, you can create rich documents with R markdown that combine text, figures, equations and tables that are generated by R on the fly. Now if only blogs could get a DOI…

Tables:

Tables can be used with the knitr::kable function.

mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2

Math

Equations are handled in LATEX format by MathJax: $$\frac{1}{n} \sum{i=i}^{n} x{i}$$

Embedded Images:

Links to websites can be included like this.

Embedding images with control over the size and resolution is a bit tricky. I like to import my PNG images as R objects, that way they are treated like any other plot.

This is also a caption.

Citations:

It is also straightforward to include inline citations like this using the package knitcitations package (Abrams et al. (2012); Bolnick et al. (2010)).

And include a dynamically generated list of references:

Works Cited:

  • Peter A. Abrams, Lasse Ruokolainen, Brian J. Shuter, Kevin S. McCann, (2012) Harvesting Creates Ecological Traps: Consequences of Invisible Mortality Risks in Predator–Prey Metacommunities. Ecology 93 281-293 10.1890/11-0011.1
      1. Bolnick, T. Ingram, W. E. Stutz, L. K. Snowberg, O. L. Lau, J. S. Paull, (2010) Ecological Release From Interspecific Competition Leads to Decoupled Changes in Population And Individual Niche Width. Proceedings of The Royal Society B: Biological Sciences 277 1789-1797 10.1098/rspb.2010.0018

Source code for this document is available here