R syntax highlighting for bloggers on WordPress.com

牵手常德棋牌官方下载Announcing the ability to highlight R syntax in WordPress.com blogs, thanks to the recent work of Yihui Xie, Yoav Farhi and Andrew Redd.

牵手常德棋牌官方下载Good news for who are using to host their blog.

This week, the good people running WordPress.com (special thanks goes to ), have added the ability for all the users of the WordPress.com platform to be able to highlight their R code inside posts.

牵手常德棋牌官方下载Basically you’ll need to wrap the code in your post like this:

[sourcecode language="r"]
test.function = function(r) {
    return(pi * r^2)

(Which will then look like this:
r syntax highlighted code example

Further details (and other supported languages) can be read about .

This new feature was possible thanks to the work of (who create for R), who created a (the plugin used by WordPress.com for sytnax highlighting) 牵手常德棋牌官方下载. And thanks should also go to , the creator of (which connects between notepad++ to R). He both made some good suggestions, and was game to take on the brush creation in case there would be problems, which thankfully so far there aren’t any)

p.s: If you are a WordPress.org users (e.g: have a self hosted WordPress blog) and want to enable R syntax highlighting for your blog, I would recommend the use of the WP-Syntax plugin (enhanced with GeSHi version which can be downloaded here.

26 thoughts on “R syntax highlighting for bloggers on WordPress.com”

  1. 牵手常德棋牌官方下载Another way to accomplish this is to compose your blog post and apply syntax highlighting offline (using a package such as Pygments which has grammars for R source code and R console transcripts) and post to WordPress using the XMLRPC API. This just requires adding some CSS to your template. If anyone is interested, details are here:

    1. Ana –
      This is a nice hack, but it has three disadvantages:
      1) It is not free – adding CSS on WordPress.com costs money.
      2) It requires the user to work on their websites CSS (which requires more time and fiddling)
      牵手常德棋牌官方下载 3) The user will need to spend time preparing their R code.

      This looks (IMHO) less simple then simple copy-pasting the code and adding the proper tags around it.


      1. 牵手常德棋牌官方下载Thanks for pointing out the cost issue. I have now added support for a CSS-inliner so you don’t need to modify your site’s CSS.

        1. Hi Andrew, this could work on a self hosted site – but it won’t work on a WordPress.com hosted site (since they will not allow the css to function without paying them). Revolution tool is nice, although for practical blog writing purposes, I find that using the WordPress plugins is faster to use.


  2. Awesome! Thanks a lot to all involved!

    牵手常德棋牌官方下载BTW, is there any difference between [sourcecode] and [code]? I was always using the latter.

    1. WordPress.com is using the plugin “SyntaxHighlighter Evolved” to highlight the code (Tal told me this), and one ugly thing about any software is always on the documentation. I didn’t find any explanation on which tag to use in the webpages on that plugin, and in the end, I found them in the source code — anyone of ‘sourcecode’, ‘source’ and ‘code’ can be used (line 208: )

      I simply use <pre> because that is the safest way — you code won’t be affected much even if your highlighter tool fails.

    1. 牵手常德棋牌官方下载Yihui you are right, I exaggerated a bit. I’ll correct my post.

      For my defense, you did come up in the R journal:

      And gave a talk in useR2010:


  3. Pingback:
  4. Pingback:
  5. Pingback:
  6. Pingback:
  7. Pingback:
  8. Pingback:
  9. Pingback:
  10. I had a few problems using this. I posted a screenshot at
    It’s a shame it didn’T work for me. It would be so great if it did.

  11. Pingback:
  12. Pingback:

Leave a Reply

牵手常德棋牌官方下载This site uses Akismet to reduce spam. .