[R] I don't understand this

Richard A. O'Keefe ok at cs.otago.ac.nz
Tue Sep 2 07:12:14 CEST 2003


For reasons which I'll spare you, I'm writing a program to analyse
R source code.  This has led me to probe some of the darker corners
of R syntax to find out what is supposed to happen.

Now, from reading the R documentation (and the New S book &c) I know
perfectly well that
    f(a, b, etc) <- x
is supposed to turn into
    a <- "f<-"(a, b, etc, value=x)

Except, what if f is not an identifier or string?
What, for example, should _this_ do?

> x <- NULL
> (if (TRUE) names else dim)(x) <- 27

I was expecting _either_ that I would be told that you can't
set names(NULL) to 27, _or_ that I would be told the whole thing
wasn't allowed.

In fact, it was allowed.

> x
[1] 27

This result has me completely baffled.

Is this behaviour intentional?
What rules does it follow from?
What _exactly_ are the rules for assignment supposed to be _in R_?

The emphasis on _in R_ is because I know the New S book spells out
a lot of detail, but (a) I've been searching for my copy for a couple
of weeks and (b) R is not _exactly_ the same as S.




More information about the R-help mailing list