Skip to content

WordPress Blogging with R in 3 Steps

September 29, 2009

A few people have emailed me and enquired about the use of tools mentioned at the end of this post to make blogposts with embedded R-commands. Below is a small step-by-step walkthrough of how to accomplish this.

  1. Write your blog post in a simple text file, you can include formatting using asciidoc syntax. Let’s call the file workflow.Rnw:
    Letters
    -------
    
    First we will display all the letters.
    
    <<>>=
    letters
    @
    
    And then only the first five letters of the alphabet.
    
    <<>>=
    letters[1:5]
    @
  2. Process workflow.Rnw with Sweave using driver provided by ascii package and create workflow.txt, a file in Asciidoc format.
    > library(ascii)
    > Sweave("workflow.Rnw", driver = RweaveAsciidoc,
    +     syntax = "SweaveSyntaxNoweb")
    Writing to file workflow.txt
    Processing code chunks ...
     1 : echo term verbatim
     2 : echo term verbatim
    
    You can now run asciidoc on 'workflow.txt'

    The asciidoc file workflow.txt looks like this:

    Letters
    -------
    
    First we will display all the letters.
    
    ----
    > letters
     [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m"
    [14] "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z"
    ----
    
    And then only the first five letters of the alphabet.
    
    ----
    > letters[1:5]
    [1] "a" "b" "c" "d" "e"
    ----
  3. Use Python script blogpost.py written by Stuart Rackham to upload the post to a WordPress host. The host and login details are contained in blogpost.py.conf.

    Note

    Prerequisites are Python >2.5 and Asciidoc.
    python blogpost.py post --conf blogpost.py.conf workflow.txt

    will render the following entry:


Letters

First we will display all the letters.

> letters
 [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m"
[14] "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z"

And then only the first five letters of the alphabet.

> letters[1:5]
[1] "a" "b" "c" "d" "e"
About these ads
One Comment leave one →
  1. erikr permalink
    September 30, 2009 1:31 am

    Hey, I actually posted something along these lines a couple weeks ago, at http://blogisticreflections.wordpress.com/2009/09/20/welcome-to-blogistic-reflections/

    You might want to check it out. In addition to using Sweave and the asciidoc driver, I use it within org-mode to get the HTML export functionality, including htmlized, pretty source code. You might find some of it useful, but only if you’re an Emacs/ESS user I suppose.

    I thought I might be the only one on WordPress using the asciidoc package to create posts, but I guess not! :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 167 other followers

%d bloggers like this: