[R] odd feature
Martin Maechler
maechler at stat.math.ethz.ch
Mon May 22 17:40:53 CEST 2006
>>>>> "Gabor" == Gabor Grothendieck <ggrothendieck at gmail.com>
>>>>> on Mon, 22 May 2006 11:34:09 -0400 writes:
Gabor> On 5/22/06, Martin Maechler <maechler at stat.math.ethz.ch> wrote:
>> >>>>> "TL" == Thomas Lumley <tlumley at u.washington.edu>
>> >>>>> on Mon, 22 May 2006 07:09:09 -0700 (PDT) writes:
>>
TL> On Mon, 22 May 2006, Gabor Grothendieck wrote:
>> >> Due to lazy evaluation, I don't think a and b are fully evaluated:
>> >>
>> >>> ifelse(1, a <- 1, b <- 2)
>> >> [1] 1
>> >>> a
>> >> [1] 1
>> >>> b
>> >> Error: object "b" not found
>>
TL> yes. If you look at the code for ifelse() it evaluates
TL> the second argument if any test values are TRUE and the
TL> third argument if any test values are FALSE, so in the
TL> scalar case it does not evaluate both arguments.
>>
>> yes.
>> And (Gabor), if you recall what I said earlier, it's pretty clear
>> that I would not even *consider* using ifelse() in the scalar
>> case. So my original statement was about the case ifelse() is
>> designed for: The non-trivial vector case, and there my
>> statement of "fully evaluated" does apply.
>>
>> Martin
>>
Gabor> I don't think they are fully evaluated in the vector case either:
>> ifelse(rep(TRUE,4), a <- 1:4, b <- 1:4)
Gabor> [1] 1 2 3 4
>> a
Gabor> [1] 1 2 3 4
>> b
Gabor> Error: object "b" not found
PLEASE !!!!
------
I said "non-trivial" above !!!!!!!!
Martin
More information about the R-help
mailing list