title | author | date | output | subtitle | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Rmarkdown introduction |
Antoine K.D. Abalo |
2024-02-12 |
|
Epihubben Journal Club |
- Lightweight markup language for creating formatted text using a plain-text editor
- Created by John Gruber and Aaron Swartz in 2004
- Aim: Ease plain text conversion into rich text format, without any heavy codes
- Package developped by Yihui Xie to integrated Markdown langage into R (around 2012 - 2014)
- Aim: Facilitate reproducible research, allowing codes sharing with textual documentation on different form (LaTeX, HTML, Markdown, etc.) and for dynamic report generation with R.
- Yihui Xie: Author of Knitr, blogdown, bookdown etc.
-
R Markdown family of packages enables creating beautiful data science products like:
- books, blogs, websites, and presentations etc.
-
Aim: help you publish polished websites for sharing your work. E.g.:
- Present analyses or visualizations with R code (Ex. My tutorial),
- Slides (like this one you are seing),
- R package (My package),
- Personal-professional websites, etc.
When you run render, R Markdown feeds the .Rmd file to knitr, which executes all of the code chunks and creates a new markdown (.md) document which includes the code and its output.
The markdown file generated by knitr is then processed by pandoc which is responsible for creating the finished format.
- You can insert chunks:
- keyboard shortcut Ctrl + Alt + I (OS X: Cmd + Option + I)
- Command in the editor toolbar
- Typing the chunk delimiters
{r} and
.
- R Markdown run each code chunk and embed the results beneath the code chunk in your final report.
NB: Chunk options for personnalised code output
# This is an example
a <- c(1,2,3,4)
cat("The output of a =", a)
## The output of a = 1 2 3 4
plot(pressure)
age_group | Number_events | Pers_years |
---|---|---|
35-39 | 0 | 480 |
40-44 | 1 | 587 |
45-49 | 3 | 680 |
50-54 | 5 | 541 |
55-59 | 8 | 479 |
60-64 | 8 | 356 |
65-69 | 4 | 157 |
70-74 | 1 | 36 |
R Markdown documents are a perfect platform for interactive content. To make your documents interactive, add:
- Interactive JavaScript visualizations based on htmlwidgets, or
- Reactive components made with Shiny (upcoming coding clubs)
Scientific articles
- If you don't have R and Rstudio installed, you can create a free account on R Studio Cloud and start using R.