Chapter 2 Lab 1: Introduction to Electronic Lab Notebooks

Objectives:

  1. To create electronic notebooks for the 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 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.

2.1 Why electronic notebooks?

Reproducibility is a core value of quantitative biology: another scientist (or you, six months from now) should be able to open your notebook, run it, and get the exact same results. An electronic notebook that mixes your written explanations, your code, and your code’s output in one document is one of the easiest ways to guarantee that.

We will call these documents Electronic Lab Notebooks (ELNs). Your ELNs will record what you did in lab, save your results and commands, and document where your data files live. Every lab practicum in this course must be submitted as a knitted R Markdown document.


2.2 Basics of Markdown

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

2.2.1 Basic syntax

In Markdown, text that is not specially formatted displays in plain font. If you surround words with certain symbols, they change appearance:

  • **bold** becomes bold
  • *italics* becomes italics

If you want to add a header or subtitle, start a line with #. One # is a main header, two ## is a subtitle, and so on.

2.2.2 Lines and blocks of code

Markdown allows you to display unformatted lines of code. To create in-line code, surround it with a single backtick `.

2.2.2.1 Example of inline code:

Similarity searches were done using blastn with default parameters.

2.2.2.2 Example of code blocks:

To create a code block, start a region with three backticks, add your code, then close with three more backticks:

This is a code block
some_command --flag value

2.2.3 Lists

Unordered lists start each item with a -:

- Bananas
- Pijamas
- Bandanas
  • Bananas
  • Pijamas
  • Bandanas

Ordered lists use a number and a period. Numbers don’t have to be consecutive in the raw text — Markdown renumbers them automatically:

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

Nested lists are created with 4 spaces of indentation:

1. This week:
    - Homework
    - Breakfast
2. This weekend
    - Nothing
  1. This week:
    • Homework
    • Breakfast
  2. This weekend
    • Nothing

2.2.4 Horizontal rules

Three * in a row on an empty line creates a horizontal rule:

***

2.3 Executable code chunks

Executable Code Chunks

Executable code chunks are sections in your R Markdown file that allow you to execute or run code. That means you can read datasets, create tables, and plot figures directly inside the notebook.

Executable code chunks look like this:

```{coding language goes here}
code goes here
```

We can use bash, R, and even python (with the right packages installed) inside an R Markdown document.

An example using bash to get the current date:

```{bash}
date
```
## Thu Sep  3 09:04:55 EDT 2026

And an example using R:

```{r}
2 + 2
```
## [1] 4

Question 1

  • Create a new R Markdown document in RStudio (File -> New File -> R Markdown) and save it as Lab1_YourName.Rmd
  • Add a level-1 header with your name, a level-2 header called “Lab 1”
  • Write two sentences about yourself using at least one bold word and one italic word
  • Add an unordered list with three of your hobbies
  • Add one R code chunk that prints the result of 5 * 7
  • Knit the document to HTML and confirm it renders without errors. Add a screenshot or describe what you see.

Question 2

  • Why does reproducibility matter in science? Give one example (real or hypothetical) of a problem that could arise if a colleague could not reproduce your analysis.
  • What is the difference between writing code in the R console versus writing it inside a code chunk in an R Markdown notebook?