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.
cannot install
RispondiElimina> 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)
Are you able to install the dependencies: RJSONIO, png, ReadImages packages?
RispondiEliminaIf 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")
Thanks. The code in the post work on Linux but not on Windoze. I did not try your suggestion.
RispondiEliminaI see. To tell the truth I tried the code on Linux and Mac only! I can't guarantee it would work on Win! Sorry!
RispondiEliminaI haven't tried the package yet, but does it include the mouse-overs? Sometimes those are the funniest part.
RispondiEliminaThe 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.
RispondiEliminaIs it possible to include functions to support things like in http://xkcd.com/467/?
RispondiEliminaI'm interested in revamping http://xkcd.com/467/ using ggplot2 and manipulate.
It is open source and you are free to contribute! You can find the RXKCD package page at this link.
RispondiElimina