R markdown
How to combine R code and reports?
Your data tells a story. Tell it with R Markdown. https://www.rstudio.com/wp-content/uploads/2016/03/rmarkdown-cheatsheet-2.0.pdf
Install the package:
install.packages("rmarkdown")
R Markdown provides an authoring framework for data science. You can use a single R Markdown file to both
- save and execute code
- generate high quality reports that can be shared with an audience
R Markdown documents are fully reproducible and support dozens of static and dynamic output formats
To get started in RStudio: New file -> R Markdown In Title put the title of future report
Save the file (Save).
To look at intermediate results click Knit HTML.
Add R code chunk
You can quickly insert chunks like these into your file with
- the keyboard shortcut Ctrl + Alt + I (OS X: Cmd + Option + I)
- the Add Chunk command in the editor toolbar
or by typing the chunk delimiters {r} and .
Code + result:
```{r} dim(iris) ```
Only code:
```{r eval=FALSE} dim(iris) ```
Only result:
```{r echo=FALSE} dim(iris) ```
Text formating
Inline code: code results can be inserted directly into the text:
We have 2+2=`r 2+2`
Italic:
*italics* and _italics_
Bold:
**bold** and __bold__
Other:
superscript^2^
~~strikethrough~~
Headers:
# Header 1 ## Header 2 ### Header 3 #### Header 4 ##### Header 5 ###### Header 6
Lists:
* unordered list * item 2 + sub-item 1 + sub-item 2 1. ordered list 2. item 2 + sub-item 1 + sub-item 2
Formulas:
$A = \pi*r^{2}$
External pic:
![](/Users/pics/Koala.jpg)
Link:
[link](www.rstudio.com) <http://rmarkdown.rstudio.com>
Page break:
***
Block quote:
> block quote
Table:
Table Header | Second Header ------------- | ------------- Table Cell | Cell 2 Cell 3 | Cell 4