R Markdown is an authoring format that enables easy creation of dynamic documents, presentations, and reports from R. It combines the core syntax of markdown (an easy-to-write plain text format) with embedded R code chunks that are run so their output can be included in the final document. R Markdown documents are fully reproducible (they can be automatically regenerated whenever underlying R code or data changes).
Roger D. Peng, Reproducible Research: Concepts and Ideas p.10 on Coursera
RStudio — Install the latest version of RStudio
Other environments — Install the rmarkdown package.
rmarkdown::render functionrmarkdown::render("input.Rmd")
*italic* **bold** _italic_ __bold__
I am italic
I am bold
Setext:
Header 1 ============= Header 2 -------------
atx:
# Header 1 ## Header 2 ### Header 3
Unordered List:
* Item 1
* Item 2
+ Item 2a
- Item 2b
Ordered List:
1. Item 1
2. Item 2
3. Item 3
+ Item 3a
+ Item 3b
Unordered List:
Ordered List:
A plain http address or add a link to a phrase.
Link:
[rugbcn-r-users-group](http://www.meetup.com/es/rugbcn-barcelona-r-users-group/)
Image:

Plain code blocks are displayed in a fixed-width font but not evaulated.
```
This text is displayed verbatim / preformatted
```
Specify the language of the block is avaliable
```r
x = rnorm(10)
```
x = rnorm(10)
Inline equation: $equation$ \(\frac{1}{n} \sum_{i=i}^{n} x_i\)
Display equation: $$equation$$ \[\frac{1}{n} \sum_{i=i}^{n} x_i\]
First Header | Second Header ------------- | ------------- Content Cell | Content Cell Content Cell | Content Cell
| First Header | Second Header |
|---|---|
| Content Cell | Content Cell |
| Content Cell | Content Cell |
You can color content using base color classes red, blue, green, yellow, and gray (or variations of them e.g. red2, red3, blue2, blue3, etc.).
<div class="red2"> This text is red </div>
R code will be evaluated and printed
```{r}
summary(cars$dist)
```
summary(cars$dist)
## Min. 1st Qu. Median Mean 3rd Qu. Max. ## 2.00 26.00 36.00 42.98 56.00 120.00
```{r plot}
summary(cars)
plot(cars)
```
echo(TRUE): whether to include R source code in the output fileeval(TRUE): whether to evaluate the code chunkmessage(TRUE): whether to preserve messages emitted by message()include(TRUE): if include=FALSE, nothing will be written into the output document, but the code is still evaluated and plot files are generatedwarning(TRUE): whether to preserve warnings in the outputSet global chunk options:
knitr::opts_chunk$set()
dev('png'): figure format(png, jpeg, tiff, svg, …)fig.path('figure/'): figure pathfig.width(7): figure widthfig.height(7): figure heightdpi(72): DPI (dots per inch)```{r dev='svg', fig.path='myplot',fig.width=5, fig.height=5}
plot(iris)
```
I counted 'r 1+1' red trucks on the highway.
I counted 2 red trucks on the highway.
library(knitr)
library(ggvis)
mtcars %>%
ggvis(x = ~wt, y = ~mpg) %>%
layer_smooths(se=TRUE, opacity := 0.5, opacity.hover := 0.75) %>%
layer_points(fill = ~factor(cyl), size := 50, size.hover := 200) %>%
set_options(hover_duration = 250)
library(DT) datatable(mtcars,options=list(pageLength=3))