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

From: Arne Henningsen <arne.henningsen_at_googlemail.com>
Date: Tue, 10 Nov 2009 11:24:13 +0100

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

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Tue 10 Nov 2009 - 10:29:12 GMT

This archive was generated by hypermail 2.2.0 : Tue 10 Nov 2009 - 16:20:26 GMT