[Rd] Problem in R 2.2.0 with environments and [

Gabor Grothendieck ggrothendieck at gmail.com
Tue Sep 6 05:48:42 CEST 2005


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"



More information about the R-devel mailing list