Re: [R] assign / environment side effect on R 2.4.0

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Mon 26 Jun 2006 - 21:00:39 EST

Please do study the posting guide, as there is no `R 2.4.0'.

This seems to be related to the NEWS item

     o	[[ on a list does not duplicate the extracted element unless
 	necessary.  (It did not duplicate in other cases, e.g. a
 	pairlist.)

Now in so far as I can follow it, in your example [[ behaves in the same way as $ always did (which is what informed people would expect).

R-help is not the place to discuss unreleased versions of R, nor for questions about code development. (Did I mention studying the posting guide?)

On Fri, 23 Jun 2006, Thomas Petzoldt wrote:

> Sorry,
>
> the posted example had the side effect on all platforms (correctly: R
> 2.2.1/Windows, 2.3.1/Linux, 2.4.0/Windows), but in the following
> corrected example the behavior of 2.4.0 differs from the older versions.
>
> The only difference between the "wrong" and the "new" example is
> L[["test"]] vs. L$test in the assign.
>
> Thomas P.
>
>
> envfun <- function(L) {
> # L <- as.list(unlist(L))
> p <- parent.frame()
> assign("test", L[["test"]], p) ## [["test"]] instead of $test
> environment(p[["test"]]) <- p
> }
>
>
> solver <- function(L) {
> envfun(L)
> # some other stuff
> }
>
> L <- list(test = function() 1 + 2)
>
> e1 <- environment(L$test)
> solver(L)
> e2 <- environment(L$test)
>
> print(e1)
> print(e2)
>
> ______________________________________________
> 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
>

-- 
Brian D. Ripley,                  ripley@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

______________________________________________
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 Jun 27 00:35:22 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 27 Jun 2006 - 02:12:46 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.