# [Rd] 'is.integer' (PR#13671)

Stavros Macrakis macrakis at alum.mit.edu
Wed Apr 22 22:30:36 CEST 2009

```Dear R experts,

You are being a bit harsh on this user. He simply doesn't understand
the distinction between "object of type integer" and "integer-valued
object", which is actually fairly subtle.

On Wed, Apr 22, 2009 at 1:45 PM,  <hzambran.newsgroups at gmail.com> wrote:
> This is a very simple function that seems not to be working, according to the
> definition given by '?is.integer'.
...
>> is.integer(1)
>  FALSE
>
> and 1 is obviously an integer value.

The is.integer function is correctly documented to check whether
objects are of *type* integer, thus:

is.integer( 1L ) => TRUE

In R, objects of type integer are only created with literals of the
form 999L; as the output of some functions when the input is integral
(e.g. sort, unique, rev, ...); as the output of some functions which
return index values or differences of index values (which, grep, rle,
...); and the output of a few other functions in certain cases (seq).

Most numbers in R are floating-point numbers (type double), and
determining whether their value is integral is rather subtle.

For example, consider the vector 1+1000^-(1:6).  In floating-point
arithmetic, the first 5 values are distinguishable from the integer 1,
but the 6th is not, though of course the *mathematical* number
1+1000^-6 is not integral.  Now consider 1e40, which has the property
that floor(x)==x==ceiling(x), which you might think characterizes an
integer;  but it also has the property that x+1 == x.  Similarly for
1/3 * 1e40.

In other words, it is really a rather subtle question whether a
floating-point number "represents" an integer....

-s

```