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%") }
This is some introductory text. It will appear above the table of contents.
# insert a page TOC at the top of the page blogdown::shortcode_html("toc")
When this file is rendered as a webpage, the title will be assigned an <H1>
html tag. It's a good idea to make the header hierarchy for page content start with level 2 (i.e., start the line with ##
) so section headers don't compete with the page title for importance.
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.
A new output directory will be created, containing a copy of this .Rmd file (renamed index.Rmd
) and subfolders for supporting documents.
TODO: expand
slug, weight, type, tags
The default knit function for this document is bscContentHelpers::knit_for_web
. When you knit the document, a few things will happen:
index.Rmd
.include_pdf
to FALSE
in the YAML header, a PDF version of this document will be generated and put in the page bundle's files/
subdirectory.files/
.files/
.The page bundle will be suitable for inclusion in the BSC site. (Note that you'll still need to preview and build the page locally before it can go live on the site. See the site repo and README for more.)
If you'd rather just output a static document (like a PDF), you're better off using the Article
template.
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.
Some code should just be rendered if the output is HTML (e.g., a web page). Conditionally execute code chunks by setting eval=knitr::is_html_output()
.
Shortcodes are special types of code chunks specifically for webpages built with Hugo.
Some useful shortcodes:
blogdown::shortcode_open("hint", "warning")
Only evaluate shortcodes if output is html. Suppress for pdf.
blogdown::shortcode_close("hint")
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:
knitr::include_graphics("path/to/image.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.