knitr::opts_chunk$set( echo = FALSE, eval = TRUE, ## output settings for PDFs fig.pos = "H", out.extra = "", fig.show = 'hold', fig.align = 'center' )
# image settings for html and pdf # [only applies to images inserted with knitr::include_graphics()] if(knitr::is_html_output()) { knitr::opts_chunk$set(dpi = 72) } else if(knitr::is_latex_output()) { knitr::opts_chunk$set(out.width = "100%") }
Update this template with your custom content. Then create a formatted output document by pressing the Knit
button in or using the Shift + Ctrl + K
shortcut in R Studio.
Review the package documentation for more about configuring the output. In brief, you should choose one or more output formats. This template is oriented toward html, Word, or PDF output, but you can choose anything you want. Include multiple formats to knit them all at once. Delete or comment out the ones you don't need.
Some output formats allow additional configurations (table of contents, color scheme or logo, etc). See the README for more.
You can set some additional properties in the header, such as output file name and location. If you don't customize these, defaults will be used. See the README for more.
This document is written in R Markdown.
Some common markdown syntax is demonstrated below. More information is available from RStudio, among many other places.
Text can easily be made italic or bold or ~~strikethrough~~ or ~subscript~ or ^superscript^.
You can make unordered lists:
You can also make ordered lists:
Embed R code and results via code chunks. You can decide whether to print the code, the results, and any messages or warnings.
mean_speed <- mean(cars$speed) mean_speed
Objects in the current environment are accessible via inline code. For example, the mean speed of the cars
dataset is r mean_speed
.
If you want to print the code verbatim without running it, you can do that by adjusting the chunk options:
min_speed <- min(cars$speed) min_speed
And if you want to run code without printing it, you can do that too.
max_speed <- max(cars$speed) max_speed
The maximum speed is r max_speed
.
Save image files in the images/
subdirectory. Insert them into the document like this:

If you want to number and cross-reference your images or have more control over how they're displayed, insert them as R code chunks instead. Be sure to give each code chunk a unique label and a caption, as in Figure \@ref(fig:chunk-name) (set eval = TRUE
):
knitr::include_graphics("images/image_name.png")
Equations can be easily inserted with standard LaTeX syntax. Inline: $y_i = \beta_0 + \beta_1x_i + \varepsilon_i$
Standalone:
$$y_i = \beta_0 + \beta_1x_i + \varepsilon_i$$
Print a formatted table with knitr::kable()
and refer to it as Table \@ref(tab:cars-table):
knitr::kable( head(cars), caption = "A table with some car data." #,longtable = TRUE )
Tip: to allow tables to break across PDF pages, pass kable(..., longtable = TRUE)
.
Generate a plot and refer to it as Figure \@ref(fig:cars-figure):
plot(cars)
Citations are stored as BibTeX entries in references.bib. They can be referenced inline by BibTeX id [@rmarkdown].
Insert a footnote anywhere.[^my-note]
[^my-note]: Citations and footnotes will be formatted automatically when you render the document.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.