[Rd] logical comparison of functions (PR#13588)

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Tue Mar 10 22:12:53 CET 2009


Duncan Murdoch wrote:
> On 10/03/2009 4:35 PM, michael_karsh at earthlink.net wrote:
>> Full_Name: Michael Aaron Karsh
>> Version: 2.8.0
>> OS: Windows XP
>> Submission from: (NULL) (164.67.71.215)
>>
>>
>> When I try to say if (method==f), where f is a function, it says that
>> the
>> comparison is only possible for list and atomic types.  I tried
>> saying if
>> (method!=f), and it gave the same error message.  Would it be
>> possible to repair
>> it say that == and != comparisons would be possible for functions?
>
> This is not a bug.  Please don't report things as bugs when they
> aren't.  "==" and "!=" are for atomic vectors, as documented.
>
> Use identical() for more general comparisons, as documented on the man
> page for ==.

note that in most programming languages comparing function objects is
either not supported or returns false unless you compare a function
object to itself.  r is a notable exception:

    identical(function(a) a, function(a) a)
    # TRUE

which would be false in all other languages i know;  however,

    identical(function(a) a, function(b) b)
    # FALSE

though they are surely identical functionally.

btw. it's not necessarily intuitive that == works only for atomic vectors.

vQ



More information about the R-devel mailing list