[R] I don't understand this
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Sep 2 07:34:08 CEST 2003
On Tue, 2 Sep 2003, Richard A. O'Keefe wrote:
> 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.
Error: couldn't find function " <-"
! (On some systems I get a set of non-printable chars in there.)
What I would have expected is that it tried to find "(<-" and failed, as
> x <- 3
> (names(x)) <- 27
Error: couldn't find function "(<-"
(and S does essentially that in your example).
> In fact, it was allowed.
> > x
>  27
> This result has me completely baffled.
Not reproducible, either.
> 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.
And for R you have the source code, and a `R Language Definition'.
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help