[R] Is there any difference between <- and =

David M Smith david at revolution-computing.com
Fri Mar 13 01:10:28 CET 2009

On Thu, Mar 12, 2009 at 8:29 AM, "Jens Oehlschlägel" <oehl_list at gmx.de> wrote:
> Thus there is dangerous advice in the referenced blog which reads:
> "
> f(x <- 3)
> which means "assign 3 to x, and call f with the first argument set to the value 3
> "

The thrust of the blog post was the stylistic question of whether to
use <- or = for assignment, not a recommendation to use constructs
like this.  (In fact, the next line reads "This is a contrived example
though, and never really occurs in real-world programming.")  But I've
added your sound advice that such constructs are best avoided. I've
never seen the need to perform assignments in function calls before,
but I'll avoid them now knowing about potential for mischief from lazy
evaluation. Thanks.


# David Smith

David M Smith <david at revolution-computing.com>
Director of Community, REvolution Computing www.revolution-computing.com
Tel: +1 (206) 577-4778 x3203 (Seattle, USA)

More information about the R-help mailing list