Re: [R] odd feature

From: Uwe Ligges <ligges_at_statistik.uni-dortmund.de>
Date: Tue 23 May 2006 - 01:45:32 EST

Gabor Grothendieck wrote:

> On 5/22/06, Martin Maechler <maechler@stat.math.ethz.ch> wrote:
>

>>>>>>>"TL" == Thomas Lumley <tlumley@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
>>

>
>
> I don't think they are fully evaluated in the vector case either:
>
>
>>ifelse(rep(TRUE,4), a <- 1:4, b <- 1:4)

>
> [1] 1 2 3 4
>
>>a

>
> [1] 1 2 3 4
>
>>b

>
> Error: object "b" not found

Martin's "non-trivial" means not all conditions are TRUE or not all are FALSE, then both statements are FULLY evaluated and he is right.

See the ifelse() code which is not that hard to read...

Uwe

> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue May 23 01:58:45 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 23 May 2006 - 02:10:19 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.