[Rd] Activating a Regular Binding
Gabriel Becker
gmbecker at ucdavis.edu
Thu Apr 7 01:20:18 CEST 2011
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
More information about the R-devel
mailing list