^^ YAML header

I did not know we had to share the document so if you’re reading this I’m sorry

R Markdown

What is R Markdown?

A document type used to write technical reports. It weaves in text (markdown) and chunks of code (R), which could then be exported in html, pdf, or word format. This way of report-writing increases reproducibility and flexibility.

Reproducility: Word vs Markdown

Word files (aka “raw file”) contains a lot of formatting files, which buries the text and makes the internal code “unreadable”. Conversely, markdown allows plain text writing in the raw file, making it human-readable, while simultaneously allowing formatting.

It can also be written in simple text editors like notepad.

In terms of utility, markdown can be used to make blogs, resumes, academic papers, etc.

Formatting

Text styles

Type this:

# * italics *
# ** bold **
# ** bold-italics ***

Ignore the apostrophes

for example:

  • Yan
  • Wu
  • Shi

Lists

  • hyphen
  • for
  • bullets
  1. numbers
  2. for
  3. numbers

Nested list

indent twice

  1. one
  2. two
  • two one
  • two two
    • two two one
  1. three

Headings

# one
## two
### three
#### four
##### five
###### six (max)

Inserting images

Local images

Upload local file into work space by clicking “more” on the file’s tab toolbar, then opening another files window where the picture is before dragging the image directly into the project file window.

Afterwards, type this:

# ![](file name)

In this example, I used the “more” button to open the “3361_dump” file in a file window before opening the “pictures” file in a separate window. I then dragged the desired picture (Zayne my bbg) into the 3361_dump file window. The picture file immediately loaded into the file tab within R studio without refreshing.

Gorgeous, innit?

Web images

Use the same command(?) as the local file, but replacing the file name with the link address of the image.

ZAYNE RAHHHHHHHHH

^ this is a “block quote”

Customising output

YAML

Output files and themes

Markdown formatting language. Output to different files with by changing name in output into ‘html_document: default’/ ‘pdf_document:default’. The most recent exported file type will be set on top in the output section.

You can delete ‘default’ and add ‘theme:…’ to apply different theme in output.

Possible themes: default, cerulean, journal, flatly, darkly, readable, spacelab, united, cosmon, lumen, paper, sandstone, simplex, yeti

E.g.,:

# title: "3051 dump Rmd"
# output: 
  # html_document:
    # theme: readable 
#date: "2024-05-21"

YAML is very strick on indents and spaces

  • +1 indent per sub item
  • no text after ‘:’ if there are sub items (e.g., html is a sub item of the output line)

Table of content

# title: "3051 dump Rmd"
# output: 
  # html_document:
      # toc: true
      # toc_float: true
      # theme: readable 
#date: "2024-05-21"

“toc_float: true” makes a dynamic table of contents that stays visible wherever you scroll. ‘False’ makes a static TOC at the top of the page.

NOTE: using toc_float in viewer panes makes the preview jittery.

Data

Type:

# $ = inline maaths
# $$ = standalone equation (e.g., $e=mc^2$)
  • Whitespace sensitive
  • Equations follow ‘LaTeX’ rules (pronounced as latte)

E.g.:

Inline: \(1+2=3\)

Standalone equation:

\[ a^2 + b^2 = c^2 \] Use symbol names preceded by ’  ’ with dollar signs to make symbols:

\[ \Psi + \delta + \alpha \] You can type superscript ( x^{} ) and subscript ( x_{} ); fraction is not an option by default, you will need to install the amsmath package for it

\[ MSB_{A} = SS_{A} \div df \]