Skip to content

Latest commit

 

History

History
172 lines (121 loc) · 6.4 KB

_Epihubben_Journal_Club_Rmarkdown.md

File metadata and controls

172 lines (121 loc) · 6.4 KB
title author date output subtitle
Rmarkdown introduction
Antoine K.D. Abalo
2024-02-12
ioslides_presentation slidy_presentation beamer_presentation
keep_md
true
default
default
Epihubben Journal Club

Markdown

  • 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

R Markdown

  • 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 - Fonctionalities

  • 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.

Overview: Start using Rmarkdown

Overview panels Overview panels

The magic behind

Overview panels

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.

Codes chunks

Overview panels

Inline coding

  • 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

Tables - Figures

plot(pressure)

Tables - Figures

Example of embended table
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

Interactive Documents

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)

Interactive table

Scientific articles

Additional resources

The reference guide

The Rmarkdown cheatsheet

Let's put this into practice

  • If you don't have R and Rstudio installed, you can create a free account on R Studio Cloud and start using R.