Chapter 5 Introduction to electronic notebooks in R Markdown

Objectives:

  1. To create electronic notebooks for course
  2. To familiarize ourselves with the use of R markdown and its features
  3. To create our initial R markdown document
  4. To understand the importance of replicable and reproducible notebooks

The electronic lab notebooks we will use will in class will be created as R Markdown documents.

Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.

5.1 Markdown formats

As mentioned above, Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents.

We will use R Markdown as it will allow us to create documents that we can modify in different computers (as long as we have R and R Studio).

We will call these documents Electronic Lab Notebooks (ELS). These ELS’ will be used to write down what you have done in class, save the results and the commands and also will tell us where the files you are using will be at.

But, before we go into the super complex part of it, lets learn the basics of R markdown.


5.2 Basics of Markdown

So, the idea to use the R markdown file as a E-notebook we need to understand what the syntax is.

Syntax: a set of rules for or an analysis of the syntax of a language

5.2.1 Basic syntax

In the case of markdown, all the text that is not formatted in any way will be displayed in the most basic font.

So you’ll see that all of these sentences are in simple format.

In addition, if you surround words with certain elements, it can become a word in bold or in italics.

In this case, when I add a ** before and after the word I want to highlight, the word becomes a bold word. When I add a ** before and after the word I want to highlight, the word becomes a word in italics.

If you want to add a header, or a subtitle, start a sentence with #. One # means main header, two will be a subtitle, and so on.

5.2.2 Lines of code

Markdown allows you to create unformatted lines, or lines of code. In these lines you can add the code you are using for certain steps, or to illustrate examples.

To create a code in-line, just add a `(backtick) between the line of code

5.2.2.1 Example of inline code:

Similarity searches were done using blastn with default parameters and an expected E-value of 10-5.

5.2.2.2 Example of code blocks:

To create a code block, start a region with three `(backticks). Add the code in the line after the backticks and then close with three additional backticks.

This is a code-block
blastp -query q

5.2.3 Lists

You can create unordered or ordered lists in Markdown. To create unordered lists in markdown, start each element of the list with a - sign:

Code:

- Bananas
- Pijamas
- Bandanas

Result:

  • Bananas
  • Pijamas
  • Bandanas

To create ordered lists, add a number with a period before each element. The numbers don’t have to be consecutive, which will allow Markdown to modify the list no problem (Check the raw code before you run the Knitr command):

Code:

1. Wake up
1. Make the bed
1. Lie down again

Result:

  1. Wake up
  2. Make the bed
  3. Lie down again

You can also make nested lists! Nested lists can are done by creating list using 4 spaces:

Code:

1. This week:
    - Homework
    - Breakfast
    - Cats litter
2. This weekend
    - Nothing

Result:

  1. This week:
    • Homework
    • Breakfast
    • Cats litter
  2. This weekend
    • Nothing

5.2.4 Horizontal rules

If you want to separate sections by a horizontal rule, use three * in a row in an empty line:

***

5.2.6 Tables

Finally, lets learn how to add tables.

Tables in markdown can be annoying, but gladly there are online elements that will help us with tables.

However, lets start basic. A table can be created by having list of words and separating them with hyphens - (for the first row), and then separating each column with a pipe |:

Header One Header Two
Cell [1,1] Cell [1,2]
Cell [2,1] Cell [2,2]

So, you can imagine that creating a gigantic table is a mess. Imagine creating the table from the syllabus into Markdown?

Do not worry, use this amazing page to copy and paste any Excel/CSV/Table and turn it into Markdown!

Just copy and paste it from the page:

Week Lecture
1 Introduction to Quantitative Biology (Dresch and Tabima)
2 Biological Datasets and creating electronic notebooks (Tabima)
3 Introduction to the UNIX command line (Tabima)
4 Data management in the command line (Tabima)
5 Extracting patterns and data using UNIX (Tabima)
6 Introduction to scripting in UNIX (Tabima)
7 Creating pipelines for basic data analysis in UNIX (Tabima)
8 Introduction to Matlab (Dresch)
9 m files and functions (Dresch)
10 Inputting/Exporting Data (Dresch)
11 Data Visualization (Dresch)
12 Simple Statistics (Dresch)
13 Data Fitting (Dresch)
14 Group Project time
15 Final submission Group Project

5.3 R Markdown Excerise:

Create a Markdown page that describes yourself in a simple manner. Use as many element of syntax as possible, like bold text, italics, lists, tables and even add a picture of yourself. You can make it a very simple resume, a simple CV or just a small paragraph of you and your likes.