[R] "is" and the story of a typo

Uwe Ligges ligges at statistik.tu-dortmund.de
Thu Apr 1 20:35:40 CEST 2010



On 31.03.2010 10:21, (Ted Harding) wrote:
> On 30-Mar-10 23:23:09, Jim Lemon wrote:
>> Hi all,
>> The gurus may pour scorn on me for not knowing this, but I happened
>> to  mistype "if" as "is" in the heat of debugging a function. As I
>> scanned the debugged function with some satisfaction, I noticed the
>> error. How could this have worked?

Beside Ted's comments: You could have mistyped it completely different 
with a valid function name and as long as it is syntactically valid, how 
should R be able to guess your error?

Example:

x <- 1
# You want:
if(x < 5)
    cat("YES!\n")

# works:
sin(x < 5)
    cat("YES!\n")


# and also
sin(x < 5)
{
    cat("YES!\n")
}

# but not

sin(x < 5){
    cat("YES!\n")
}

#  nor

sin(x < 5)  cat("YES!\n")

# and that is also true for is:

is(x < 5){
    cat("YES!\n")
}

is(x < 5) cat("YES!\n")



I think now we all have again a better idea about the way the R prser 
does its job....

Uwe Ligges





  I assume that "is" is a generic
>> function that calls one of the is.* functions to evaluate whatever
>> is passed. It appears that this particular typo causes "is" to work
>> out and report the contents of its argument. Ho hum. As I did not
>> test the FALSE result, I never would have noticed that it was not
>> the conditional statement I expected until it evaluated something
>> that should have been FALSE.
>>
>> Jim
>
> Hi Jim,
>
>    is: ?is
>
>    is(is)
>
>    is(is(is))
>
>    is(is(is(is)))
>
>    identical(is(is(is)),is(is(is(is))))
>
> Ted.
>
> --------------------------------------------------------------------
> E-Mail: (Ted Harding)<Ted.Harding at manchester.ac.uk>
> Fax-to-email: +44 (0)870 094 0861
> Date: 31-Mar-10                                       Time: 09:21:29
> ------------------------------ XFMail ------------------------------
>
> ______________________________________________
> 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