Creating a Report with R Markdonw

Open an R Markdown Document

To open a new R Markdown document, go to File | New and select R Markdown. This will give you a basic template and show you what can be done. Make a few changes and save this document. After this, click, Knit HTML at the top to see the output. We'll talk more about this soon.

What is R Markdown

R Markdown enables easy authoring of reproducible web reports from R. It offers:

Markdown is a simple markup language designed to make authoring web content easy for everyone. Rather than writing HTML and CSS code, Markdown enables the use of a syntax much more like plain-text email.

Markdown Help

Markdown is easy to learn and you can be up and running in minutes. In the upper left corner of the editor, click the MD button to see a quick reference guide for Markdown.

Knit HTML

When we clicked the Knit HTML button, this took our R Markdown file, and converted it to an HTML file. This is important because the HTML can be easily distributed and viewed on almost any computer through a standard web browser.

R Code Chunks

You'll notice that the R Code Chunks are different than in Sweave or knitr, but they are not actually that different. The only major difference is that the tag used has changed. For example, go to the Chunks menu and insert a new chunk. You'll see the basic syntax for a chunk. Now everything else is the same as using knitr. Note that the chunk options are the same as knitr (we cannot use Sweave here).

Equations

You can embed LaTeX or MathML equations in R Markdown files using the following syntax:

$equation$ for inline equations (note there must not be whitespace adjacent to the $ delimiters)
$$ equation $$ for display equations
<math ...> </math> for MathML equations.

See the following help doc:

http://www.rstudio.org/docs/authoring/using_markdown_equations

Navigating between chunks

The same chunk navigation and options works in R Markdown as in knitr. Test out some of these options as we used in the homePrices.Rnw file. Copy some of the code chunks over such as the following.

library(ggplot2)# plot price based on the ratingqplot(rating, price, color = age, data = homes)

More examples

http://rpubs.com/gallery/googleVis

http://rpubs.com/gallery/options

Why HTML

As we've described before, now we can add dynamic content and distribute just one file such as the googleVis example.