Rev 16763 | Rev 38586 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{bindenv}\title{Binding and Environment Adjustments}\usage{lockEnvironment(env, bindings = FALSE)environmentIsLocked(env)lockBinding(sym, env)unlockBinding(sym, env)bindingIsLocked(sym, env)makeActiveBinding(sym, fun, env)bindingIsActive(sym, env)}\alias{bindenv}\alias{lockEnvironment}\alias{environmentIsLocked}\alias{lockBinding}\alias{unlockBinding}\alias{makeActiveBinding}\alias{bindingIsLocked}\alias{bindingIsActive}\arguments{\item{env}{an environment.}\item{bindings}{logical specifying whether bindings should be locked.}\item{sym}{a name object or character string}\item{fun}{a function taking zero or one arguments}}\description{These functions represent an experimental interface for adjustmentsto environments and bindings within environments. They allow forlocking environments as well as individual bindings, and for linkinga variable to a function.}\details{The function \code{lockEnvironment} locks its environment argument,which must be a proper environment, not NULL. Locking the NULL(base) environment may be supported later. Locking the environmentprevents adding or removing variable bindings from the environment.Changing the value of a variable is still possible unless the bindinghas been locked.\code{lockBinding} locks individual bindings in the specifiedenvironment. The value of a locked binding cannot be changed.Locked bindings may be removed from an environment unless theenvironment is locked.\code{makeActiveBinding} installs \code{fun} so that getting thevalue of \code{sym} calls \code{fun} with no arguments, and assigningto \code{sym} calls \code{fun} with one argument, the value to beassigned. This allows things like C variables linked to R variablesand variables linked to data bases to be implemented. It may alsobe useful for making thread-safe versions of some system globals.}\examples{# locking environmentse<-new.env()assign("x",1, env=e)get("x",env=e)lockEnvironment(e)get("x",env=e)assign("x",2, env=e)try(assign("y",2, env=e)) # error# locking bindingse<-new.env()assign("x",1, env=e)get("x",env=e)lockBinding("x", e)try(assign("x",2, env=e)) # errorunlockBinding("x", e)assign("x",2, env=e)get("x",env=e)# active bindingsf<-local({x <- 1function(v) {if (missing(v))cat("get\n")else {cat("set\n")x <<- v}x}})makeActiveBinding("fred", f, .GlobalEnv)bindingIsActive("fred", .GlobalEnv)fredfred<-2fred}\keyword{internal}\author{Luke Tierney}