From ggrothendieck at gmail.com  Tue Sep  6 07:52:36 2005
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Tue, 6 Sep 2005 01:52:36 -0400
Subject: [Rd] Problem in R 2.2.0 with environments and [
In-Reply-To: <971536df05090520486999efd6@mail.gmail.com>
References: <971536df05090520486999efd6@mail.gmail.com>
Message-ID: <971536df05090522523ea9f109@mail.gmail.com>

Sorry. I think this "problem" was actually the same one as my previous
post where I set my library path wrong.  Once I set it correctly both
versions worked fine.

On 9/5/05, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
> I have found a problem with R 2.2.0 under Windows XP.
> 
> Under R 2.1.1 patched I get the following result as expected.  First
> we define a function f which displays the names of its arguments,
> rather than their values.  We define a variable x whose value
> is an environment and whose class is c("x", "environment").
> f(x, x) then gives the expected result of "x" and "x".  If,
> if we assign f to "[.x" then x[x] also gives "x" and "x" as
> expected under R 2.1.1 patched but _not_ under R 2.2.0.
> 
> First we show it under R 2.1.1 where everything works as expected:
> 
> > f <- function(x, y) { print(deparse(substitute(x))); print(deparse(substitute(y))) }
> > x <- .GlobalEnv
> > class(x) <- c("x", "environment")
> > f(x, x)
> [1] "x"
> [1] "x"
> > "[.x" <- f
> > x[x]  ########## this is what we would have expected so its ok
> [1] "x"
> [1] "x"
> >
> > R.version.string
> [1] "R version 2.1.1, 2005-06-23"
> 
> Now lets repeat the above under R 2.2.0 and we see that f(x,x)
> works as expected but not x[x] even though   "[.x" has set to equal f.
> Unlike the situation in R 2.1.1 now f(x,x) and x[x] give
> different results even though "[.x" was set to equal f.
> 
> > f <- function(x, y) { print(deparse(substitute(x))); print(deparse(substitute(y))) }
> > x <- .GlobalEnv
> > class(x) <- c("x", "environment")
> > f(x, x)
> [1] "x"
> [1] "x"
> > ################# now x[x] and f(x,x) should give same result
> > "[.x" <- f
> > x[x]  ####################### does not give the same as f(x,x)
> [1] "<environment>"
> [1] "<environment>"
> >
> > R.version.string
> [1] "R version 2.2.0, 2005-09-03"
>



[Rd] Problem in R 2.2.0 with environments and [
Gabor Grothendieck