R Markdown Syntax Cheatsheet

R Markdown Cheat Sheet

Your one-stop reference for R Markdown syntaxβ€”covering inline code, code chunks, formatting rules, and more. Explore concise examples and see rendered outputs to help you combine R code and narrative seamlessly.

Rendered Output Style:

Quick Reference

Jump to any R Markdown syntax to get started quickly

Inline Elements

(12 items)

Block Elements

(9 items)

R Markdown Syntax

Essential R Markdown elements for creating dynamic documents that combine narrative text, code, and results. These features enable reproducible research and interactive reports.

Inline Elements

Plain Text

inline

Basic text content without any special formatting.

R Markdown Input

Plain text.

Rendered Output

Plain text.

πŸ’‘ Tips

  • No special syntax needed for regular text.
  • Forms the foundation of all Markdown documents.

Line Breaks

inline

Create line breaks using two spaces at the end of a line or a backslash.

R Markdown Input

End a line with two spaces to  
start a new paragraph.

Also end a line with a backslash\
to make a new line.

Rendered Output

End a line with two spaces to
start a new paragraph.

Also end a line with a backslash
to make a new line.

πŸ’‘ Tips

  • Two spaces at line end create a line break within the same paragraph.
  • Backslash at line end also creates a line break.
  • Empty line creates a new paragraph.

Text Emphasis

inline

Apply italic and bold formatting to text using asterisks.

R Markdown Input

*italics* and **bold**

Rendered Output

italics and bold

πŸ’‘ Tips

  • Single asterisks for italics: *text*
  • Double asterisks for bold: **text**
  • Can be combined: ***bold and italic***

Superscript and Subscript

inline

Create superscript and subscript text using caret and tilde symbols.

R Markdown Input

superscript^2^/subscript~2~

Rendered Output

superscript2/subscript2

πŸ’‘ Tips

  • Use ^text^ for superscript.
  • Use ~text~ for subscript.
  • Useful for mathematical expressions and chemical formulas.

Strikethrough

inline

Cross out text using double tildes.

R Markdown Input

~~strike through~~

Rendered Output

strike through

πŸ’‘ Tips

  • Use double tildes: ~~text~~
  • Useful for showing deleted or outdated content.

Escaped Characters

inline

Display special Markdown characters literally using backslashes.

R Markdown Input

escaped: \* \_ \\

Rendered Output

escaped: * _ \

πŸ’‘ Tips

  • Use backslash before special characters to display them literally.
  • Common escaped characters: \*, \_, \\, \#, \+

Dashes

inline

Create en-dash and em-dash using double and triple hyphens.

R Markdown Input

en dash: --, em dash: ---

Rendered Output

en dash: –, em dash: β€”

πŸ’‘ Tips

  • Double hyphen -- creates en-dash (–)
  • Triple hyphen --- creates em-dash (β€”)
  • En-dash for ranges, em-dash for breaks in thought.

Inline Code

inline

Display code inline using single backticks.

R Markdown Input

`verbatim code`

Rendered Output

verbatim code

πŸ’‘ Tips

  • Use single backticks for short code snippets.
  • Text inside backticks is displayed literally.
  • Useful for variable names, function names, etc.

Inline Math

inline

Insert mathematical expressions inline using single dollar signs.

R Markdown Input

equation: $e^{i \pi} + 1 = 0$

Rendered Output

equation: eipi+1=0e^{i \pi} + 1 = 0

πŸ’‘ Tips

  • Use single $ for inline math: $equation$
  • LaTeX syntax supported for mathematical notation.
  • Requires MathJax or similar math renderer.

Block Elements

Headers

block

Create headers of different levels using hash symbols.

R Markdown Input

# Header 1
## Header 2
...
###### Header 6

Rendered Output

Header 1

Header 2

...
Header 6

πŸ’‘ Tips

  • Number of # symbols determines header level.
  • Space required after # symbols.
  • Headers automatically create anchor links in HTML output.

Unordered Lists

block

Create bullet point lists using hyphens, with support for nesting.

R Markdown Input

- unordered list
- item 2
    - item 2a (indent 1 tab)
    - item 2b

Rendered Output

  • unordered list
  • item 2
    • item 2a (indent 1 tab)
    • item 2b

πŸ’‘ Tips

  • Use - (hyphen) for list items.
  • Indent with tab or 4 spaces for nesting.
  • Can also use + or * instead of -.

Ordered Lists

block

Create numbered lists, with support for mixing with unordered lists.

R Markdown Input

1. ordered list
2. item 2
  - item 2a (indent 1 tab)
  - item 2b

Rendered Output

  1. ordered list
  2. item 2
    • item 2a (indent 1 tab)
    • item 2b

πŸ’‘ Tips

  • Use numbers followed by period: 1., 2., etc.
  • Can mix ordered and unordered lists through nesting.
  • Actual numbers don't matter - Markdown auto-numbers.

Images

block

Insert images using exclamation mark followed by link syntax.

R Markdown Input

![Caption](https://github.githubassets.com/assets/GitHub-Logo-ee398b662d42.png)

or

![Caption](id2)

At the end of the document include:
[id2]: https://github.githubassets.com/assets/GitHub-Logo-ee398b662d42.png

Rendered Output

Caption

πŸ’‘ Tips

  • Format: ![alt text](image path)
  • Alt text important for accessibility.
  • Can use reference style like links.
  • Supports relative and absolute paths.

Code Blocks

block

Display multiple lines of code using triple backticks.

R Markdown Input

```
multiple lines
of verbatim code
```

Rendered Output

multiple lines
of verbatim code

πŸ’‘ Tips

  • Use triple backticks for multi-line code.
  • Can specify language for syntax highlighting: ```r
  • All text inside is displayed literally.

Block Quotes

block

Create indented quote blocks using greater-than symbol.

R Markdown Input

> block quotes

Rendered Output

block quotes

πŸ’‘ Tips

  • Use > at beginning of line for quotes.
  • Can be nested with multiple > symbols.
  • Often styled with different background or border.

Math Blocks

block

Create standalone mathematical equations using double dollar signs.

R Markdown Input

equation block:
$$E = mc^{2}$$

Rendered Output

equation block:

E=mc2E = mc^{2}

πŸ’‘ Tips

  • Use double $$ for block math equations.
  • Equations are centered and displayed prominently.
  • Supports complex LaTeX mathematical expressions.

Horizontal Rule

block

Create horizontal dividing lines using three hyphens.

R Markdown Input

horizontal rule:
---

Rendered Output

horizontal rule:


πŸ’‘ Tips

  • Use three or more hyphens on their own line.
  • Creates visual separation between sections.
  • Can also use *** or ___

Tables

block

Create formatted tables using pipes and hyphens for alignment.

R Markdown Input

|Right|Left|Default|Center|
|----:|:---|-------|:----:|
|12   |12  |12     |12    |
|123  |123 |123    |123   |
|1    |1   |1      |1     |

Table: Caption text, example rendered table

Rendered Output

Caption text, example rendered table
Right Left Default Center
12 12 12 12
123 123 123 123
1 1 1 1

πŸ’‘ Tips

  • Use | to separate columns.
  • Alignment: :-- (left), --: (right), :--: (center), --- (default)
  • Add Table: caption below table for table caption.
  • Header row separated by alignment row.

Explore More Cheatsheets

Discover other Markdown guides for different platforms and use cases

50+ Examples

Markdown Cheatsheet

Complete guide to standard Markdown syntax with examples and live previews

Explore Guide
25+ Formats

Discord Markdown

Discord-specific markdown formatting for chat and embeds

Explore Guide