12 September 2014

A bit about R Markdown

title: "About R Markdown Try Out"
author: "Dasapta Erwin Irawan"
date: "Friday, September 12, 2014"
   fig_width: 5
   fig_height: 5
   fig_caption: true

Dear all,

I've finally experienced an R history, especially in the evolution of R Markdown. I first knew R in 2011. It was when I attended a short course about Top Model package, delivered by Wouter Bouytaert of Imperial College London (pardon for mis-spelling). 

This post was written in R Markdown. For those of you that havent't used it, just go to File -> New -> R Markdown. The R Markdown (Rmd) was one of the flavour of the original Markdown markup that was made mainly for HTML. You can write web page easier with MD then convert it to HTML before then upload it to your web page.

If we use the older R studio, the conversion process is based on command lines using `knitr` package following this flow:

from Rmd -> rendered to md -> rendered to html (the basic final format). 

Knitr is an R package written by Yihui Xie. With this package you can convert an Rmd file to HTML, directly with in R Studio. The newer `knitr` package had included the `pandoc` ability. So you can convert Rmd to pdf, LaTex, odt, or even Word. 

Then what's Pandoc? 
It is a command line based software, written by John MacFarlane. Previously we had to separately installed `pandoc`  outside R std. Then convert Rmd to many formats including Word, via terminal or Windows prompt.to pdf or word. Pandoc project is still running now. With this software you can amazingly turn your txt file in to a full size book without any word processor software. 

Back to Rmd, the following sections talk about the components and basic features of Rmd. It basically consists of YAML header and body text.

# 1. YAML Header

The YAML (Yet Another Markup Language) header is placed on top of the Rmd file, and it must be started and closed with three dashes `---`. I tried with two or five dashes, it didn't work.

If we use the newest version of R Studio (Version 0.98.1049), Rstd will automatically make the the YAML header, based on our choices in new file window.

We can insert in YAML header our figure size using this command: 

+ `fig_width:`, 
+ `fig_height:`, and 
+ `fig_caption:` 

# 2. Embedding R code

The default `echo` will be `TRUE`. If we use option `{r, echo = FALSE}` then Rstd will still run the command but not showing the actual code in the final doc / html / pdf document.

We can use 

+ three back ticks without ```{r}``` to make a dummy code. R std will show the code but not running it.
+ or use ```{r, eval=FALSE}```

We can also name the chunk by typing ```{r chunkname}```, with no spaces. So then we can use it to make an in-text reference.

Here's an example.

```{r chunk1}
A <- 2="" font="">
B <- 2="" font="">
C <- a="" b="" font="">

We can also cache a chunk so it won't be re-run by R Std. If the result is figure, then the figure is named based on the chunk name.

Example: Here's an equation 

```{r chunk2, cache=TRUE}
A <- 2="" font="">
B <- 2="" font="">
C <- a="" b="" font="">

# 3. Embedding image

We can automatically embed R plots as you show me. We also can embed offline images by using this command.

![Alt text](/path/to/img.jpg)

Here's an example

![Fig 1 Citroen DS is the most beautiful car ever made](C:\Users\dira0651\Documents\14-09-12\CitroenDS.jpg) 

from [Wikipedia](http://en.wikipedia.org/wiki/Citroën_DS)

# 4. Bold, italics and bullets

We can use under score symbol to print bold and italic font:

+ __Bold__
+ _italic_ 

We can use symbols like `-` or `+`. Add two `tabs` for nested bullets.

+ Bullet 1
+ Bullet 2
    + Bullet 2.1
    + Bullet 2.2
+ Bullet 3

Or combined with number:

1. List 1
2. List 2
    + Bullet 2.1
    + Bullet 2.2
3. List 3

Post a Comment