[R] difference between <- and =

Richard A. O'Keefe ok at cs.otago.ac.nz
Mon Sep 1 04:49:00 CEST 2003


Levi Larkey <larkey at mail.utexas.edu> wrote:

a perfect illustration of why allowing "=" as an alternative
spelling for "<-" was always an obviously really bad idea.

	Is there any reason for using one operator over the other outside of 
	function definitions and calls?

You should never use "=" for assignment unless you are suffering such
severe "C" withdrawal symptoms that the doctor just had to give you a
shot to calm you down.  It is best to keep different symbols for
different purposes.  (I note that Ada uses ":=" for assignment and
"=>" for keyword arguments.)

Something that would be quite useful would be an option asking R to
warn you
    - if you have any assignment operator in a function argument
      (thanks to lazy evaluation this probably *won't* do what you
      expect)
    - if you have "=" anywhere except for binding a name to an argument.
Perhaps these could be two options.




More information about the R-help mailing list