Re: [R] problem in my code

From: Thomas Lumley <tlumley_at_u.washington.edu>
Date: Tue 11 Jul 2006 - 00:37:07 EST

On Mon, 10 Jul 2006, Gabor Grothendieck wrote:

> The problem can be reduced to this:
>
> x <- 1
> x[1] <<- 2 # error
>
> The following are ok:
>
> x <- 1
> x[1] <- 3
>
> x <- 1
> x <- 4
>
> x <- 1
> x <<- 5
>
> Does anyone know why? Is this a bug in <<- ?

No, it's a feature. The fact that x<<-5 works is arguably a bug (though probably not worth fixing).

x[1] <<- 2 is equivalent (per section 3.4.4 of the language guide) to

`*tmp*` <- get("x", envir=parent.env(), inherits=TRUE)
`*tmp*`[1] <- 2
x <<- `*tmp*`

and the get() fails when you try to do this from the command line. Since the point of superassignment is to assign in a lexical parent environment it makes no sense to do it directly at the command line.

         -thomas

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley@u.washington.edu	University of Washington, Seattle

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Jul 11 00:46:29 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 11 Jul 2006 - 02:15:51 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.