[R] R is GNU S, not C.... [was "how to get or store ....."]

Martin Maechler maechler at stat.math.ethz.ch
Thu Dec 8 08:46:44 CET 2005


>>>>> "DeepS" == Deepayan Sarkar <deepayan.sarkar at gmail.com>
>>>>>     on Wed, 7 Dec 2005 19:15:52 -0600 writes:

    DeepS> On 12/7/05, Jan T. Kim <jtk at cmp.uea.ac.uk> wrote:
    >> On Tue, Dec 06, 2005 at 04:21:01PM +0000, Patrick Burns wrote:
    >> > I don't put in extraneous ';' because I maybe get a
    >> > blister on my little finger.
    >> >
    >> > I suspect that those who find the semi-colons ugly in
    >> > R do not find them ugly in C.  I think the reason there
    >> > would be a visceral reaction  in R but not in C is that
    >> > there is a danger when using them in R that they really
    >> > mean something.
    >> >
    >> > We get questions on R-help often enough about why
    >> > code like:
    >> >
    >> > if(x > 0) y <- 4
    >> > else y <- 4.5e23
    >> >
    >> > doesn't work.
    >> >
    >> > If people habitually used semi-colons, those sorts of
    >> > questions would probably multiply.
    >> 
    >> I don't understand. It would seem to me that in
    >> 
    >> if (x > 0) y <- 4;
    >> else y <- 4.5e23;
    >> 
    >> it's pretty obvious that the "if" statement is terminated by the
    >> semicolon at the end of the first line and that therefore, the "else"
    >> on the next line is erroneous because it is not associated with any
    >> "if".

    DeepS> Why is it obvious?

    DeepS>    if (x > 0) y = 4;
    DeepS>    else y = 4.5e23;

    DeepS> is perfectly legal C.

Very good!  I'm glad we got here,  namely back to the original
subject, and now have seen a nice example of why it can be a bad
idea to maltreat the S language by extraneous ";" ..

    >> At least, the version above fails consistently, i.e. regardless of
    >> context.

    DeepS> It fails for unrelated reasons.

    DeepS> if (x > 0) { y <- 4; } else { y <- 4.5e23; }

    DeepS> doesn't fail.

    DeepS> -Deepayan

Thank you, Deepayan, Brian,
and all the others "in the knowning" who hadn't lost patience with
this thread yet... ;-) 
Martin

    >> On the other hand, I've studied the R Language Definition for
    >> quite some time before fully understanding why
    >> 
    >> if (x > 0) y <- 4
    >> else y <- 4.5e23
    >> 
    >> works inside of a function (or other enclosing block) while it does not
    >> work interactively (or at the top level of a script).
    >> 
    >> Best regards, Jan
    >> --
    >> +- Jan T. Kim -------------------------------------------------------+
    >> |             email: jtk at cmp.uea.ac.uk                               |
    >> |             WWW:   http://www.cmp.uea.ac.uk/people/jtk             |
    >> *-----=<  hierarchical systems are for files, not for humans  >=-----*




More information about the R-help mailing list