Learn to Post at RPubs
Posted on November 29, 2014
Rpubs is a great place to post markdown files created using RStudio and knitr
to create markdown files that are then rendered and posted at Rpubs. This post describes one of my first posts at Rpubs.
Install R and RStudio and Rtools
- Install R from CRAN
- It is also helpful to download RTools
- Install RStudio which is an Integrated Development Environment (IDE) with a helpful GUI (graphical user interface) layout for your R command line, scripting, logs, output, help and other useful windows all from the same integrated interface.
RStudio Interface - screen capture (Windows 8.1 on a Surface Pro 3)
To begin you first need to create a R-markdown (*.rmd)
file. From the RStudio menus, choose File/New File/R markdown.
For RStudio version 0.98.1091, creating a new RMD file opens another window where you can customize what kind of RMD file you want to create:
- either a document (in either HTML, DOC or PDF formats);
- presentation (as either HTML-ioslides, HTML-Slidy, or PDF-beamer formats);
- Shiny document (as HTML document with Shiny interactive components or Shiny presentation as IOSlides with interactive components); or
- from a template of your choosing.
The great thing about R-markdown documents using the current RStudio interface (since 0.96) is that the knitr
package is now built in as part of RStudio. Yihui Xie has more information on his website about knitr support in RStudio. You will notice that the RMD file I created below has both regular text and r code mixed together. When I am ready to compile this document I will click the Knit HTML
button at the top of the document which will then “weave” the text and code together executing the R code commands and embedding the results in the final document. For example, the first code “chunk” below runs summary statistics on the 2 variables in the cars
dataset (speed and dist) which comes with the base R software. The second code “chunk” below then creates a scatterplot of these variables (speed on the x-axis and dist on the y-axis). The final produced HTML document will show the summary statistics table and the scatterplot instead of the raw code.
Click on the Knit HTML
This will then execute the knitr
commands and process the document “weaving” together the markdown, text and r-codes to produce the HTML file. This HTML file will then open up in another screen (kind of like a temporary browser window from RStudio). From this window you can view your final HTML document, open it another browser application (like IE, Chrome, Firefox, etc), or “Publish” it.
By clicking on Publish you are asking to post your final document on Rpubs. For this to work you need to have an account set-up and be logged in to your Rpubs account.
If all goes well your document will then be posted to RPubs