Sunday, June 15, 2014

Blogging in R

1. R Markdown

This post will introduce the steps to publish a R script with outputs and relevant documentations onto Blogger blogs. Since Blogger accepts posts in text or HTML, and text is too inefficient and hence out of the question, we need to look into producing HTML versions of our R scripts and incorporating them into the blogs.

The following method needs minimal support from external installations. The only requirements are:

  • RStudio IDE,
  • knitr package,
  • text editor e.g. Notepad++, Sublime.

There are three steps involved:

  1. coding and documenting in R Markdown format,
  2. ouput to a .html file,
  3. copy a portion of the .html file and paste it into the HMTL entry box on your blog entry editor.

This post is created and published by the above steps.

1. R Markdown

Since the purpose of a blog post is not to simply share codes, but to teach and to exchange knowledge, a fair amount of text is expected to be included to explain ideas, concepts and methods. R Markdown is a neat format to use when you have both text and code/output, and you do not want your text to appear as chunky comments as in a R script (no, seriously, you do not want that).

After installing knitr in RStudio, you can create a new R Markdown file by going to File | New | R Markdown. The R Markdown file can interpret Markdown syntax, as well as R codes.

For instance, you can write in bold or italics using asterisk marks, and in-line code with a back-tick.

You can display outputs to R functions:

summary(cars)
##      speed           dist    
##  Min.   : 4.0   Min.   :  2  
##  1st Qu.:12.0   1st Qu.: 26  
##  Median :15.0   Median : 36  
##  Mean   :15.4   Mean   : 43  
##  3rd Qu.:19.0   3rd Qu.: 56  
##  Max.   :25.0   Max.   :120

You can also embed plots:

plot(cars)

plot of chunk unnamed-chunk-2

Read this article for more details on how to write in R Markdown.

2. RMD to HTML

Click the Knit HTML button at the top of the scripting panel to knit the R Markdown file to HTML. In the same folder where the .rmd file is stored, a .html file is created.

3. HTML to Blog Post

Open the .hmtl file in a text editor. On the blog entry box, switch from text to HTML. You will now need to copy a portion of the HTML code into the entry box.

To entirely retain the formatting of your blog, then just select the portion within the <body> </body> tags.

For this post, I selected all the HTML code except for

body, td {
   font-family: sans-serif;
   background-color: white;
   font-size: 12px;
   margin: 8px;
}

in the <head> </head> tags, so that I retain the basic format of my blog while including other elements such as visualizing codes in wells.

Finally, Publish!

Sunday, February 23, 2014

속담 [A]

아는 길도 물어 가라.
Even if you know the way, ask.

아니 땐 굴뚝에 연기 날까?
There is no smoke without fire. / 无风不起浪。
[굴뚝 = chimney, 연기 = smoke, 나다 = emanate]


Reference:

http://en.wikiquote.org/wiki/Korean_proverbs
https://sites.google.com/site/matthewpluskoreanequalsfun/sayings-proverbs-sogdam

Saturday, February 22, 2014

Biei, Hokkaido

I had this idea of drawing with lines. First trial.

While at Biei, Hokkaido, last summer, I cycled past a wheat field and took the photo below. Honestly, there's a perfect screensaver-worthy photo at every turn.


I contemplated not including the original photo here in this post, since my "line picture" cannot match up to the intricate details and clarity. It is a compressed and impressionistic representation of the real thing. Clear blue sky. Vast wheat field. One lone tree. And especially that brilliance of light that seems to originate from the far point, where clouds meet field, and spreads to color the entire heavens and earth.


While playing around with Photoshop, I was pleasantly surprised by what I see just by changing the hues. Rather mesmerizing.


Sunday, February 9, 2014

《如梦之梦》观后感

“有一个故事里,有人做了一个梦,在那个梦里,有人说了一个故事。”
360度的舞台、8个小时的演出、时间与空间的穿越,这样的一场话剧,令人印象深刻。虽然无幸买到舞台中央莲花池内的票,无法近距离地看清演员们脸上的表情,从远处看也别有一番风味。 当多个演员在舞台上演示同一个角色时,在我眼里,我真的可以看到一个角色的多个分身。每个角色没有清楚的样貌表情,全凭想象;我确实听了一个故事。

这是一个怎样的故事?

一个关于人生的故事。第一幕,所有演员绕着舞台一直走,一圈一圈地走。有的人跑起来了,越跑越快,超越了其他人,又被其他人超越。可是不管怎么跑,这都是一个圈,没有起点,没有终点,没有谁前谁后。他们放慢了脚步,一个一个的,直到所有人都静止地站着,站在舞台上不一样的位置。那就是终点吧。

这是一个怎样的故事。

一位刚从医学院毕业的学生第一天上班,她被分配的五个病人里,当天就死了四个。无助,她不知道如何面对死亡。学校里没有教过。她从表妹那里听说,可以试着倾听濒临死亡的病人叙述他们自己的故事,借此帮助他们,减轻他们的痛苦,哪怕只有一点点。 这不符合学校里教的专业知识,也不符合医院里的流程做法,但是她还是这样去做了。她终于得到了五号病人的信任,听他讲述了他的人生旅程...

五号病人莫名其妙地认识了妻子,妻子又莫名其妙地离开了他。他莫名其妙地得了一场怪病,为找到一个能解释自己命运的说法来到巴黎,爱上了一个叫江红在巴黎边缘漂泊的女子。他们因为一个吉普赛人的一句话去寻找一个远方的古堡。在古堡,他看见一幅画,并为了追随画中平生未见的女主人公离开了巴黎和江红,去到了上海,在那儿听她讲了一个故事。很奇怪,很飘渺,但是确实发生了。妻子没有回来,五号病人没有找到病因,他和江红没有重逢,他与画中人也只是一幅画的联系,仅此而已。但是他却在她临死前听完了她一生的故事。就像那位年轻的医生在他临死前听完了他一生的故事一样。

五号病人始终没有名字;人到最后也只是个号码而已。他可能是我们任何一个人,他的故事可能是我们任何一个人的故事。

那位画中人叫顾香兰,在旧上海曾是一名名妓。她爱过一个叫王德宝的富二代,却被一个法国伯爵看上。伯爵为她赎了身,带她住在法国古堡里。顾香兰得到了自由,和另一个牢笼。她和伯爵无法沟通,不仅仅是在语言上,语言可以学习,而是在心灵和思想上,这种鸿沟难以跨越。对伯爵来说,顾香兰只是个漂亮精致的玩偶。当玩偶有了自己的生命,不再受操纵者控制时,它就会被遗弃。顾香兰和伯爵因为思想上的格格不入开始在情感上折磨对方,说不上谁对谁错,直到有一天伯爵带着所有的财产离开了。从金丝雀到麻雀的过程如此突然,顾香兰为了复仇,忍辱负重地在法国活着,只是活着、等着。多年后再见到伯爵时,当她还在盘算着如何重重地打出报复的一击时,她发现伯爵得了癌症。复仇一直是个目标,当目标忽然不再清晰的时候,人生就没了重心,没了着陆点。也许复仇本就不应该是个目标,虽然当时它是个如此唯一的选择。后来,王德宝竟在法国找到了顾香兰。他们两人回到了上海,却回不到过去。更确切的说,王德宝宁愿停留在过去,在那个谈情说爱送花做爱的回忆里,并没意识到顾香兰已经不在了。也许他跟伯爵一样从未真的在意过顾香兰的内心,只是年轻、快感和痴迷给了他‘爱’的错觉。

这是一个怎样的故事...

一个让人舍不得叫停的故事,又是一个不得不醒,可是醒了,却又还在梦境里的梦。顾香兰死了,但她的故事被五号病人传承着。五号病人死了,他的故事被那年轻的医生,被愿意聆听的我们,传承着。而我们的故事,又如何呢。
 
我仿佛做了一场梦,梦里,有人说了一个故事。

Thursday, January 16, 2014

자기 소개

안녕하세요?
만나서 반갑습니다.
제 이름은 웬유 입니다.
저는 싱가포르에서 왔어요.
저의 취미는 독서하기 입니다.