R Cheatsheet Rmarkdown Reference
R Cheatsheet Rmarkdown Reference
Syntax
Contents:
1. Markdown Syntax
2. Knitr chunk options
3. Pandoc options
Becomes
Plain text
End a line with two spaces
to start a new paragraph.
*italics* and _italics_
**bold** and __bold__
superscript^2^
~~strikethrough~~
[link](www.rstudio.com)
# Header 1
## Header 2
### Header 3
#### Header 4
##### Header 5
###### Header 6
endash: -emdash: --ellipsis: ...
inline equation: $A = \pi*r^{2}$
image: 
horizontal rule (or slide break):
***
> block quote
* unordered list
* item 2
+ sub-item 1
+ sub-item 2
1. ordered list
2. item 2
+ sub-item 1
+ sub-item 2
Table Header
------------Table Cell
Cell 3
|
|
|
|
Second Header
------------Cell 2
Cell 4
Updated 10/30/2014
Contents:
1. Markdown Syntax
2. Knitr chunk options
3. Pandoc options
Syntax
Becomes
Chunk options
option
default value
description
Code evaluation
child
NULL
A character vector of filenames. Knitr will knit the files and place them into the main document.
code
NULL
Set to R code. Knitr will replace the code in the chunk with the code in the code option.
Knitr will evaluate the chunk in the named language, e.g. engine = 'python'. Run names(knitr::knit_engines$get()) to
see supported languages.
engine
'R'
eval
TRUE
If FALSE, knitr will not run the code in the code chunk.
include
TRUE
If FALSE, knitr will run the chunk but not include the chunk in the final document.
purl
TRUE
If FALSE, knitr will not include the chunk when running purl() to extract the source code.
collapse
FALSE
If TRUE, knitr will collapse all the source and output blocks created by the chunk into a single block.
echo
TRUE
If FALSE, knitr will not display the code in the code chunk above its results in the final document.
Results
If 'hide', knitr will not display the codes results in the final document. If 'hold', knitr will delay displaying all output
pieces until the end of the chunk. If 'asis', knitr will pass through results without reformatting them (useful if results
return raw HTML, etc.)
results
'markup'
error
TRUE
If FALSE, knitr will not display any error messages generated by the code.
message
TRUE
If FALSE, knitr will not display any messages generated by the code.
warning
TRUE
If FALSE, knitr will not display any warning messages generated by the code.
Code Decoration
comment
'##'
A character string. Knitr will append the string to the start of each line of results in the final document.
highlight
TRUE
If TRUE, knitr will highlight the source code in the final output.
prompt
FALSE
If TRUE, knitr will add > to the start of each line of code displayed in the final document.
strip.white
TRUE
If TRUE, knitr will remove white spaces that appear at the beginning or end of a code chunk.
tidy
FALSE
If TRUE, knitr will tidy code chunks for display with the tidy_source() function in the formatR package.
Updated 10/30/2014
Contents:
1. Markdown Syntax
2. Knitr chunk options
3. Pandoc options
default value
description
Chunks
opts.label
NULL
The label of options set in knitr:: opts_template() to use with the chunk.
R.options
NULL
Local R options to use with the chunk. Options are set with options() at start of chunk. Defaults are restored at end.
ref.label
NULL
A character vector of labels of the chunks from which the code of the current chunk is inherited.
autodep
FALSE
If TRUE, knitr will attempt to figure out dependencies between chunks automatically by analyzing object names.
cache
FALSE
If TRUE, knitr will cache the results to reuse in future knits. Knitr will reuse the results until the code chunk is altered.
cache.comments
NULL
If FALSE, knitr will not rerun the chunk if only a code comment has changed.
cache.lazy
TRUE
If TRUE, knitr will use lazyload() to load objects in chunk. If FALSE, knitr will use load() to load objects in chunk.
cache.path
'cache/'
cache.vars
NULL
A character vector of object names to cache if you do not wish to cache each object in the chunk.
dependson
NULL
A character vector of chunk labels to specify which other chunks a chunk depends on. Knitr will update a cached
chunk if its dependencies change.
Cache
A file path to the directory to store cached results in. Path should begin in the directory that the .Rmd file is saved in.
Animation
anipots
'controls,loop'
interval
dev
'png'
The R function name that will be used as a graphical device to record plots, e.g. dev='CairoPDF'.
dev.args
NULL
dpi
72
external
TRUE
fig.align
'default'
fig.cap
NULL
fig.env
'figure'
fig.ext
NULL
fig.height, fig.width
Plots
A number for knitr to use as the dots per inch (dpi) in graphics (when applicable).
If TRUE, knitr will externalize tikz graphics to save LaTex compilation time (only for the tikzDevice::tikz() device).
How to align graphics in the final document. One of 'left', 'right', or 'center'.
A character string to be used as a figure caption in LaTex.
The Latex environment for figures.
The file extension for figure output, e.g. fig.ext='png'.
The width and height to use in R for plots created by the chunk (in inches).
fig.keep
'high'
If 'high', knitr will merge low-level changes into high level plots. If 'all', knitr will keep all plots (low-level changes may
produce new plots). If 'first', knitr will keep the first plot only. If 'last', knitr will keep the last plot only. If 'none', knitr
will discard all plots.
fig.lp
'fig:'
fig.path
'figure/'
fig.pos
''
fig.process
NULL
fig.retina
fig.scap
NULL
fig.subcap
NULL
fig.show
'asis'
If 'hide', knitr will generate the plots created in the chunk, but not include them in the final document. If 'hold', knitr
will delay displaying the plots created by the chunk until the end of the chunk. If 'animate', knitr will combine all of
the plots created by the chunk into an animation.
fig.showtext
NULL
out.extra
NULL
out.height, out.width
NULL
The width and height to scale plots to in the final output. Can be in units recognized by output, e.g. 8\\linewidth, 50px
resize.height, resize.width
NULL
The width and height to resize tike graphics in LaTex, passed to \resizebox{}{}.
sanitize
FALSE
A file path to the directory where knitr should store the graphics files created by the chunk.
A character string to be used as the figure position arrangement in LaTex.
A function to post-process a figure file. Should take a filename and return a filename of a new figure source.
Dpi multiplier for displaying HTML output on retina screens.
Updated 10/30/2014
Templates
Basic YAML
html_document
pdf_document
word_document
md_document
ioslides_presentation
slidy_presentation
beamer_presentation
Template options
---
Latex options
title: "My PDF"
output:
output: pdf_document
html_document:
fontsize: 11pt
toc: true
geometry: margin=1in
toc_depth: 2
---
---
Interactive Docs
---
---
title: "Chapters"
output: md_document
Contents:
1. Markdown Syntax
2. Knitr chunk options
3. Pandoc options
title: "Slides"
output:
slidy_presentation:
incremental: true
runtime: shiny
---
becomes
You can start a new slide with a horizontal rule`***` if you do not want
a header.
## Bullets
Render bullets with
- a dash
- another dash
## Incremental bullets
>- Use this format
>- to have bullets appear
>- one at a time (incrementally)
ioslides
f
w
o
h
p
slidy
C
F
A
S
B
description
lang
fontsize
documentclass
classoption
geometry
Document fonts (works only with xelatex and lualatex, see the latex_engine option)
Color for internal, external, and citation links (red, green, magenta, cyan, blue, black)
Updated 10/30/2014
colortheme
css
X
X
duration
fig_caption
fig_crop
fig_retina
fig_width
X
X
X
X
Add a countdown timer (in minutes) to footer of slides (e.g., duration: 45).
t fonttheme
X
includes
-in_header
-before_body
-after_body
X "textmate")
See below
X
X
latex_engine
X
X
number_section
Save a copy of .tex file that contains knitr output (in addition to the .Rmd and PDF files)?
File path to a logo (at least 128 x 128) to add to presentation (e.g., logo: logo.png).
X
preserve_yaml
reference_docx
Directory of dependency files to use (Bootstrap, MathJax, etc.) (e.g., lib_dir: libs).
X
X
mathjax
Save a copy of .md file that contains knitr output (in addition to the .Rmd and HTML files)?
X
logo
X
X
X
X
smaller
smart
template
theme
toc
toc_depth
X
X
The lowest heading level that defines individual slides (e.g., slide_level: 2).
Use the smaller font size in the presentation?
X
X
transition
slide_level
widescreen
keep_tex
variant
incremental
self_contained
X
X
s pandoc_args
highlight
lib_dir
footer
font_adjustmen
description
fig_height
keep_md
beamer
slidy
ioslides
md
word
option
html
Contents:
1. Markdown Syntax
2. Knitr chunk options
3. Pandoc options