Re: [S] Assignment arrow.

Tue, 26 May 1998 10:37:05 -0200

On Thu May 21 19:41:15 1998,
Z. Todd Taylor <> wrote:
>Don MacQueen <> wrote:
>> Splus has a variety of syntax options that are useful, but that I tend to
>> avoid for the sake of clarity and quick comprehension. For example,
>> embedded assignment:
>> if ( x.cls <- inherits(x,'lm') ) {...}
>> (admittedly, this one isn't really all that bad, but you get the idea, I
>I love that particular idiom (as well as others like it)...

After having been bitten once, this particular idiom is one I never ever use
anymore. OK, in an if (...) statement its no problem. But used in the
list of a function call it can be. Why? Lazy evaluation. Watch:

> danger <-
function(x, y)
if(x < 0)
else y

> danger(-1, a <- 2)
[1] -1

> a
Error: Object "a" not found

> danger(1, a <- 2)
[1] 2

> a
[1] 2

Whether or not object "a" is created depends on the value of argument x.
Not particularly nice. Of course this is a simplified example where the
is pretty obvious; it can get much more obscure.

As for the "_" assignment operator, I use it all the time at the command line
(lazy fingers), never ever when writing functions. I'm (= I am) not sure what
the fuss is about, except perhaps aesthetics. Been working with S this way
for years now and I'm still functioning reasonably well...


P.S. Bill, I'm working on that formatting. ;)

Wageningen Agricultural University
Laboratory of Plant Breeding
P.O. Box 386
6700 AJ Wageningen

This message was distributed by To unsubscribe
send e-mail to with the BODY of the
message: unsubscribe s-news