This is a practice on how to use R markdown for reproducible research.

We are going to use ToothGrowth dataset.

Below is a code chunk:

Toothdata <- ToothGrowth

head(Toothdata)
##    len supp dose
## 1  4.2   VC  0.5
## 2 11.5   VC  0.5
## 3  7.3   VC  0.5
## 4  5.8   VC  0.5
## 5  6.4   VC  0.5
## 6 10.0   VC  0.5

As you can see, from the running the ‘play’ button on the code.

fit <- lm(len ~ dose, data = Toothdata)

b <- fit$coefficients

plot(len ~ dose, data = Toothdata)

abline(lm(lm(len ~ dose, data = Toothdata)))
Figure 1: The tooth growth

Figure 1: The tooth growth

This slop of the regression line is 9.7635714.

Section Headers

We can also put sections and subsections in out r markdown file, similar to numbers or buller points in a word document.

First level header

Second level header

Third level header

Make sure to put space after #, otherwise it will not work.

We can also add bullet points in the file.

  • one item
  • one item
  • one more item
    • one more item
      • one more indentation Here indentation matters!!!

Numbering

  1. First item
  2. Second item
  3. Third item
    • sub item 1
    • sub item 2

Block Quotes

We can really put nice quotes into the markdown doc by using ‘>’ symbol.

“Genes are like the story, and DNA is the language that the story is written in.”

— Sam Kean

Formulas

We can also put nice formatted formulas into markdown

Hard-Weinberg Formula

\[p^2 + 2pq + q^2 = 1\]

It can be really complex like

\[\Theta = \begin{pmatrix}\alpha & \beta\\ \gamma & \delta \end{pmatrix}\]

Code chunks

Code chunk option

print("Hello world")
## [1] "Neko says meaww..."

Let’s talk about knitr, it interpretes the code chunk. There are the following options.

Eval (T or F): whether or not to evaluate the r code chunk.

Echo (T or F): whether or not to show the code for the chunk, but results will still print.

Cache: If enable, the same code chunk will not be evaluated the next time that the knitr is running.

fig.width or fig.height: The graphical device that represent the size of the plots in inches. The figure are first written to the knitr doc then to files that are saved separately.

out.width or out.height: The output size of the R plots in the R doc.

fig.cap: The words for the figure caption.

Table of contents

We can also add a table of contents to our HTML doc.

Tabs

You can also add TABS in our report. To do this you need to specify each section that you want to give a tab by placing “{.tabset}” after the line.

Themes

We can always use different themes to change the HTML doc. Themes like: cerulean journal flatly readable spacelab united cosmo lumen paper sandstone simplex yeti null

We can also change color by specifying highlights: default tango payments kate monochrome espresso zenburn haddock textmate

Choose any one of them either theme or highlights.

Code folding

You can also use the code_folding option like this: code_folding: hide

Summary

There are a TON of options in R markdown