R Markdown enables you to generate reproducible and dynamic reports straight from your R code, documenting your works as an HTML, PDF, Word, slideshows, and more.
We will use knitrand rmarkdown packages to write R Markdown files in Rstudio and generate report in various formats.

Let’s create a report on analysis of ‘basic salary’ data.

#Install R Packages
install.packages("knitr")
install.packages("rmarkdown")

Open .Rmd File:


.Rmd Structure:


Write Document:

Few of the output formats available to use with R Markdown are as follows:

Arguments can be added to each code chunk, which allow you to customize how or if you want code to be processed or appear on the rendered output (pdf document, html document, etc).
Here we have specified echo=TRUE to display the code along with the results.
Comments can be added using ‘#’ followed by the text.

R Code Chunk Arguments:


Generate Report:


Output as an HTML Document:


Output as a Word Document: