Skip to content
Back to formatted view

Raw Message

Message-ID: <alpine.LRH.2.01.1001150805310.13188@hymn34.u.washington.edu>
Date: 2010-01-15T16:05:31Z
From: Thomas Lumley
Subject: advice/opinion on "<-" vs "=" in teaching R
In-Reply-To: <d8ad40b51001150014i1e2b99bcw9213d02c4c04fdfb@mail.gmail.com>

On Fri, 15 Jan 2010, Barry Rowlingson wrote:

> On Fri, Jan 15, 2010 at 6:57 AM, Ted Harding
> <Ted.Harding at manchester.ac.uk>wrote:
>
>>
>> There is at least one context where the distinction must be
>> preserved. Example:
>>
>>  pnorm(1.5)
>>  # [1] 0.9331928
>>  pnorm(x=1.5)
>>  # Error in pnorm(x = 1.5) : unused argument(s) (x = 1.5)
>>  pnorm(x<-1.5)
>>  # [1] 0.9331928
>>  x
>>  # [1] 1.5
>>
>> Ted.
>>
>>
> I would regard modifying a variable within the parameters of a function
> call as pretty tasteless. What does:
>
>
> foo(x<-2,x)
> or
> foo(x,x<-3)
>
> do that couldn't be done clearer with two lines of code?
>

It allows the lazy evaluation mechanism to determine whether the  assignment happens. That would be very hard to do in two lines of code.

         -thomas

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