R Markdown

The Johns Hopkins Data Science Lab

Introduction

R Markdown is built into RStudio and allows you to create documents like HTML, PDF, and Word documents from R. With R Markdown, you can embed R code into your documents.

Why use R Markdown?

Getting Started

Getting Started

The beginning of an R Markdown file looks like this:

---
title: "Air Quality"
author: "JHU"
date: "06, Septembre 2024"
output: html_document
---

The new document you’ve created will contain example text and code below this – delete it for a fresh start.

Making Your First Slide

Adding Text

Formatting Text

Text Code in R Markdown
plain text plain text
italics *italics*
bold **bold**
link [link](http://www.jhsph.edu)
verbatim code code here

Embedding R Code

This is a chunk of R code in R Markdown:

```{r}
head(airquality)
```
The code gets run, and both the input and output are displayed.

head(airquality)
##   Ozone Solar.R Wind Temp Month Day
## 1    41     190  7.4   67     5   1
## 2    36     118  8.0   72     5   2
## 3    12     149 12.6   74     5   3
## 4    18     313 11.5   62     5   4
## 5    NA      NA 14.3   56     5   5
## 6    28      NA 14.9   66     5   6

Embedding R Code

To hide the input code, use echo=FALSE.

```{r, echo=FALSE}
head(airquality)
```

##   Ozone Solar.R Wind Temp Month Day
## 1    41     190  7.4   67     5   1
## 2    36     118  8.0   72     5   2
## 3    12     149 12.6   74     5   3
## 4    18     313 11.5   62     5   4
## 5    NA      NA 14.3   56     5   5
## 6    28      NA 14.9   66     5   6

This can be useful for showing plots.

Embedding R Code

To show the input code only, use eval=FALSE.

```{r, eval=FALSE}
head(airquality)
```

head(airquality)

Embedding R Code

To run the code without showing input or output, use include=FALSE.

```{r, include=FALSE}
library(ggplot2)
```

Generating Slideshows

Generating Slideshows

PDFs and LaTeX

Downloading and Installing LaTeX

Conclusion

For more information about R Markdown visit http://rmarkdown.rstudio.com/