Re: [R] odd feature

From: Thomas Lumley <tlumley_at_u.washington.edu>
Date: Tue 23 May 2006 - 00:09:09 EST

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

yes. If you look at the code for ifelse() it evaluates the second argument if any test values are TRUE and the third argument if any test values are FALSE, so in the scalar case it does not evaluate both arguments.

         -thomas

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley@u.washington.edu	University of Washington, Seattle

______________________________________________
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 00:13:46 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:14 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.