Posted on by & filed under Content - Highlights and Reviews, Programming & Development.

code A guest post by Tom Barker, a software engineer, an engineering manager, a professor and an author. Currently he is Director of Software Engineering and Development at Comcast, and an Adjunct Professor at Philadelphia University. He has authored Pro JavaScript Performance: Monitoring and Visualization, Pro Data Visualization with R and JavaScript, and Technical Management: A Primer, and can be reached at @tomjbarker.

In my previous posts I’ve spoken at length about using the R console, but there is another way to develop R scripts. If you prefer to develop in an IDE instead of at the command line, there is a free product called RStudio IDE available. The RStudio IDE is made by the RStudio company, and is much more than just an IDE as we will soon see. RStudio, the company, was founded by JJ Allaire, the creator of ColdFusion. RStudio IDE is available for download at – see below for a screen shot of the download page.


After installation, the IDE looks like below, and is essentially split into four panes.


The upper left pane is our R script file where we edit the R source code. The bottom left pane is the R command line. The upper right side pane holds the command history as well as all of the objects in the current workspace. The bottom right pane is split into tabs that can show:

  • The contents of the file system for the current working directory
  • Plots or charts that we have generated
  • Current packages installed
  • R help pages

This is great to have everything that you need in one place, but now here is where it gets really interesting.

R Mark Down

In version 0.96 of RStudio the team announced support for R Markdown using the knitr package. What this means is that you can essentially embed R code into markdown documents that can get interpreted into HTML. It gets even better.

RStudio, the company, also makes a product called RPubs that allows you to create accounts and host your R markdown files for distribution over the web.

Note that markdown is a plain text markup language, created by Philadelphia native John Gruber and the late Aaron Swartz. In markdown you can use simple and lightweight text encodings to signify formatting. The markdown document is read and interpreted and an HTML file is output.

A quick overview of markdown syntax:

The great thing about R Markdown is that you can embed R code within your markdown document. You embed R using three tick marks and the letter r in curly braces:

OK, let’s see how we do this. We need three things to begin creating R Markdown (.rmd) documents:

  • R
  • R Studio IDE version 0.96 or higher
  • The knitr package

The knitr package is used to reformat R into several different output formats, including HTML, markdown, or even plain text. Information about the knitr package is available here

Since we already have R and RStudio IDE installed, we will first install knitr. R Studio IDE has a nice interface to install packages. Simply go to the Tools file menu and click on Install Packages. You should get the pop up that you see below where you can specify the package name (R Studio IDE has a nice type ahead here for package discovery), and what library to install to.


Once knitr is installed you need to close and relaunch RStudio IDE. Then go to the file menu and choose File -> New… and you should see a number of options here, including R Markdown. If you choose R Markdown, you get a new file with the following template:


The R Markdown template has the following code:

This is the template, and when you click the Knit HTML button you see the following output.


Notice the Publish button at the top of the above screen shot? That is how you push your R Markdown file to RPubs for hosting and distribution over the Web.


RPubs is a free web-publishing platform for R Markdown files, provided by RStudio (the company). You can create a free account by visiting See below for a screen shot of the RPubs homepage:


Just click on the Register button and fill out the form to create your free account. RPubs is fantastic; it’s a platform where you can post your R Markdown documents for distribution. Just be aware that every file you put up on RPubs is publicly available; so be sure not to put any sensitive or proprietary information up on it.

OK, back to the R Markdown document in RStudio IDE. Once you click the publish button you will be prompted to login with your RPubs account. After logging in you will be directed to the document details page, as you can see below.


After filling out the document details, a title for your document, along with a description, you will be directed to your document hosted in RPubs.


This is a powerful distribution method for R documents, and allows you to communicate your data visualizations over the Web.

For more details about R, see the resources below from Safari Books Online.

Not a subscriber? Sign up for a free trial.

Safari Books Online has the content you need

The Art of R Programming is both broad in its coverage of various language constructs and data structures, and deep and co mprehensive in explaining them. It provides working examples, and iluminates the R philosophy: a clean functional language with strong vector operation support, and a “do more with less typing” foundation that can make programs an order of magnitude smaller and expressive.
Pro Data Visualization using R and JavaScript by Tom Barker, makes the R language approachable, and promotes the idea of data gathering and analysis. You’ll see how to use R to interrogate and analyze your data, and then use the D3 JavaScript library to format and display that data in an elegant, informative, and interactive way. You will learn how to gather data effectively, and also how to understand the philosophy and implementation of each type of chart, so as to be able to represent the results visually.
Pro JavaScript Performance: Monitoring and Visualization by Tom Barker, gives you the tools to observe and track the performance of your web applications over time from multiple perspectives, so that you are always aware of, and can fix, all aspects of your performance.
Learning R will help you learn how to perform data analysis with the R language and software environment, even if you have little or no programming experience. With the tutorials in this hands-on guide, you’ll learn how to use the essential R tools you need to know to analyze data, including data types and programming concepts.

Tags: R Markdown, R Scripts, RPubs, RStudio,

Comments are closed.