giovedì 14 luglio 2011

R meets XKCD

Being a big fan of XKCD and, of course, of the R programming language, I thought that a package which allows to display my favorite strips  would something (useless) but cool!
So, mimicking the approach (and the code) of the fortunes package (thanks Achim Zeileis!), I created a simple package (names RXKCD) which allows the user to displays his favorite XKCD strip by selecting the specific number, randomly or simply displaying the current strip.
You can install the package using:
if (!require('RJSONIO')) install.packages('RJSONIO', repos = '')
if (!require('png')) install.packages('png', repos = '')
if (!require('ReadImages')) install.packages('ReadImages', repos = '')
install.packages("RXKCD", repos="")
And you can use it by typing:
searchXKCD("someone is wrong")
Below the result (xkcd license):

Update: The updated version of the package , which is available from CRAN (just type install.packages("RXKCD") ), allows the user to save the xkcd metadata database in a local directory (.Rconfig) and update it in order to have access to the latest XKCD info: see ?saveConfig and ?updateConfig.

8 commenti:

  1. cannot install
    > install.packages("RXKCD", repos="")
    Warning message:
    In getDependencies(pkgs, dependencies, available, lib) :
    package ‘RXKCD’ is not available (for R version 2.13.1)

  2. Are you able to install the dependencies: RJSONIO, png, ReadImages packages?

    If the procedure described in the post above does not work, you can dowload the package source from:

    and install it by typing:
    install.packages("RXKCD_1.0.tar.gz", repos=NULL, type="source")

  3. Thanks. The code in the post work on Linux but not on Windoze. I did not try your suggestion.

  4. I see. To tell the truth I tried the code on Linux and Mac only! I can't guarantee it would work on Win! Sorry!

  5. I haven't tried the package yet, but does it include the mouse-overs? Sometimes those are the funniest part.

  6. The value returned by the getXKCD() function includes an 'alt' field containing the string related to the mouse-over event but it doesn't work on the downloaded image: so you can read it but it will not show on the image.

  7. Is it possible to include functions to support things like in

    I'm interested in revamping using ggplot2 and manipulate.

  8. It is open source and you are free to contribute! You can find the RXKCD package page at this link.