[R] Re: assigning with operator '='.

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Wed May 22 17:00:15 CEST 2002


Rolf Turner <rolf at math.unb.ca> writes:

> I've just checked out Jens Oehlschlgel's posting as regards assigning
> with the ``='' operator.  Yep, the phenomenon described really does
> happen.  And yep, it sure seems ***very*** dangerous to me.
> 
> Mind you, using ``='' as the assignment operator strikes me as being
> dangerous anyhow.  Bad design decision by the S people (by John
> Chambers?) and R should ***not*** have followed suit, compatibility
> or no compatibility.
> 
> The best workaround for the problem raised by Jens is
> 
> 	***NEVER NEVER NEVER*** use ``='' as
> 	the assigment operator.
> 
> But the R core team should take steps to get rid of this behaviour
> (or better still, get rid of ``='' as assignment!!!).

Well, we haven't exactly advertised it very much... Mainly, it is
there because it is used in some books (John's green one, notably) and
it's nice to allow people to use it with R. You're not allowed to use
it in while and if conditions, so the danger is limited, but if you
insist on goofing, you can do

 a = (b = 3) + 1

when you intended

 a = (b == 3) + 1

but then again you can also do

t.sim <- simulation.that.runs.for.hours()
sum(t.sim>1.96)
sum(t.sim<-1.96)

as I suspect everyone has done at some point....

The subassignment behaviour is surely a bug, although not easily
spotted.

do_set has

    switch (PRIMVAL(op)) {
    case 1: case 3:                                     /* <-, = */
    ...

so clearly the intention is that they are the same, but the "op" is
getting passed down into somewhere where it matters, obviously...


-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list