[Rd] Bug in all.equal() or in the plm package

Achim Zeileis Achim.Zeileis at wu-wien.ac.at
Wed Nov 25 16:21:19 CET 2009


Hi,

sorry for replying so late to this. I somehow missed the original thread 
and was just pointed to it by Yves...

>>> I noticed that there is a (minor) bug either the command all.equal()
>>> or in the "plm" package. I demonstrate this using an example taken
>>> from the documentation of plm():
>>>
>>
>> I'm not sure this is a bug, but I'd call it at least a design flaw. 
>> The problem is that the length.Formula method in the Formula package 
>> (which plm depends on) returns a vector of length 2.  Now there's 
>> nothing in R that requires length() to return a scalar, but all.equal 
>> assumes it does, and I'd guess there are lots of other places this 
>> assumption is made.

Well, ?length says:

      The default method currently returns an 'integer' of length 1.
      Since this may change in the future and may differ for other
      methods, programmers should not rely on it.

The problem IMO is that the all.equal() method for "formula" gets called 
by inheritance without assuring that it works. I think we just need to 
supply a suitable all.equal() method for "Formula" objects.

>> Okay, let's call it "design flaw". Given that the "unusual" behaviour
>> of length.Formula() causes this problem, I suggest that the
>> length.Formula() method should be changed. Maybe to something like

> R> a <- as.Formula( y ~ x | z | w )
> # current behaviour:
> R> length(a)
> [1] 1 3
> # suggested behaviour:
> R> length(a)
> [1] 2

This wouldn't be correct either because this is not a list of length 2. A 
"Formula" is a "formula" (of length 2 or 3) with two attributes ("lhs" and 
"rhs"). Thus, currently length() does not reflect the internal structure 
but rather the conceptual structure (of a formula consiting of a LHS and 
RHS, both with a certain length).

Unless there are good reasons to do otherwise, I would keep the length() 
method and just supply a suitable all.equal() method for 
"Formula" objects.

hth,
Z


More information about the R-devel mailing list