[Rd] Active bindings in attached environments

From: Jeff Horner <jeff.horner_at_vanderbilt.edu>
Date: Thu, 05 Nov 2009 09:41:31 -0600


Hi,

I was wondering if this is expected behavior for active bindings in attached environments, or if this is a bug:

> e <- new.env()
> makeActiveBinding('x',function() 'foo',e)
> ls(e)
[1] "x"
> attach(e)
> search()

[1] ".GlobalEnv"        "e"                 "package:graphics"
[4] "package:grDevices" "package:datasets"  "package:utils"
[7] "package:methods"   "Autoloads"         "package:base"

> x

function() 'foo' # Should this print 'foo' ?

This works as I would expect:

> with(e,x)

[1] "foo"

but this doesn't:

> f <- function() x
> f()
function() 'foo'

However, changing the environment of f does:

> environment(f) <- e
> f()
[1] "foo"

Jeff



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 05 Nov 2009 - 19:57:39 GMT

This archive was generated by hypermail 2.2.0 : Thu 05 Nov 2009 - 20:10:20 GMT