The shortcut to knit a document is Command + Shift + K

Text Formatting Basics

Headers

First Level Header

Second Level Header

Third Level Header

Bulleted and Numbered Lists

  • List element 1
  • List element 2
  • List element 3
    • List item 3a
    • List item 3b

numbered lists:

  1. Numbered list 1
  2. Numbered list 2
  3. Numbered list 3.The numbers auto-increment, don’t have to worry about renumbering!

combine numbered and unordered lists:

  1. Numbered list 1
  2. Numbered list 2
    • Item 1
    • Item 2

Text Formatting

  • Make text italic like this or this.
  • Make text bold like this or this.
  • Use backticks for code.
  • Wrap a character to subscript in tildes (~). For example, H~2~O renders as H2O.
  • Wrap a character to superscript in carets (^), like this: R^2^ renders as R2.

Insert a new code chunk with:

Command + Option + I

Before running code chunks it is often a good idea to restart your R session and start with a clean environment. Do this with Command + Shift + F10

To save time, it’s worth learning these shortcuts to run code:

  • Run all chunks above the current chunk with Command + Option + P
  • Run the current chunk with Command + Option + C or Command + Shift + Enter
  • Run the next chunk with Command + Option + N
  • Run all chunks with Command + Option + R or Command + A + Enter

chunk options

  • echo = FALSE: Do not show code in the output, but run code and produce all outputs, plots, warnings and messages. The code chunk to generate a plot in the image below is an example of this.
  • eval = FALSE: Show code, but do not evaluate it.
  • fig.show = “hide”: Hide plots.
  • include = FALSE: Run code, but suppress all output. This is helpful for setup code. You can see an example of this in the top code chunk of the image below.
  • message = FALSE: Prevent packages from printing messages when they load. This also suppress messages generated by functions.
  • results = “hide”: Hides printed output.
  • warning = FALSE: Prevents packages and functions from displaying warnings.

Inline Code

The cars dataset contains 50 rows and 2 columns.

knitr::kable(head(cars), 
             caption = "The First Few Rows of the Cars Dataset")
The First Few Rows of the Cars Dataset
speed dist
4 2
4 10
7 4
7 22
8 16
9 10

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.