SlideShare a Scribd company logo
2
Most read
render()
RStudio Pro FeaturesWorkflow
Debug ModeEmbed code with knitr syntax
learn more at rmarkdown.rstudio.com
Rmd
Reproducible Research
At the click of a button, or the type
of a command, you can rerun the
code in an R Markdown file to
reproduce your work and export
the results as a finished report.
Use rmarkdown::render()
to render/knit at cmd line.
Important args:
input - file to render
output_format
output_options - List of
render options (as in YAML)
output_file
output_dir
params - list of params to use
envir - environment to
evaluate code chunks in
encoding - of input file
R Markdown Cheat Sheet
RStudioĀ® is a trademark of RStudio, Inc. • CC BY RStudio • info@rstudio.com • 844-448-1212 • rstudio.com Learn more at rmarkdown.rstudio.com • RStudio IDE 0.99.879 • Updated: 02/16More cheat sheets at http://www.rstudio.com/resources/cheatsheets/
Debug ModeParameters
.Rmd files
An R Markdown (.Rmd) file is a record of
your research. It contains the code that a
scientist needs to reproduce your work
along with the narration that a reader
needs to understand your work.
Dynamic Documents
You can choose to export the
finished report as a html, pdf,
MS Word, ODT, RTF, or
markdown document; or as a
html or pdf based slide show.
Rmd
.Rmd structure
Modify
chunk
options
Run all
previous
chunks
Run
current
chunk
Insert
code
chunk
Go to
code
chunk
Run
code
chunk(s)
Set
preview
location
Open in
window
Save Find and
replace
Open a new .Rmd file at File ā–¶ New File ā–¶ R Markdown.
Use the wizard that opens to pre-populate the file with a
template
1 Write document
by editing template2
Spell
Check
Publish Show
outline
Knit document to create report
Use knit button or render() to knit3
Examine build log
in R Markdown console6
Preview Output
in IDE window4
Use output file that is
saved alongside .Rmd7
Publish (optional)
to web or server5
Reload document
Find in document
File path to
output document
Synch publish button
to accounts at
• rpubs.com,
• shinyapps.io
• RStudio Connect
Debug ModeInteractive Documents
Optional section of
render (e.g. pandoc)
options written as
key:value pairs (YAML).
• At start of file
• Between lines of - - -
YAML Header
Narration formatted with
markdown, mixed with:
Text
Chunks of embedded
code. Each chunk:
• Begins with ```{r}
• ends with ```
R Markdown will run the
code and append the
results to the doc.
It will use the location of
the .Rmd file as the
working directory
Code chunks
Turn your report into an interactive
Shiny document in 4 steps
* Your report will rendered as a Shiny app, which means you
must choose an html output format, like html_document,
and serve it with an active R Session.
1 Add runtime: shiny to the
YAML header.
2 Call Shiny input functions to embed
input objects.
4 Render with rmarkdown::run or click
Run Document in RStudio IDE
3 Call Shiny render functions to embed
reactive output.
---
output: html_document
runtime: shiny
---
```{r, echo = FALSE}
numericInput("n",
"How many cars?", 5)
renderTable({
head(cars, input$n)
})
```
Embed a complete app into your document with
shiny::shinyAppDir()
Inline code
Insert with `r <code>`. Results appear as text without code.
Built with
`r getRversion()`
Global options
Set with knitr::opts_chunk$set(), e.g.
```{r include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r echo=TRUE}
getRversion()
```
Code chunks
One or more lines surrounded
with ```{r} and ```. Place
chunk options within curly
braces, after r. Insert with
cache - cache results for future knits
(default = FALSE)
cache.path - directory to save cached
results in (default = "cache/")
child - file(s) to knit and then include
(default = NULL)
collapse - collapse all output into single
block (default = FALSE)
comment - prefix for each line of results
(default = '##')
dependson - chunk dependencies for
caching (default = NULL)
echo - Display code in output document
(default = TRUE)
engine - code language used in chunk
(default = 'R')
error - Display error messages in doc
(TRUE) or stop render when errors occur
(FALSE) (default = FALSE)
eval - Run code in chunk (default =
TRUE)
message - display code messages in
document (default = TRUE)
results (default = 'markup')
'asis' - passthrough results
'hide' - do not display results
'hold' - put all results below all code
tidy - tidy code for display (default =
FALSE)
warning - display code warnings in
document (default = TRUE)
fig.align - 'left', 'right', or 'center' (default
= 'default')
fig.cap - figure caption as character
string (default = NULL)
fig.height, fig.width - Dimensions of
plots in inches
highlight - highlight source code
(default = TRUE)
include - Include chunk in doc after
running (default = TRUE)
Important chunk options
Parameterize your documents to reuse with
different inputs (e.g., data sets, values, etc.)
Add parameters
1 Create and set
parameters in the
header as sub-values
of params
---
params:
n: 100
d: !r Sys.Date()
---
Call parameters
2 Call parameter
values in code as
params$<name>
Today’s date
is `r params$d`
Set parameters
3 Set values wth Knit
with parameters or
the params argument
of render():
render("doc.Rmd",
params = list(n = 1, d = as.Date("2015-01-01"))
Indent 2
spaces
Options not listed above: R.options, aniopts, autodep, background, cache.comments, cache.lazy, cache.rebuild, cache.vars, dev, dev.args, dpi, engine.opts, engine.path, fig.asp, fig.env, fig.ext, fig.keep,
fig.lp, fig.path, fig.pos, fig.process, fig.retina, fig.scap, fig.show, fig.showtext, fig.subcap, interval, out.extra, out.height, out.width, prompt, purl, ref.label, render, size, split, tidy.opts
RStudioĀ® is a trademark of RStudio, Inc. • CC BY RStudio • info@rstudio.com • 844-448-1212 • rstudio.com More cheat sheets at http://www.rstudio.com/resources/cheatsheets/
Debug ModePandoc’s Markdown Debug ModeSet render options with YAML
Plain text
End a line with two spaces
to start a new paragraph.
*italics* and **bold**
`verbatim code`
sub/superscript^2^~2~
~~strikethrough~~
escaped: * _ 
endash: --, emdash: ---
equation: $A = pi*r^{2}$
equation block:
$$E = mc^{2}$$
> block quote
# Header1 {#anchor}
## Header 2 {#css_id}
### Header 3 {.css_class}
#### Header 4
##### Header 5
###### Header 6
<!--Text comment-->
textbf{Tex ignored in HTML}
<em>HTML ignored in pdfs</em>
<http://www.rstudio.com>
[link](www.rstudio.com)
Jump to [Header 1](#anchor)
image:
![Caption](smallorb.png)
* unordered list
+ sub-item 1
+ sub-item 2
- sub-sub-item 1
* item 2
Continued (indent 4 spaces)
1. ordered list
2. item 2
i) sub-item 1
A. sub-sub-item 1
(@) A list whose numbering
continues after
(@) an interruption
Term 1
: Definition 1
| Right | Left | Default | Center |
|------:|:-----|---------|:------:|
| 12 | 12 | 12 | 12 |
| 123 | 123 | 123 | 123 |
| 1 | 1 | 1 | 1 |
- slide bullet 1
- slide bullet 2
(>- to have bullets appear on click)
horizontal rule/slide break:
***
A footnote [^1]
[^1]: Here is the footnote.
Debug ModeCitations and Bibliographies
Set bibliography file and CSL 1.0 Style
file (optional) in the YAML header1
Use citation keys in text
2
Render. Bibliography will be added to end
of document3
Create citations with .bib, .bibtex, .copac, .enl, .json,
.medline, .mods, .ris, .wos, and .xml files
Smith cited [@smith04].
Smith cited without author [-@smith04].
@smith04 cited in line.
---
bibliography: refs.bib
csl: style.csl
---
Debug ModeCreate a Reusable template
1 Create a new package with a
inst/rmarkdown/templates directory
2 In the directory, Place a folder that contains:
• template.yaml (see below)
• skeleton.Rmd (contents of the template)
• any supporting files
4 Access
template in
wizard at File ā–¶
New File ā–¶
R Markdown
3 Install the package
---
name: My Template
---
template.yaml
Write with syntax on the left to create effect on right (after render)
Debug ModeTable suggestions
Several functions format R data into tables
data <- faithful[1:4, ]
```{r results = "asis"}
print(xtable::xtable(data, caption = "Table with xtable"),
type = "html", html.table.attributes = "border=0"))
```
```{r results = "asis"}
stargazer::stargazer(data, type = "html",
title = "Table with stargazer")
```
```{r results = 'asis'}
knitr::kable(data, caption = "Table with kable")
```
sub-option description
citation_package The LaTeX package to process citations, natbib, biblatex or none X X X
code_folding Let readers to toggle the display of R code, "none", "hide", or "show" X
colortheme Beamer color theme to use X
css CSS file to use to style document X X X
dev Graphics device to use for figure output (e.g. "png") X X X X X X X
duration Add a countdown timer (in minutes) to footer of slides X
fig_caption Should figures be rendered with captions? X X X X X X X
fig_height, fig_width Default figure height and width (in inches) for document X X X X X X X X X X
highlight Syntax highlighting: "tango","pygments","kate","zenburn","textmate" X X X X X
includes File of content to place in document (in_header, before_body, after_body) X X X X X X X X
incremental Should bullets appear one at a time (on presenter mouse clicks)? X X X
keep_md Save a copy of .md file that contains knitr output X X X X X X
keep_tex Save a copy of .tex file that contains knitr output X X
latex_engine Engine to render latex, "pdflatex", "xelatex", or "lualatex" X X
lib_dir Directory of dependency files to use (Bootstrap, MathJax, etc.) X X X
mathjax Set to local or a URL to use a local/URL version of MathJax to render X X X
md_extensions Markdown extensions to add to default definition or R Markdown X X X X X X X X X X
number_sections Add section numbering to headers X X
pandoc_args Additional arguments to pass to Pandoc X X X X X X X X X X
preserve_yaml Preserve YAML front matter in final document? X
reference_docx docx file whose styles should be copied when producing docx output X
self_contained Embed dependencies into the doc X X X
slide_level The lowest heading level that defines individual slides X
smaller Use the smaller font size in the presentation? X
smart Convert straight quotes to curly, dashes to em-dashes, … to ellipses, etc. X X X
template Pandoc template to use when rendering file X X X X X
theme Bootswatch or Beamer theme to use for page X X
toc Add a table of contents at start of document X X X X X X X
toc_depth The lowest level of headings to add to table of contents X X X X X X
toc_float Float the table of contents to the left of the main content X
html
pdf
word
odt
rtf
md
ioslides
slidy
beamer
Options not listed: extra_dependencies, fig_crop, fig_retina, font_adjustment, font_theme, footer, logo, html_preview,
reference_odt, transition, variant, widescreen
When you render, R Markdown
1. runs the R code, embeds results and text into .md file with knitr
2. then converts the .md file into the finished format with pandoc
Set a document’s
default output format
in the YAML header:
---
output: html_document
---
# Body
output value creates
html_document html
pdf_document pdf (requires Tex )
word_document Microsoft Word (.docx)
odt_document OpenDocument Text
rtf_document Rich Text Format
md_document Markdown
github_document Github compatible markdown
ioslides_presentation ioslides HTML slides
slidy_presentation slidy HTML slides
beamer_presentation Beamer pdf slides (requires Tex)
Customize output
with sub-options
(listed at right):
---
output:
html_document:
code_folding: hide
toc_float: TRUE
---
# Body
Indent 2
spaces
Indent 4
spaces
# Tabset {.tabset .tabset-fade .tabset-pills}
## Tab 1
text 1
## Tab 2
text 2
### End tabset
Use .tabset css class
to place sub-headers
into tabs
html tabsets
gituhb
Learn more in
the stargazer,
xtable, and
knitr packages.
Learn more at rmarkdown.rstudio.com • RStudio IDE 0.99.879 • Updated: 02/16

More Related Content

DOCX
Ī— ĪµĻ€Ī±Ī½Ī¬ĻƒĻ„Ī±ĻƒĪ· ĻƒĻ„Ī·Ī½ Ī ĪµĪ»ĪæĻ€ĻŒĪ½Ī½Ī·ĻƒĪæ
PDF
ĪœĪ±ĪøĪ·Ī¼Ī±Ļ„Ī¹ĪŗĪ¬ Ε΄.1.3: Ī„Ī„ĪŸĪ¹ αριθμοί μέχρι το 1.000.000.000΄΄ Ī˜ĪµĻŒĪ“Ļ‰ĻĪæĻ‚ ΑρβανιτίΓης...
PDF
Ī“Ī»ĻŽĻƒĻƒĪ± Ε΄ 13.2. ΄΄ ĪšĪ±Ļ„Ī±ĻƒĪŗĪµĻ…Ī­Ļ‚ των Ī±Ī½ĪøĻĻŽĻ€Ļ‰Ī½ ΄΄
PPTX
Οι φίλοι μου Δ΄τάξη 8Īæ Ī“Ī·Ī¼ĪæĻ„Ī¹ĪŗĻŒ ĻƒĻ‡ĪæĪ»ĪµĪÆĪæ Ī£Ī„ĪšĪ•Ī©Ī
PPTX
ŅšŠ°Ń€Š°ŠæŠ°Š¹Ń‹Š¼ Ń‚Ń€ŠøŠ³Š¾Š½Š¾Š¼ŠµŃ‚Ń€ŠøŃŠ»Ń‹Ņ› Ń‚ŠµŅ£Š“ŠµŃƒŠ»ŠµŃ€Š³Šµ есептер ŃˆŃ‹Ņ“Š°Ń€Ńƒ
DOCX
01 solicitud de pasantias egresado
PDF
Ī˜Ī­Ī¼Ī±Ļ„Ī± Ī ĻĪæĻƒĪæĪ¼ĪæĪÆĻ‰ĻƒĪ·Ļ‚ μέχρι την ĪµĪ¾ĪÆĻƒĻ‰ĻƒĪ·Ļ‚ εφαπτομένης Ī±Ļ€ĻŒ την Ελληνογαλλική Σχολ...
Ī— ĪµĻ€Ī±Ī½Ī¬ĻƒĻ„Ī±ĻƒĪ· ĻƒĻ„Ī·Ī½ Ī ĪµĪ»ĪæĻ€ĻŒĪ½Ī½Ī·ĻƒĪæ
ĪœĪ±ĪøĪ·Ī¼Ī±Ļ„Ī¹ĪŗĪ¬ Ε΄.1.3: Ī„Ī„ĪŸĪ¹ αριθμοί μέχρι το 1.000.000.000΄΄ Ī˜ĪµĻŒĪ“Ļ‰ĻĪæĻ‚ ΑρβανιτίΓης...
Ī“Ī»ĻŽĻƒĻƒĪ± Ε΄ 13.2. ΄΄ ĪšĪ±Ļ„Ī±ĻƒĪŗĪµĻ…Ī­Ļ‚ των Ī±Ī½ĪøĻĻŽĻ€Ļ‰Ī½ ΄΄
Οι φίλοι μου Δ΄τάξη 8Īæ Ī“Ī·Ī¼ĪæĻ„Ī¹ĪŗĻŒ ĻƒĻ‡ĪæĪ»ĪµĪÆĪæ Ī£Ī„ĪšĪ•Ī©Ī
ŅšŠ°Ń€Š°ŠæŠ°Š¹Ń‹Š¼ Ń‚Ń€ŠøŠ³Š¾Š½Š¾Š¼ŠµŃ‚Ń€ŠøŃŠ»Ń‹Ņ› Ń‚ŠµŅ£Š“ŠµŃƒŠ»ŠµŃ€Š³Šµ есептер ŃˆŃ‹Ņ“Š°Ń€Ńƒ
01 solicitud de pasantias egresado
Ī˜Ī­Ī¼Ī±Ļ„Ī± Ī ĻĪæĻƒĪæĪ¼ĪæĪÆĻ‰ĻƒĪ·Ļ‚ μέχρι την ĪµĪ¾ĪÆĻƒĻ‰ĻƒĪ·Ļ‚ εφαπτομένης Ī±Ļ€ĻŒ την Ελληνογαλλική Σχολ...

What's hot (13)

PDF
ĪœĪ±ĪøĪ·Ī¼Ī±Ļ„Ī¹ĪŗĪ¬ Ε΄ - Ī•Ļ€Ī±Ī½Ī¬Ī»Ī·ĻˆĪ· 8Ī·Ļ‚ ĪµĪ½ĻŒĻ„Ī·Ļ„Ī±Ļ‚, κεφ. 46-49 ΄΄
PDF
Ī“Ī»ĻŽĻƒĻƒĪ± Δ΄. 2.2. ΄΄ Το ποτάμι τρέχει να ĻƒĻ…Ī½Ī±Ī½Ļ„Ī®ĻƒĪµĪ¹ τη ĪøĪ¬Ī»Ī±ĻƒĻƒĪ±Ī„Ī„
PDF
Ī•Ī Ī•ĪžĪ•Ī”Ī“Ī‘Ī–ĪŸĪœĪ‘Ī™ Ī£Ī„ĪœĪœĪ•Ī¤Ī”Ī™ĪšĪ‘ Ī£Ī§Ī—ĪœĪ‘Ī¤Ī‘
DOC
Πρόσκληση για 25Ī· Mαρτίου
DOC
Eπιχειρηματολογία
PPTX
Ī•Ī½ĪµĻƒĻ„ĻŽĻ„Ī±Ļ‚, Ī Ī±ĻĪ±Ļ„Ī±Ļ„Ī¹ĪŗĻŒĻ‚, AĻŒĻĪ¹ĻƒĻ„ĪæĻ‚
DOCX
Έκθεση Α΄ Λυκείου, Ī ĻĪæĻ†ĪæĻĪ¹ĪŗĻŒĻ‚ και Ī³ĻĪ±Ļ€Ļ„ĻŒĻ‚ Ī»ĻŒĪ³ĪæĻ‚
PPTX
18. Java associative arrays
DOCX
Ī£Ī„ĪĪ¤Ī‘ĪšĪ¤Ī™ĪšĪŸ: Το ΄ποκείμενο - Το Αντικείμενο
PDF
Odoo - From v7 to v8: the new api
Ā 
PDF
Ī›Ī‘Ī¤Ī™ĪĪ™ĪšĪ‘ Ī›Ī„ĪšĪ•Ī™ĪŸĪ„ μάθημα 10Īæ
PDF
Α΄ κλίση ĪæĻ…ĻƒĪ¹Ī±ĻƒĻ„Ī¹ĪŗĻŽĪ½. Ī•Ī½ĻŒĻ„Ī·Ļ„Ī± 6 Αρχαίων Α΄ Ī“Ļ…Ī¼Ī½Ī±ĻƒĪÆĪæĻ…
DOCX
παρατατικος Ī±ĻŒĻĪ¹ĻƒĻ„ĪæĻ‚
ĪœĪ±ĪøĪ·Ī¼Ī±Ļ„Ī¹ĪŗĪ¬ Ε΄ - Ī•Ļ€Ī±Ī½Ī¬Ī»Ī·ĻˆĪ· 8Ī·Ļ‚ ĪµĪ½ĻŒĻ„Ī·Ļ„Ī±Ļ‚, κεφ. 46-49 ΄΄
Ī“Ī»ĻŽĻƒĻƒĪ± Δ΄. 2.2. ΄΄ Το ποτάμι τρέχει να ĻƒĻ…Ī½Ī±Ī½Ļ„Ī®ĻƒĪµĪ¹ τη ĪøĪ¬Ī»Ī±ĻƒĻƒĪ±Ī„Ī„
Ī•Ī Ī•ĪžĪ•Ī”Ī“Ī‘Ī–ĪŸĪœĪ‘Ī™ Ī£Ī„ĪœĪœĪ•Ī¤Ī”Ī™ĪšĪ‘ Ī£Ī§Ī—ĪœĪ‘Ī¤Ī‘
Πρόσκληση για 25Ī· Mαρτίου
Eπιχειρηματολογία
Ī•Ī½ĪµĻƒĻ„ĻŽĻ„Ī±Ļ‚, Ī Ī±ĻĪ±Ļ„Ī±Ļ„Ī¹ĪŗĻŒĻ‚, AĻŒĻĪ¹ĻƒĻ„ĪæĻ‚
Έκθεση Α΄ Λυκείου, Ī ĻĪæĻ†ĪæĻĪ¹ĪŗĻŒĻ‚ και Ī³ĻĪ±Ļ€Ļ„ĻŒĻ‚ Ī»ĻŒĪ³ĪæĻ‚
18. Java associative arrays
Ī£Ī„ĪĪ¤Ī‘ĪšĪ¤Ī™ĪšĪŸ: Το ΄ποκείμενο - Το Αντικείμενο
Odoo - From v7 to v8: the new api
Ā 
Ī›Ī‘Ī¤Ī™ĪĪ™ĪšĪ‘ Ī›Ī„ĪšĪ•Ī™ĪŸĪ„ μάθημα 10Īæ
Α΄ κλίση ĪæĻ…ĻƒĪ¹Ī±ĻƒĻ„Ī¹ĪŗĻŽĪ½. Ī•Ī½ĻŒĻ„Ī·Ļ„Ī± 6 Αρχαίων Α΄ Ī“Ļ…Ī¼Ī½Ī±ĻƒĪÆĪæĻ…
παρατατικος Ī±ĻŒĻĪ¹ĻƒĻ„ĪæĻ‚
Ad

Similar to Rmarkdown cheatsheet-2.0 (20)

PDF
RStudio_s_R_Markdown_documentation_Cheat_Cheet__1677232908.pdf
PDF
rmarkdown.pdf
PDF
R package development, create package documentation isabella gollini
PPTX
Reproducible Computational Research in R
PDF
Devtools cheatsheet
PDF
Devtools cheatsheet
PDF
Basics of R programming for analytics [Autosaved] (1).pdf
PDF
Language-agnostic data analysis workflows and reproducible research
PDF
Draft sas and r and sas (may, 2018 asa meeting)
PDF
Reproducibility with R
PPTX
R sharing 101
DOCX
CS 23001 Computer Science II Data Structures & AbstractionPro.docx
PDF
7986-lect 7.pdf
PDF
Extensible markup language attacks
PDF
What we can learn from Rebol?
PDF
Fluentd unified logging layer
PPTX
R You Ready? An I/O Psychologist's Guide to R and Rstudio
PPTX
R Introduction
PDF
0100_Embeded_C_CompilationProcess.pdf
ODP
RStudio_s_R_Markdown_documentation_Cheat_Cheet__1677232908.pdf
rmarkdown.pdf
R package development, create package documentation isabella gollini
Reproducible Computational Research in R
Devtools cheatsheet
Devtools cheatsheet
Basics of R programming for analytics [Autosaved] (1).pdf
Language-agnostic data analysis workflows and reproducible research
Draft sas and r and sas (may, 2018 asa meeting)
Reproducibility with R
R sharing 101
CS 23001 Computer Science II Data Structures & AbstractionPro.docx
7986-lect 7.pdf
Extensible markup language attacks
What we can learn from Rebol?
Fluentd unified logging layer
R You Ready? An I/O Psychologist's Guide to R and Rstudio
R Introduction
0100_Embeded_C_CompilationProcess.pdf
Ad

More from Dieudonne Nahigombeye (10)

PDF
PDF
Rstudio ide-cheatsheet
PDF
Reg ex cheatsheet
PDF
How big-is-your-graph
PDF
Ggplot2 cheatsheet-2.1
PDF
Eurostat cheatsheet
PDF
Data transformation-cheatsheet
PDF
Data import-cheatsheet
PDF
Advanced r
Rstudio ide-cheatsheet
Reg ex cheatsheet
How big-is-your-graph
Ggplot2 cheatsheet-2.1
Eurostat cheatsheet
Data transformation-cheatsheet
Data import-cheatsheet
Advanced r

Recently uploaded (20)

PDF
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
PPTX
Qualitative Qantitative and Mixed Methods.pptx
PDF
ā€œGetting Started with Data Analytics Using R – Concepts, Tools & Case Studiesā€
PPTX
IBA_Chapter_11_Slides_Final_Accessible.pptx
PPTX
Database Infoormation System (DBIS).pptx
PPT
Quality review (1)_presentation of this 21
PDF
Lecture1 pattern recognition............
PPTX
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
PPTX
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
PDF
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
PPTX
STUDY DESIGN details- Lt Col Maksud (21).pptx
PPTX
Business Acumen Training GuidePresentation.pptx
PPTX
Supervised vs unsupervised machine learning algorithms
PDF
annual-report-2024-2025 original latest.
PPTX
Microsoft-Fabric-Unifying-Analytics-for-the-Modern-Enterprise Solution.pptx
PDF
Business Analytics and business intelligence.pdf
PPTX
Introduction to machine learning and Linear Models
PPTX
Data_Analytics_and_PowerBI_Presentation.pptx
PPTX
IB Computer Science - Internal Assessment.pptx
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
Qualitative Qantitative and Mixed Methods.pptx
ā€œGetting Started with Data Analytics Using R – Concepts, Tools & Case Studiesā€
IBA_Chapter_11_Slides_Final_Accessible.pptx
Database Infoormation System (DBIS).pptx
Quality review (1)_presentation of this 21
Lecture1 pattern recognition............
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
STUDY DESIGN details- Lt Col Maksud (21).pptx
Business Acumen Training GuidePresentation.pptx
Supervised vs unsupervised machine learning algorithms
annual-report-2024-2025 original latest.
Microsoft-Fabric-Unifying-Analytics-for-the-Modern-Enterprise Solution.pptx
Business Analytics and business intelligence.pdf
Introduction to machine learning and Linear Models
Data_Analytics_and_PowerBI_Presentation.pptx
IB Computer Science - Internal Assessment.pptx

Rmarkdown cheatsheet-2.0

  • 1. render() RStudio Pro FeaturesWorkflow Debug ModeEmbed code with knitr syntax learn more at rmarkdown.rstudio.com Rmd Reproducible Research At the click of a button, or the type of a command, you can rerun the code in an R Markdown file to reproduce your work and export the results as a finished report. Use rmarkdown::render() to render/knit at cmd line. Important args: input - file to render output_format output_options - List of render options (as in YAML) output_file output_dir params - list of params to use envir - environment to evaluate code chunks in encoding - of input file R Markdown Cheat Sheet RStudioĀ® is a trademark of RStudio, Inc. • CC BY RStudio • info@rstudio.com • 844-448-1212 • rstudio.com Learn more at rmarkdown.rstudio.com • RStudio IDE 0.99.879 • Updated: 02/16More cheat sheets at http://www.rstudio.com/resources/cheatsheets/ Debug ModeParameters .Rmd files An R Markdown (.Rmd) file is a record of your research. It contains the code that a scientist needs to reproduce your work along with the narration that a reader needs to understand your work. Dynamic Documents You can choose to export the finished report as a html, pdf, MS Word, ODT, RTF, or markdown document; or as a html or pdf based slide show. Rmd .Rmd structure Modify chunk options Run all previous chunks Run current chunk Insert code chunk Go to code chunk Run code chunk(s) Set preview location Open in window Save Find and replace Open a new .Rmd file at File ā–¶ New File ā–¶ R Markdown. Use the wizard that opens to pre-populate the file with a template 1 Write document by editing template2 Spell Check Publish Show outline Knit document to create report Use knit button or render() to knit3 Examine build log in R Markdown console6 Preview Output in IDE window4 Use output file that is saved alongside .Rmd7 Publish (optional) to web or server5 Reload document Find in document File path to output document Synch publish button to accounts at • rpubs.com, • shinyapps.io • RStudio Connect Debug ModeInteractive Documents Optional section of render (e.g. pandoc) options written as key:value pairs (YAML). • At start of file • Between lines of - - - YAML Header Narration formatted with markdown, mixed with: Text Chunks of embedded code. Each chunk: • Begins with ```{r} • ends with ``` R Markdown will run the code and append the results to the doc. It will use the location of the .Rmd file as the working directory Code chunks Turn your report into an interactive Shiny document in 4 steps * Your report will rendered as a Shiny app, which means you must choose an html output format, like html_document, and serve it with an active R Session. 1 Add runtime: shiny to the YAML header. 2 Call Shiny input functions to embed input objects. 4 Render with rmarkdown::run or click Run Document in RStudio IDE 3 Call Shiny render functions to embed reactive output. --- output: html_document runtime: shiny --- ```{r, echo = FALSE} numericInput("n", "How many cars?", 5) renderTable({ head(cars, input$n) }) ``` Embed a complete app into your document with shiny::shinyAppDir() Inline code Insert with `r <code>`. Results appear as text without code. Built with `r getRversion()` Global options Set with knitr::opts_chunk$set(), e.g. ```{r include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` ```{r echo=TRUE} getRversion() ``` Code chunks One or more lines surrounded with ```{r} and ```. Place chunk options within curly braces, after r. Insert with cache - cache results for future knits (default = FALSE) cache.path - directory to save cached results in (default = "cache/") child - file(s) to knit and then include (default = NULL) collapse - collapse all output into single block (default = FALSE) comment - prefix for each line of results (default = '##') dependson - chunk dependencies for caching (default = NULL) echo - Display code in output document (default = TRUE) engine - code language used in chunk (default = 'R') error - Display error messages in doc (TRUE) or stop render when errors occur (FALSE) (default = FALSE) eval - Run code in chunk (default = TRUE) message - display code messages in document (default = TRUE) results (default = 'markup') 'asis' - passthrough results 'hide' - do not display results 'hold' - put all results below all code tidy - tidy code for display (default = FALSE) warning - display code warnings in document (default = TRUE) fig.align - 'left', 'right', or 'center' (default = 'default') fig.cap - figure caption as character string (default = NULL) fig.height, fig.width - Dimensions of plots in inches highlight - highlight source code (default = TRUE) include - Include chunk in doc after running (default = TRUE) Important chunk options Parameterize your documents to reuse with different inputs (e.g., data sets, values, etc.) Add parameters 1 Create and set parameters in the header as sub-values of params --- params: n: 100 d: !r Sys.Date() --- Call parameters 2 Call parameter values in code as params$<name> Today’s date is `r params$d` Set parameters 3 Set values wth Knit with parameters or the params argument of render(): render("doc.Rmd", params = list(n = 1, d = as.Date("2015-01-01")) Indent 2 spaces Options not listed above: R.options, aniopts, autodep, background, cache.comments, cache.lazy, cache.rebuild, cache.vars, dev, dev.args, dpi, engine.opts, engine.path, fig.asp, fig.env, fig.ext, fig.keep, fig.lp, fig.path, fig.pos, fig.process, fig.retina, fig.scap, fig.show, fig.showtext, fig.subcap, interval, out.extra, out.height, out.width, prompt, purl, ref.label, render, size, split, tidy.opts
  • 2. RStudioĀ® is a trademark of RStudio, Inc. • CC BY RStudio • info@rstudio.com • 844-448-1212 • rstudio.com More cheat sheets at http://www.rstudio.com/resources/cheatsheets/ Debug ModePandoc’s Markdown Debug ModeSet render options with YAML Plain text End a line with two spaces to start a new paragraph. *italics* and **bold** `verbatim code` sub/superscript^2^~2~ ~~strikethrough~~ escaped: * _ endash: --, emdash: --- equation: $A = pi*r^{2}$ equation block: $$E = mc^{2}$$ > block quote # Header1 {#anchor} ## Header 2 {#css_id} ### Header 3 {.css_class} #### Header 4 ##### Header 5 ###### Header 6 <!--Text comment--> textbf{Tex ignored in HTML} <em>HTML ignored in pdfs</em> <http://www.rstudio.com> [link](www.rstudio.com) Jump to [Header 1](#anchor) image: ![Caption](smallorb.png) * unordered list + sub-item 1 + sub-item 2 - sub-sub-item 1 * item 2 Continued (indent 4 spaces) 1. ordered list 2. item 2 i) sub-item 1 A. sub-sub-item 1 (@) A list whose numbering continues after (@) an interruption Term 1 : Definition 1 | Right | Left | Default | Center | |------:|:-----|---------|:------:| | 12 | 12 | 12 | 12 | | 123 | 123 | 123 | 123 | | 1 | 1 | 1 | 1 | - slide bullet 1 - slide bullet 2 (>- to have bullets appear on click) horizontal rule/slide break: *** A footnote [^1] [^1]: Here is the footnote. Debug ModeCitations and Bibliographies Set bibliography file and CSL 1.0 Style file (optional) in the YAML header1 Use citation keys in text 2 Render. Bibliography will be added to end of document3 Create citations with .bib, .bibtex, .copac, .enl, .json, .medline, .mods, .ris, .wos, and .xml files Smith cited [@smith04]. Smith cited without author [-@smith04]. @smith04 cited in line. --- bibliography: refs.bib csl: style.csl --- Debug ModeCreate a Reusable template 1 Create a new package with a inst/rmarkdown/templates directory 2 In the directory, Place a folder that contains: • template.yaml (see below) • skeleton.Rmd (contents of the template) • any supporting files 4 Access template in wizard at File ā–¶ New File ā–¶ R Markdown 3 Install the package --- name: My Template --- template.yaml Write with syntax on the left to create effect on right (after render) Debug ModeTable suggestions Several functions format R data into tables data <- faithful[1:4, ] ```{r results = "asis"} print(xtable::xtable(data, caption = "Table with xtable"), type = "html", html.table.attributes = "border=0")) ``` ```{r results = "asis"} stargazer::stargazer(data, type = "html", title = "Table with stargazer") ``` ```{r results = 'asis'} knitr::kable(data, caption = "Table with kable") ``` sub-option description citation_package The LaTeX package to process citations, natbib, biblatex or none X X X code_folding Let readers to toggle the display of R code, "none", "hide", or "show" X colortheme Beamer color theme to use X css CSS file to use to style document X X X dev Graphics device to use for figure output (e.g. "png") X X X X X X X duration Add a countdown timer (in minutes) to footer of slides X fig_caption Should figures be rendered with captions? X X X X X X X fig_height, fig_width Default figure height and width (in inches) for document X X X X X X X X X X highlight Syntax highlighting: "tango","pygments","kate","zenburn","textmate" X X X X X includes File of content to place in document (in_header, before_body, after_body) X X X X X X X X incremental Should bullets appear one at a time (on presenter mouse clicks)? X X X keep_md Save a copy of .md file that contains knitr output X X X X X X keep_tex Save a copy of .tex file that contains knitr output X X latex_engine Engine to render latex, "pdflatex", "xelatex", or "lualatex" X X lib_dir Directory of dependency files to use (Bootstrap, MathJax, etc.) X X X mathjax Set to local or a URL to use a local/URL version of MathJax to render X X X md_extensions Markdown extensions to add to default definition or R Markdown X X X X X X X X X X number_sections Add section numbering to headers X X pandoc_args Additional arguments to pass to Pandoc X X X X X X X X X X preserve_yaml Preserve YAML front matter in final document? X reference_docx docx file whose styles should be copied when producing docx output X self_contained Embed dependencies into the doc X X X slide_level The lowest heading level that defines individual slides X smaller Use the smaller font size in the presentation? X smart Convert straight quotes to curly, dashes to em-dashes, … to ellipses, etc. X X X template Pandoc template to use when rendering file X X X X X theme Bootswatch or Beamer theme to use for page X X toc Add a table of contents at start of document X X X X X X X toc_depth The lowest level of headings to add to table of contents X X X X X X toc_float Float the table of contents to the left of the main content X html pdf word odt rtf md ioslides slidy beamer Options not listed: extra_dependencies, fig_crop, fig_retina, font_adjustment, font_theme, footer, logo, html_preview, reference_odt, transition, variant, widescreen When you render, R Markdown 1. runs the R code, embeds results and text into .md file with knitr 2. then converts the .md file into the finished format with pandoc Set a document’s default output format in the YAML header: --- output: html_document --- # Body output value creates html_document html pdf_document pdf (requires Tex ) word_document Microsoft Word (.docx) odt_document OpenDocument Text rtf_document Rich Text Format md_document Markdown github_document Github compatible markdown ioslides_presentation ioslides HTML slides slidy_presentation slidy HTML slides beamer_presentation Beamer pdf slides (requires Tex) Customize output with sub-options (listed at right): --- output: html_document: code_folding: hide toc_float: TRUE --- # Body Indent 2 spaces Indent 4 spaces # Tabset {.tabset .tabset-fade .tabset-pills} ## Tab 1 text 1 ## Tab 2 text 2 ### End tabset Use .tabset css class to place sub-headers into tabs html tabsets gituhb Learn more in the stargazer, xtable, and knitr packages. Learn more at rmarkdown.rstudio.com • RStudio IDE 0.99.879 • Updated: 02/16