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 = 'http://cran.r-project.org')
if (!require('png')) install.packages('png', repos = 'http://cran.r-project.org')
if (!require('ReadImages')) install.packages('ReadImages', repos = 'http://cran.r-project.org')
install.packages("RXKCD", repos="http://R-Forge.R-project.org")
And you can use it by typing:
library(RXKCD)
searchXKCD("someone is wrong")
getXKCD(386)
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="http://R-Forge.R-project.org")
    Warning message:
    In getDependencies(pkgs, dependencies, available, lib) :
    package ‘RXKCD’ is not available (for R version 2.13.1)

    RispondiElimina
  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:

    https://r-forge.r-project.org/src/contrib/RXKCD_1.0.tar.gz

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

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

    RispondiElimina
  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!

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

    RispondiElimina
  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.

    RispondiElimina
  7. Is it possible to include functions to support things like in http://xkcd.com/467/?

    I'm interested in revamping http://xkcd.com/467/ using ggplot2 and manipulate.

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

    RispondiElimina