Open In App

Introduction to R Markdown

In this article, we will explore the concepts of Markdown in R Programming Language.

We will cover the following topics:

Introduction to R Markdown

Markdown is a lightweight markup language and created by John Gruber in 2004. Nowadays markdown is one of the world’s most popular markup languages. The file extension of a Markdown file is .md or .markdown. To compile a markdown file user needs an application capable of processing markdown files like Microsoft Word, Dillinger, etc. These applications utilize a Markdown parser which converts a markdown file to printable HTML code. 



Advantages Of Markdown

What is R Markdown?

R Markdown is a way of generating fully reproducible documents, in which both text and code can be combined. That’s how things can be made as bullets, bold, italics, links, or run inline R codes. Despite these documents all starting as plain text, one can render them into HTML pages, or PDFs, or Word documents, or slides! The symbols that use to signal, for example, bold or italics is compatible with all of those formats. 

Why use R Markdown?

Getting started with R Markdown

To create an R Markdown document, in R Studio, go to File > New File > R Markdown. The following window will appear: 



As one can see, the above image is filled in a title and an author and switched the output format to a PDF. Explore around this window and the tabs along the left to see all the different formats that it can output to. When this is completed, click OK, and a new window should open with a little explanation on R Markdown files. 

There are three important sections of an R Markdown document. 

Knitting the document

When the user is done with a document, in R Markdown, then one has to “knit” his plain text and code into his final document. To do so, click on the Knit button which is present on the top of the source panel. When one does so, it will prompt him to save the document as an RMD file. Do so. A document like this can be seen: 

So here one can see that the content of the header was rendered into a title, followed by his/her name and the date. The text chunks produced a section header called “R Markdown” which is followed by two paragraphs of text. Following this, one can see the R code summary(cars), importantly, followed by the output of running that code. This is one of the huge benefits of R Markdown that is rendering the results to code inline.

Article Tags :