[R] Evaluating Assignment-Operator R 2.0.0
Prof Brian Ripley
ripley at stats.ox.ac.uk
Fri Oct 8 12:06:46 CEST 2004
On Fri, 8 Oct 2004, friedemann wrote:
> Dear Helpers,
> in which way I have to use the assignment-operator evaluating left to right
> with R 2.0.0?
<- is the operator you should normally use.
> With R 2.0.0 (w2k-installation) the "superassignment" operator '<<-' seems to
> have a different behaviour compared with R 1.9.1 :
> > x<<-4
> > x
>  4
> > attr(x,'y')<<-5
> Error: Object "x" not found
> Using earlier versions of R I never got this error.
> In the NEWS file and the docs coming along with R 2.0.0 I did not found
> anything concerning this problem.
Did you not notice NEWS contains
o Complex superassignments were wrong when a variable with the same
name existed locally, and were not documented in R-lang.
> AFAIK '=' instead of '<<-' works - but is allowed only for toplevel-
= is allowed almost everywhere <- is, and not just at top-level.
I don't know what you are really trying to do, but
x <- 4
testit <- function() attr(x,'y') <<- 5
works as documented, and that is the normal type of usage of
superassignments. As the NEWS entry says, R-lang (`The R Language
Definition') gives fuller details (and I guess the help page for <<-
should point there).
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