- Code, results, and text in the same document
- Your results and plots are automatically generated from your data, so your documents can be easily updated if your data changes
- Outputs can be directly deployed online
- Integrates nicely with GitHub Pages and other hosting services
- Reproducible Workflow - from raw data over analysis to presentation
A YAML header is a set of key-value pairs at the start of your file. The YAML header includes meta-information about your Rmarkdown document. For example whether the output should be an HTML or a PDF document. Begin and end the header with a line of three dashes (- - -)
---
title: "Rmarkdown Workshop"
subtitle: "A basic Introduction"
author: "Fabio Votta"
output: html_document
---
- output: html_document
- output: pdf_document
- output: word_document
- output: beamer_presentation
- output: ioslides_presentation
CODING EXAMPLE
italics and bold
inline code
sub2/superscript2
strikethrough
escaped: * _ \
endash: –, emdash: —
blockquote
Line break: End line with 2+ spaces, or backslash: Roses are red Violets are blue
Roses are red
Violets are blue
CODING EXAMPLE
This… - unordered list - sub-item - sub-item 2 - sub-sub-item
- ordered list
- item 2
- sub-item 1
- sub-item 2
inline-math: A = π * r2
math-block: A = π * r2
A footnote [1]
In a setup chunk, one usually sets global options for the entire document.
Normally, an R Markdown document starts with this chunk.
knitr::opts_chunk$set
sets default options for all chunks.
## Sets Global Options
knitr::opts_chunk$set(echo = T, warning = F, message = F)
option | default | effect |
---|---|---|
eval | TRUE | Whether to evaluate the code and include its results |
echo | TRUE | Whether to display code along with its results |
warning | TRUE | Whether to display warnings |
error | FALSE | Whether to display errors |
message | TRUE | Whether to display messages |
tidy | FALSE | Whether to reformat code in a tidy way when displaying it |
results | “markup” | “markup”, “asis”, “hold”, or “hide” |
cache | FALSE | Whether to cache results for future renders |
comment | “##” | Comment character to preface results with |
fig.width | 7 | Width in inches for plots created in chunk |
fig.height | 7 | Height in inches for plots created in chunk |
cars %>%
head() %>%
knitr::kable()
speed | dist |
---|---|
4 | 2 |
4 | 10 |
7 | 4 |
7 | 22 |
8 | 16 |
9 | 10 |
The kable
function within knitr
produces neat tables out of
dataframes. A number of other packages are available for making pretty
tables, see rmarkdown.rstudio.com.
result <- 4 + 4
Inside your text you can include code with the syntax 8.
- RMarkdown for writing reproducible scientific papers
- Intro to Rmarkdown by Rstudio
- Rmarkdown Cheatsheet
- Advanced Rmarkdown Workshop
- R Markdown: The Definitive Guide (Yihui Xie, J. J. Allaire, Garrett Grolemund)
- Writing Reproducible Research Papers with R Markdown
- Starting R markdown (YouTube Intro series with the magnificent Danielle Navarro)
[1] here is the footnote text.