Message-ID: <ee2a35a60911100224y78cdbb15w53c74b239a547048@mail.gmail.com>
Date: 2009-11-10T10:24:13Z
From: Arne Henningsen
Subject: Bug in all.equal() or in the plm package
In-Reply-To: <4AF7FBD5.3090706@stats.uwo.ca>
On Mon, Nov 9, 2009 at 12:24 PM, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
> Arne Henningsen wrote:
>>
>> 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.
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
R> length(a[[1]])
[1] 1
R> length(a[[2]])
[1] 3
This would be more consistent with the usual behaviour of length, e.g.
R> b <- list( 1, 1:3 )
R> length(b)
[1] 2
R> length(b[[1]])
[1] 1
R> length(b[[2]])
[1] 3
/Arne
>> ======================================
>> R> data("Produc", package="plm")
>> R> zz <- plm(log(gsp)~log(pcap)+log(pc)+log(emp)+unemp,
>> + ? data=Produc, index=c("state","year"))
>> R> all.equal(zz,zz)
>> [1] TRUE
>> Warning message:
>> In if (length(target) != length(current)) return(paste("target,
>> current differ in having response: ", ?:
>> ?the condition has length > 1 and only the first element will be used
>>
>>>
>>> all.equal(zz$formula,zz$formula)
>>>
>>
>> [1] TRUE
>> Warning message:
>> In if (length(target) != length(current)) return(paste("target,
>> current differ in having response: ", ?:
>> ?the condition has length > 1 and only the first element will be used
>>
>>>
>>> class(zz$formula)
>>>
>>
>> [1] "pFormula" "Formula" ?"formula"
>> ======================================
>>
>> The last commands show that the warning message comes from comparing
>> the elements "formula", which are of the class "pFormula" (inheriting
>> from "Formula" and "formula"). It would be great if this issue could
>> be fixed in the future.
>>
>> Thanks a lot,
>> Arne
--
Arne Henningsen
http://www.arne-henningsen.name