tags:

views:

106

answers:

1

I am revising a paper for submission and would like to replace the old lattice graphics with shiny new ggplot2 versions. However, I run into compatibility problems between ggplot2 and two packages that are absolutely crucial for my analyses, coin and arm. When executing the following example from the manual

qplot(sleep_rem / sleep_total, awake, data = msleep)

I get an error message saying:

   Error in function (classes, fdef, mtable)  : 
   unable to find an inherited method for function "empty", for signature "data.frame"

as soon as either coin or arm are loaded.

Here are the details:

Running R 2.10.1, empty .RData file

require(ggplot2)
require(xtable)
require(MASS)
require(gdata)
require(car)
require(Hmisc)
require(psych)

qplot(sleep_rem / sleep_total, awake, data = msleep)

require(coin)
qplot(sleep_rem / sleep_total, awake, data = msleep)

require(arm)
qplot(sleep_rem / sleep_total, awake, data = msleep)

Is this reproducible with R 2.12? If not, might it be worth upgrading? I must confess I am loath to update a working system, especially when on a tight deadline.

+5  A: 

It's only the coin package that seems incompatible. Reason is that one of the packages loaded together with coin (modeltools to be exact) also contains a function empty() that masks the function empty() of plyr. Updating to R 2.12 won't change a darn thing, as both packages are contributed by other authors. You should mail the author of the ggplot package and tell him to specify plyr::empty() in his code. Or even the guys from the plyr package, as the problem might actually be there.

A possible hack could be :

require(coin)
empty <- plyr::empty
qplot(sleep_rem / sleep_total, awake, data = msleep)
rm(empty)

This works on 2.11.1 using following data frame:

msleep <- data.frame(
    sleep_rem=c(1,2,3,4,5),
    sleep_total=c(10,20,30,40,50),
    awake=c(5,4,3,2,1)
)

Make sure you remove empty from the workspace right after plotting. Otherwise you might get trouble with the other packages that are loaded. You'll have to do that with every plot you make after you loaded the package coin.

Joris Meys
This works! Joris, dank je wel (assuming you're Dutch - I'm German). The author of ggplot2 and plyr is Hadley Wickham, so if I tell him, I've told all the relevant people.
Maria Wolters
@Maria: I mailed him already, didn't realize he was the author of both. and indeed, I'm belgium. Graag gedaan dus. ;-)
Joris Meys
This problem should be fixed in the development version of ggplot2.
hadley
Nice find. Joris has a neck for these sort of things.
Roman Luštrik
Thank you Hadley! Have been producing some pretty graphs again ;)
Maria Wolters
@hadley I missed you're the author of both. Thx for the fast response - and the great packages!
Joris Meys