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
Basically in R Markdonw # is used for headers
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
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
Hyperlinks can also be incoporated into your write ups. This is how it is done RMarkdown
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}\]
These are option on of different ways in which knitr shoud interpret your code on R markdown. They are as follows:
The above code will not run or interpreted or evaluated because eval = F(fasle)
echo (T or F): whether or not to show the code in the chunk, but it will interpret or run the code
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”.
fig.width or fig.height
out.width or out.height
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
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.
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.
This allow you to hide your code in the output. This is done by adding code-folding at the YAML