Introduction to RMarkdown

Xiaorui(Jeremy) Zhu

01/08/2026

Life is short!

Don’t you want to save a little bit of time for your hobbies?

You may have these headaches:

You may have these headaches:

\(\color{red}{\text{If these questions ever bother you at least once, then you need to ...}}\)

Let RMarkdown do the trick!

Markdown/RMarkdown

How to use R Markdown file in RStudio

The most recent version of R-studio has added the “R Markdown” file type as default. You can create an “R Markdown” file.

Markdown Syntax: Simplest way of writing

# Say Hello to **Data Mining** in Markdown

* [Data Mining in R on Github](https://xiaoruizhu.github.io/Data-Mining-R/)
* [Markdown Syntax](https://daringfireball.net/projects/markdown/basics)
* [StackOverflow](www.stackoverflow.com)
* [Reddit](www.reddit.com)

## R Markdown is a special type of Markdown in R


## Here are some codes

5 + 10
mean(income)
# Need to be surrounded by code chunck (```{r}...```), will give example 

How to communicate with codes? Use “knitr”

  1. knitr is an R package that extends the markdown syntax.
  2. One of the most important functions of knitr is to include executable R code.
  3. Then, with the codes inside the paragraph, the technical report will be more readable than that not including codes.
  4. With knitr, the results of executed codes can be automatically included in the output report, which is a great feature.
  5. This feature makes your analyses “reproducible”.
  6. In this way, you can easily change your codes. Then, when you knit, the the results in your output report will be updated with your new codes.

How to communicate with codes? Use “knitr”

Here’s some code

dim(iris)
## [1] 150   5

Here’s a plot

hist(iris[[2]])

More settings of the output of code chunks can be found rmarkdown and knitr websites.

Inline code

To include some calculation by R code in a line, one can surround the codes as follows:

Two plus two equals 4. (Use a pair of backticks and the letter r like this: \(\color{red}{\text{` r 2+2 `}}\))

Beauty of it: From RMarkdown file to HTML/pdf/Word

go to top