[R] I don't understand this

Thomas Lumley tlumley at u.washington.edu
Tue Sep 2 16:10:32 CEST 2003

On Tue, 2 Sep 2003, Richard A. O'Keefe wrote:

> I asked what
> > x <- NULL
> > (if (TRUE) names else dim)(x) <- 27
> is *supposed* to do.
> Professor Brian Ripley basically gave me the answer I wanted:
> it isn't *supposed* to do anything.  However, he went on to say
> 	And for R you have the source code, and a `R Language Definition'.
> My original message made it clear that I had read the R documentation.
> I am very favourably impressed by it; compared with many commercial
> systems it is *superb*.  However, the R Language Definition is not
> finished yet and does not discuss assignment at length.  In fact,
> remarks on assignment are scattered thinly throughout the text, at
> least one appears to have "right" when it means "left".  That's OK;
> it doesn't claim to be finished documentation, but it does mean that
> some questions cannot as yet be answered by reading it.

> As for the code (src/main/eval.c), it tells you want DOES happen (if you
> are considerably more familiar with R internals than I am yet), but with
> R's characteristic paucity of comments, it says nothing about what is
> *supposed* to happen.

Yes. Unfortunately these questions probably can't be answered any other
way, either.  If something isn't discussed in the language definition or
the FAQ there may simply be no facts about what the intended behaviour is.
The issue may never have been considered, especially in cases where the S
language definition is not clear.

In the particular case you suggested I am reminded of one of Steve
Summit's postings about undefined behaviour in comp.lang.c.

     Yet for most of the 15 years I've been programming in C, I
     simply could not have told you why i=i++ is undefined.
     It's an ugly expression; it's meaningless to me; I don't know what it
     does; I don't want to know what it does; I'd never write it; I
     don't  understand why anyone would write it; it's a mystery to me why
     anyone cares what it does; if I ever encountered it in code I was
     maintaining,  I'd rewrite it.

I would have said that the behavior of
   (if (cond) names else dim)(x) <- 10
is undefined in the S language, along with things like the order of
evaluation of the apply functions.


More information about the R-help mailing list