From murdoch@dunc@n @end|ng |rom gm@||@com  Fri Apr  5 18:00:27 2019
From: murdoch@dunc@n @end|ng |rom gm@||@com (Duncan Murdoch)
Date: Fri, 5 Apr 2019 12:00:27 -0400
Subject: [Rd] [EXTERNAL] Re: Re: all.equal failure
In-Reply-To: <23719.30050.351411.6577@stat.math.ethz.ch>
References: <b23057$belnhe@ironport10.mayo.edu>
 <7b627c90-1bbf-b2a5-5ddc-391711f5208e@gmail.com>
 <b23057$bemifh@ironport10.mayo.edu>
 <8eced21f-bd54-1675-8122-b2119e36f901@gmail.com>
 <b23057$bems3o@ironport10.mayo.edu>
 <4ef61872-a213-7205-673c-fbc6a65d98ae@gmail.com>
 <23719.30050.351411.6577@stat.math.ethz.ch>
Message-ID: <4ee47f6c-e1c8-73c6-ba67-1feb97cf4e48@gmail.com>

On 05/04/2019 11:33 a.m., Martin Maechler wrote:
>>>>>> Duncan Murdoch
>>>>>>      on Fri, 5 Apr 2019 11:12:48 -0400 writes:
> 
>      > On 05/04/2019 10:46 a.m., Therneau, Terry M., Ph.D. wrote:
>      >>
>      >>
>      >> On 4/5/19 9:39 AM, Duncan Murdoch wrote:
>      >>> On 05/04/2019 10:19 a.m., Therneau, Terry M., Ph.D. wrote:
>      >>>> Duncan,
>      >>>> ?? I should have included it in my original note, but
>      >>>>
>      >>>> ??? ? all.equal(unclass(t0x), unclass(t1x))
>      >>>>
>      >>>> returns TRUE as well.? I had tried that as well. ? But a further look at
>      >>>> all.equal.default shows the following line right near the top:
>      >>>> ???? if (is.language(target) || is.function(target))
>      >>>> ???????? return(all.equal.language(target, current, ...))
>      >>>>
>      >>>> and that path explicitly ignores attributes.
>      >>>
>      >>> Which R version are you using?? I see deparse(target) and deparse(current) in
>      >>> all.equal.language(), and those should not be ignoring attributes according to the
>      >>> documentation.
> 
> But the problem is that indeed  "of course"  all.equal.formula()
> and not all.equal.language() is called for the terms since as
> you yourself remarked, their class is  c("terms", "formula"),
> 
> and so what Terry reported is indeed correct *and* a bug
> and in "all versions" of R (I did not look far back, but these things
> haven't changed much).
> 
> The cleanest would probably be to define an  all.equal.terms()
> method, as I think there may be more code relying on the
> behavior of  all.equal.formula() to only look at the formulas
> themselves and not their attributes...
> but you (Duncan) and others may have a different opinion.

I don't know if that would be easy -- it seems to me there is a bug in 
deparse(), which won't show attributes on language objects even if you 
ask it to:

# This is fine:
deparse(structure(1, attrib=2))
# [1] "structure(1, attrib = 2)"

# This doesn't show the attributes
deparse(structure(quote(f(1)), attrib=2))
# [1] "f(1)"

But as you mention, if this isn't a new bug fixing it will likely cause 
problems for people who assume it is intentional...

Duncan



[Rd] [EXTERNAL] Re: Re: all.equal failure
Duncan Murdoch