WordPress Blogging with R in 3 Steps

September 29, 2009
By

(This article was first published on "R-bloggers" via Tal Galili in Google Reader, and kindly contributed to R-bloggers)


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"

To leave a comment for the author, please follow the link and comment on his blog: "R-bloggers" via Tal Galili in Google Reader.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , , , ,

Comments are closed.