Translate

Monday, 2 December 2013

Publishing with R Markdown and knitr using RStudio

Firstly, open RStudio and install 'knitr' package, and then select 'R Markdown' for a new document/script from the File menu as shown below. 

image1

Once R Markdown is selected the new document/script will be opened with some examples of R Markdown commands. This document will be saved as rmd format. 
Once the page is opened for R Markdown, there will be new radio buttons along the top side of the document. One of them will say 'MD'. Pressing this button will open a help page at the bottom right hand corner that lists all the necessary commands used in R Markdown, including those for formatting and styling. 

image2

As it can be seen from the image above, 'knit HTML' button will publish the contents of the rmd document into html version. The html file will be saved with the same name as the rmd file and will be saved at the same location. The preview page will also pop up at the same time. The below is an example of the preview pop-up page.

image3

If you are using an Unix-like environment or if you are trying to publish html document from rmd using Windows DOS, use the following command.

Rscript -e "knitr:::knit2html('filename')"


No comments:

Post a Comment