[R] Bug in "is" ?

Kingsford Jones kingsfordjones at gmail.com
Fri Sep 26 00:19:48 CEST 2008


On Thu, Sep 25, 2008 at 3:23 PM, Wacek Kusnierczyk
<Waclaw.Marcin.Kusnierczyk at idi.ntnu.no> wrote:
> Rolf Turner wrote:
>>
[snip]

>> Now what on earth does ``integer type'' mean?  The concept ``type'' is
>> not defined
>> anywhere, and there is no help on ``type''.  There is no type()
>> function.  One
>> has to intuit, from the discussion of integer vectors existing so that
>> they
>> can be properly passed to .C() or .Fortran(), that type has something
>> to do
>> with storage mode.
>
> indeed.  one more example that R man pages are often rather
> uninformative, despite verbosity

Try

?type

which correctly guesses the user is looking for the 'typeof' page.

Or even

example(type)

Also, after a brief introduction, the R Language Definition document
begins with a discussion of types.


Kingsford Jones




>>
>> It would have been better to have called the function now known as
>> ``is.integer()''
>> something like ``is.storedAsInteger()'' and have a function
>> is.integer() which
>> does what people expect.  E.g.
>>
>>     is.integer(c(5.1, 5.4, 4.8, 5.0))
>>
>> would return
>>
>>     [1] FALSE FALSE FALSE TRUE
>
>>
>> Despite what fortune(85) says, it is not unreasonable to expect
>> functions to
>> do what one would intuitively think that they should do.  E.g. sin(x)
>> should not return
>> 1/(1+x^2) even if the help page for sin() says clearly and explicitly
>> that this
>> is what it does.  (Aside:  help pages rarely if ever say *anything*
>> clearly and
>> explicitly, at least from the point of view of the person who does not
>> already
>> understand everything about the concepts being explained.)
>
> indeed.  one more opinion that R man pages are often rather
> uninformative, despite verbosity.
>
>
>>
>> Be that as it may, this all academic maundering.  The is.integer()
>> function
>> does what it does and THAT IS NOT GOING TO CHANGE.  We'll just have to
>> deal
>> with it.  Once one is *aware* that the results of is.integer are
>> counter-intuitive,
>> one can adjust one's expectations, and it's no big deal.
>>
>> I do think, however, that there ought to a WARNING section in the help on
>> is.integer() saying something like:
>>
>>     NOTE: is.integer() DOES NOT DO what you expect it to do.
>
> hehe.  this should be printed on the first page in every R tutorial:
> "NOTE: R DOES NOT DO what you expect it to do" (seems i'm in a bad mood,
> sorry, R is just fine).
>
>>
>> In large friendly letters.
>>
>>     cheers,
>>
>>         Rolf Turner
>>
>> P. S.  Those who want a function that does what one would naturally
>> expect
>> is.integer() to do could define, e.g.
>>
>>     is.whole.number <- function(x) {
>>         abs(x-round(x)) < sqrt(.Machine$double.eps)
>>     }
>>
>> Then
>>
>>         is.whole.number(c(5.1, 5.4, 4.8, 5.0))
>>
>> returns
>>
>>     [1] FALSE FALSE FALSE TRUE
>>
>> just as one would want, hope, and expect.
>
> if *this* is what one would want, hope, and expect from is.integer, why
> can't we want, hope, and expect that it eventually happens?
>
> vQ
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list