R Markdown provides an unified authoring framework for data science, combining your code, its results, and your prose commentary. R Markdown documents are fully reproducible and support dozens of output formats, like PDFs, Word files, slideshows, and more.
You need the `rmarkdown` package, but you don’t need to explicitly install it or load it, as RStudio automatically does both when needed.
R Markdown files are designed to be used in three ways:
- For communicating to decision makers, who want to focus on the conclusions, not the code behind the analysis.
- For collaborating with other data scientists (including future you!), who are interested in both your conclusions, and how you reached them ( i.e. the code).
- As an environment in which to do data science, as a modern day lab notebook where you can capture not only what you did, but also what you were thinking.
## Markdown language
Text formatting
`*italic*` or `_italic_`
- *italic* or _italic_
`**bold**` `__bold__`
- **bold** __bold__
`` `code` ``
- `code`
`superscript^2^` and `subscript~2~`
- superscript^2^ and subscript~2~
## Markdown language
Headings
```
# 1st Level Header
## 2nd Level Header
### 3rd Level Header
```
## Markdown language
Lists
```
* Bulleted list item 1
* Item 2
* Item 2a
* Item 2b
1. Numbered list item 1
1. Item 2. The numbers are incremented automatically in the
output.
```
## Markdown language
Links and images
```
<http://example.com>
[linked phrase](http://example.com)

```
## Markdown language
Tables
```
First Header | Second Header
------------- | -------------
Content Cell | Content Cell
Content Cell | Content Cell
```
## Rmarkdown: markdown meet R
**R code will be evaluated and printed**
```` ```{r} ````
```{r}`r ''`
summary(cars$dist)
```
```` ``` ````
```{r}
summary(cars$dist)
```
## Rmarkdown: markdown meet R
**Inline R Code**
There were `` `r `` `nrow(cars)` `` ` `` cars studied
There were `r nrow(cars)` cars studied
When inserting numbers into text use `format()`
## Chunk options
Chunk output can be customised with options, arguments supplied to chunk header. Knitr provides almost 60 options that you can use to customize your code chunks.
Option | Run code | Show code | Output | Plots | Messages | Warnings
This is an R Markdown presentation. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.