WordPress Blogging with R in 3 Steps

[This article was first published on "R-bloggers" via Tal Galili in Google Reader, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.


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 their blog: "R-bloggers" via Tal Galili in Google Reader.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)