Skip to content

locked environments

2 messages · William Dunlap, Luke Tierney

#
Shouldn't the following 4 ways to alter an object in a locked environment
either all work or all fail?  (All working would be nice, I think.)

   E <- new.env()
   assign("var", c(1,2,3,4), envir=E)
   lockEnvironment(E, bindings=FALSE)
   E$var[1] <- 101 ; E$var
   #[1] 101   2   3
   local(var[2] <- 102, envir=E)
   #Error in eval(expr, envir, enclos) :
   #  cannot add bindings to a locked environment
   with(E, var[3] <- 103)
   #Error in eval(expr, envir, enclos) :
   #  cannot add bindings to a locked environment
   eval(quote(var[4] <- 104), envir=E)
   #Error in eval(expr, envir, enclos) :
   #  cannot add bindings to a locked environment
   get("var", envir=E)
   #[1] 101   2   3   4


Bill Dunlap
TIBCO Software
wdunlap tibco.com
1 day later
#
Ideally they should all work. What is happening is that the current
implementation of complex assignment wants to use a temporary variable
named *tmp*, which it can't when the evaluation environment is locked.
Assignments in compiled code use a different mechanism that I hope
will eventually be ported to the interpreter. Then these should all
work.

Best,

luke
On Wed, 20 Apr 2016, William Dunlap via R-devel wrote: