[Rd] Activating a Regular Binding

From: Gabriel Becker <gmbecker_at_ucdavis.edu>
Date: Wed, 06 Apr 2011 16:20:18 -0700


Greeting R-devel,

I find myself wanting to attach an active binding to an existing object in the global environment (R 2.12.2), but there doesn't seem to be an easy way to do this:

> x = 5
> makeActiveBinding("x", function(d) "hi", .GlobalEnv)
Error in makeActiveBinding("x", function(d) "hi", .GlobalEnv) :   symbol already has a regular binding

Now I can get around this with some fancy assignment, but this seems ugly and underhanded:

> x = 5
> y = x
> rm(x)
> makeActiveBinding("x", function(d) print("hi"), .GlobalEnv)
> x = y

[1] "hi"

So my question is: is there a legitimate way to do this?

Thanks,
Gabe

P.S. sessionInfo:

> sessionInfo()

R version 2.12.2 (2011-02-25)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:

 [1] LC_CTYPE=en_US.utf8       LC_NUMERIC=C
 [3] LC_TIME=en_US.utf8        LC_COLLATE=en_US.utf8
 [5] LC_MONETARY=C             LC_MESSAGES=en_US.utf8
 [7] LC_PAPER=en_US.utf8       LC_NAME=C
 [9] LC_ADDRESS=C              LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached): [1] tools_2.12.2

--
Gabriel Becker
Graduate Student
Statistics Department
University of California, Davis

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Wed 06 Apr 2011 - 23:23:59 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 07 Apr 2011 - 08:50:41 GMT.

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

list of date sections of archive