Skip to content
Prev 200548 / 398506 Next

Where are usages like "== 2L" documented?

On Tue, 17 Nov 2009, Bryan Hanson wrote:

            
NB: identical(x, y) is TRUE, so they behave the same.
Not really: the operands are coerced to a common type and then tested 
for equality.  From the help page for "=="

      If the two arguments are atomic vectors of different types, one is
      coerced to the type of the other, the (decreasing) order of
      precedence being character, complex, numeric, integer, logical and
      raw.
It avoids coercion.  The test x == 1 requires x to be coerced from 
integer to double, and foo[1] requires '1' to be coerced from double 
to integer.  There is little if any gain in storage space for small 
integer vectors over small double vectors, but all those coercions can 
create a lot of new objects which need to be garbage-collected.

Also, 2L is simpler to write and to read than as.integer(2) (and 
avoids a funtion call and a coercion).