R Markdown (.Rmd
), like plain Markdown (.md
), is a markup language that allows one to generate formatted documents that can easily be converted to a structurally valid HTML file. However, R Markdown has some additional features which make it popular amongst data scientists and analysts. It is the perfect authoring framework for data science, as it allows us to perform the following tasks:
R Markdown is free and open source. We can install the rmarkdown
package using the following command in the R console:
install.packages("rmarkdown")
An R Markdown file uses the .Rmd
file extension. It can contain three types of content:
---
and contains the metadata of the document. For example, the title, author, tags, categories, and more. This is optional.```
. If these code chunks contain executable code, upon rendering, the output of the code is also displayed.Let's take a look at how the R Markdown file renders as an HTML:
--- title: "Hello R Markdown" author: "Educative" categories: ["R"] tags: ["R Markdown"] --- ```{r setup, include=FALSE} knitr::opts_chunk$set(collapse = TRUE) ``` # R Markdown This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. We can also write in-line code like this: `number <- 1` We can embed an executable R code chunk like this: ``` {r} x <- 3 + 3 print(x) ``` # Including Plots We can also embed plots. See Figure \@ref(fig:pie) for example: ```{r pie, fig.cap='A fancy pie chart.', tidy=FALSE} par(mar = c(0, 1, 0, 1)) pie( c(280, 60, 20), c('Sky', 'Sunny side of pyramid', 'Shady side of pyramid'), col = c('#0292D8', '#F7EA39', '#C4B632'), init.angle = -50, border = NA ) ``` Let's make a monthly active users plot! ```{r barplot, fig.cap='Active users chart', tidy=FALSE} barplot( c(35, 40, 25, 29, 10), main="Active users chart", names.arg=c("Jan", "Feb", "Mar", "Apr", "May"), xlab="Month", ylab="Active Users", col="#711A75" ) ```
---
markers.Free Resources