Markdown is

plain text.

(where formatting is indicated but not immediately shown/rendered).

For example, this in Markdown:


# Section

*my text*


Becomes this when rendered:


Section

my text

What you see is not what you get. What you mean is what you get.

This is very powerful because plain text (“Markdown”) can become:

  • PDF
  • Word
  • HTML (which can be interactive)
  • presentation

with a push of a button.

What you see is not what you get. What you mean is what you get.

This is very powerful because plain text (“Markdown”) can become:

  • PDF
  • Word
  • HTML (which can be interactive)
  • presentation

with a push of a button. + make it even more powerful by adding R

Three components: header*, markdown, R code chunks

The header is called YAML

---
title: "Example knitr/R Markdown document"
author: "Your name"
date: "22/5/2020"
output:
word_document: default
---

Markdown quirks

  • a single Enter/new line does not render to a line break
  • 2+ empty lines always renders to a single empty line
  • learn to love backticks and curly braces: ``` {}

R Markdown quirks

  • If you execute code chunks separately, objects appear and use the current Environment
  • If you knit the whole .Rmd file, it starts fresh, and does not see other things you might have loaded

Knit document

Top cog (document settings)

Open the Document Options (“document cog”):

For example, for adding automated numbering:

Chunk cog (chunk settings)

Change chunk options (“chunk cog”):

In addition to changing the figure size, this is where we control whether we want code/messages/errors to be included in the final document, or just results.

Default code/warnings handling options for all chunks can be set using the set-up chunk:

Markdown vs Notebooks

It’s the exact same file format. The difference is how YOU work with it.

Demonstration and materials

R Markdown powers

  • documents
  • presentations
  • websites (blogdown)
  • Shiny apps (runtime: shiny)
  • books (bookdown)