Simple RMarkdown example with knitr ========= Jerzy Wieczorek, 2/10/2014 --------- ### Intro to using RMarkdown Click the **MD** toolbar button for help on Markdown. Click **Knit HTML** button or press Ctrl+Shift+H to see your output. Write your R code in "chunks". The code, text output, and plot output will be shown: {r} # Make some data: y = x + e x = 1:30 e = rnorm(30) y = x + e # Plot the data plot(x,y, main="y = x + e") abline(lm(y~x)) # Summarize the regression results summary(lm(y~x))  ---- ### More features of RMarkdown Unlike in the R Notebok, we can change chunk options, e.g. figure size: {r fig.width=4, fig.height=4} plot(x,y, main="y = x + e") abline(lm(y~x))  We can use LaTeX equations: The data above came from the model $y = x + \epsilon$ with $\epsilon \sim N(0,1)$. We can reference R results in the text output: The regression coefficient was r coef(lm(y~x))[2]. We can use the xtable package to print nice HTML tables: {r results = 'asis'} library(xtable) print(xtable(summary(lm(y~x))$coefficients, caption ="Regression results"), type='html')  Compare this to the default R output: {r} summary(lm(y ~ x))$coefficients