From murdoch at stats.uwo.ca  Mon Nov  9 12:24:05 2009
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Mon, 09 Nov 2009 06:24:05 -0500
Subject: [Rd] Bug in all.equal() or in the plm package
In-Reply-To: <ee2a35a60911090229q39087424u92fea71d6dbdb78c@mail.gmail.com>
References: <ee2a35a60911090229q39087424u92fea71d6dbdb78c@mail.gmail.com>
Message-ID: <4AF7FBD5.3090706@stats.uwo.ca>

Arne Henningsen wrote:
> Hi!
>
> 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.

Duncan Murdoch
> ======================================
> 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
>
>



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