This is a tutorial on howt use R Markdonw for reproducible research.

Here we can type long passages or description of our data without the need of “harshing” out our comment with the # symbol.

In our our first example, we will be using the ToothGrowth dataset. In this experiment, Guinea pigs (literal) were given different amount (dose) of vitamin C to see the effect on teh animal’s tooth growht.

To Run an Ro code on Markdonw file, we need to denote the section that is considred R code, we call it “code chuncks”

Below is a code chunck

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

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

plot(len ~ dose, data = Toothdata)

abline(lm(len ~ dose, data = Toothdata))

The slope is the regression line 9.7635714

Section Headers

Basically in R Markdonw # is used for headers

For first lelvel header

For second level header

For third level header

Note: Put a space after the #tag

Similarly, bullet point-type can also be added to a r markdown file, as follows

  • one item

  • one item

  • one item

    • one more item
    • one more item
    • one more item
      • one last item
  1. First item
  2. Second item
  3. Third item
    1. First sub item
    2. Second sub item
    3. Third sub item

nlock quotes

This is done by using the “>” symbol for example

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

— Sam Kean

Formulars:

This is initiated using two dollar signs for example

\[p^2 + 2pq + q^2 = 1\] This can also get complex such as

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

Code Chunks

Code Chunk Options

These are option on of different ways in which knitr shoud interpret your code on R markdown. They are as follows:

  1. eval (T or F): Whether or not to interpret the chunk, but the it will show the code

The above code will not run or interpreted or evaluated because eval = F(fasle)

  1. echo (T or F): whether or not to show the code in the chunk, but it will interpret or run the code

  2. cache: If this is enabled, it will not run the code chunk the next time you knitr to run. This is useful when a particular code chunk has a LONG RUN TIME, so “you can just silence it”.

  3. fig.width or fig.height

  4. out.width or out.height

Table of Content

We can add table of contents to our HTML Document. We do this by altering the YAML code which is at the top left of this page

This will give nice floating table of content to the document

Tabs

We can add TAB to our report. To do this, we need to specify the section and we can only place it on first level headers such that lower header under that section will be come tabs.

Theme

We can add theme to our report. This is done at the YML code. Themes available are: cosmo, lumen, paper, simplex, sandstone, yeti, null, etc.

Code folding

This allow you to hide your code in the output. This is done by adding code-folding at the YAML