A Quick R Markdown Tutorial
1 Introduction:
1.1 What is Markdown and R markdown?
Markdown (John Gruber, https://daringfireball.net/projects/markdown) is a different way to write documents that include computer code. … R markdown is a particular kind of markdown document. — Paul Johnson (“R Markdown Basics”)
1.2 How can I use R markdown?
R Studio :
Pro:
- Free
- Inline code
- Supports R, Python, SQL, C++, etc
- Standalone enviroment (sort of)
Anaconda :
Pro:
- Free
- Inline code
- Mainly for Python but also supports R
- Needs a web browser
R Studio is the preferred one because I personally can’t study when my web browser remains open 😅
1.3 What’s the relationship between R and R Studio ?
R Studio is a masking software of R, which means R is a necessary software for R Studio
2 Preparation:
2.1 Step 1, Of course, you need to install R and R Studio first:
R (free and comes with ABSOLUTELY NO WARRANTY): https://cran.r-project.org/mirrors.html
R Studio (free version is good enough for now): https://www.rstudio.com/products/rstudio/download/
2.2 Step 2, Copy and paste the code below to download the rmarkdown package in R Studio console (one time):
install.packages("rmarkdown")
Or just simply do step 3, where R Studio will automatically download it for you, but you still can use this code above in your console to show off a bit
2.3 Step 3, creating a new R Markdown file:
2.4 Step 4, output options:
PDF and Word output require extension software support. For instance, PDF output requaires you to have $\LaTeX$ installed and Word output requires Microsoft Word installed
You can either install the full $\LaTeX$ application (Mac user: MacTeX; Windows user: MiKTeX) or simply use the command below to download a light version of $\LaTeX$:
install.packages("tinytex")
tinytex::install_tinytex()
3 R Markdown Screenshot:
4 Useful code:
Header:
# Header 1
## Header 2
### Header 3
#### Header 4
##### Header 5
###### Header 6
Header 1
Header 2
Header 3
Header 4
Header 5
Header 6
bold and italics:
This is *Rmarkdown*!
This is _Rmarkdown_!
This is **Rmarkdown**!
This is **_R_ markdown**!
This is *R~~markdown~~*!
This is Rmarkdown!
This is Rmarkdown!
This is Rmarkdown!
This is R markdown!
This is Rmarkdown!
List:
* unordered list
* item 2
+ sub-item 1
+ sub-item 2
1. ordered list
2. item 2
+ sub-item 1
+ sub-item 2
- unordered list
- item 2
- sub-item 1
- sub-item 2
- ordered list
- item 2
- sub-item 1
- sub-item 2
$\LaTeX$:
\begin{equation}
e^{ix} = \cos x + i \sin x
\end{equation}
$$\begin{equation}
e^{ix} = \cos x + i \sin x
\end{equation}$$
Inline $\LaTeX$:
$\LaTeX$ is too easy for me!
$\LaTeX$ is too easy for me!
R code:
t <- "This class is my favourite course!!!"
print(t)
## [1] "This class is my favourite course!!!"
5 Generating a report:
Of course, you can always change the type of the output format later
References and hyperlinks:
1. [R Markdown Cheat Sheet](https://www.rstudio.com/wp-content/uploads/2015/02/rmarkdown-cheatsheet.pdf)
2. [R Markdown Reference Guide](https://www.rstudio.com/wp-content/uploads/2015/03/rmarkdown-reference.pdf)
3. [R Studio ![](images/rstudio_logo.png){width=25px}: R Markdown Quick Tour](https://rmarkdown.rstudio.com/authoring_quick_tour.html)
4. [R Markdown: The Definitive Guide, by _Yihui Xie, J. J. Allaire, Garrett Grolemund_](https://bookdown.org/yihui/rmarkdown/)
5. [R Markdown Basics, by _Paul Johnson _](https://cran.r-project.org/web/packages/stationery/vignettes/Rmarkdown.pdf)
6. [Homepage of the author with numerous important R packages like _knitr_, Yihui Xie](https://yihui.name)