Playing with Binding and Environment Adjustments in R , we have this 3 functions:
lockEnvironment(env)
locks env so you can't add a new symbol to env.
lockBinding(sym, env)
locks the sym within env so you can't modfiy it
unlockBinding(sym, env)
relax the latter lock.
But how can I Unlock the environment? Maybe I miss something but it looks like R don't expose an unlockEnvironment
function or equivalent mechanism to unlock the env ? Is there some design reason to this?
Here an example of how to use this functions:
e <- new.env()
lockEnvironment(e)
get("x",e)
assign("x",2,envir=e)
lockBinding("x", e)
get("x",e)
unlockBinding("x", e)
assign("x",3,envir=e)
## how to relese e lock?
unlockEnvironment(e) ## the function doesn't exist
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…