Creating an R Markdown file

Each R markddown file contains three types of text:

YAML header

  • title: “….”
  • author: “….”
  • date: “….”
  • output: html_document/pdf_document/word_document

Plain text

formating is done using marks
# Header
## Header 2

bold with double-asterisks
italics with underscores
code-type font with backticks

Chunk options

write in the bracketes after letter “r” or as general statment e.g. knitr::opts_chunk$set(echo = TRUE) on the beginning

  • include = FALSE prevents code and results from appearing in the finished file. R Markdown still runs the code in the chunk, and the results can be used by other chunks.
  • echo = FALSE prevents code, but not the results from appearing in the finished file. This is a useful way to embed figures.
  • message = FALSE prevents messages that are generated by code from appearing in the finished file.
  • warning = FALSE prevents warnings that are generated by code from appearing in the finished.
  • fig.cap = “…” adds a caption to graphical results.
  • fig.height, fig.width
  • results = “markpup” or “asis” or “hide” or “hold”

Inside chunk

Sometimes is good to have formated text also inside the chunks e.g. when you create the figures or data analysis by loop

  • cat start for header
  • knitr::kable() formated table

Printing the table

ID strain sex group cohort
064-EPL19 2510009E07Rik (indel) Male Male KO_E07Rik c007
064-EPL20 2510009E07Rik (indel) Male Male KO_E07Rik c007
064-EPL40 2510009E07Rik (indel) Male Male KO_E07Rik c007
064-EPL69 2510009E07Rik (indel) Male Male KO_E07Rik c007
064-EPL75 2510009E07Rik (indel) Male Male KO_E07Rik c007

Plotting the data and save them

Tasks

  1. Write a sentence containing words with bold, italics, and underlined formatting.
  2. Create a plot generated with 3 inches wide and 5 inches high
  3. test different Chunk options for final document