[Rd] unlockEnvironment()?

Tierney, Luke luke-tierney @ending from uiow@@edu
Wed Oct 10 19:31:05 CEST 2018


On Wed, 10 Oct 2018, William Dunlap via R-devel wrote:

> R lets one lock an environment with both an R function,
> base::lockEnvironment, and a C function, R_LockEnvironment, but, as far as
> I can tell, no corresponding function to unlock an environment.  Is this
> omission on principle or just something that has not been done yet?

Absolutely on principle!

Best,

luke

>
> I ask because several packages, including the well-used R6 and rlang
> packages, fiddle with some bits in with SET_ENVFLAGS and ENVFLAGS to unlock
> an environment.  (See grep output below.)
>
> About 5000 (1/3 of CRAN) packages depend on R6 or rlang.  Should R supply a
> more disciplined way of unlocking an environment?
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
> $ { find . -type f -print0 | xargs -0 grep -n -C 2 ENVFLAGS ; } 2>/dev/null
> ./R6/tests/manual/encapsulation.R-5-unlockEnvironment <-
> cfunction(signature(env = "environment"), body = '
> ./R6/tests/manual/encapsulation.R-6-  #define FRAME_LOCK_MASK (1<<14)
> ./R6/tests/manual/encapsulation.R:7:  #define FRAME_IS_LOCKED(e)
> (ENVFLAGS(e) & FRAME_LOCK_MASK)
> ./R6/tests/manual/encapsulation.R:8:  #define UNLOCK_FRAME(e)
> SET_ENVFLAGS(e, ENVFLAGS(e) & (~ FRAME_LOCK_MASK))
> ./R6/tests/manual/encapsulation.R-9-
> ./R6/tests/manual/encapsulation.R-10-  if (TYPEOF(env) == NILSXP)
> ./BMA/R/iBMA.glm.R-21-*/
> ./BMA/R/iBMA.glm.R-22-#define FRAME_LOCK_MASK (1<<14)
> ./BMA/R/iBMA.glm.R:23:#define FRAME_IS_LOCKED(e) (ENVFLAGS(e) &
> FRAME_LOCK_MASK)
> ./BMA/R/iBMA.glm.R:24:#define UNLOCK_FRAME(e) SET_ENVFLAGS(e, ENVFLAGS(e) &
> (~ FRAME_LOCK_MASK))
> ./BMA/R/iBMA.glm.R-25-'
> ./BMA/R/iBMA.glm.R-26-
> --
> ./BMA/R/iBMA.surv.R-22-*/
> ./BMA/R/iBMA.surv.R-23-#define FRAME_LOCK_MASK (1<<14)
> ./BMA/R/iBMA.surv.R:24:#define FRAME_IS_LOCKED(e) (ENVFLAGS(e) &
> FRAME_LOCK_MASK)
> ./BMA/R/iBMA.surv.R:25:#define UNLOCK_FRAME(e) SET_ENVFLAGS(e, ENVFLAGS(e)
> & (~ FRAME_LOCK_MASK))
> ./BMA/R/iBMA.surv.R-26-'
> ./BMA/R/iBMA.surv.R-27-
> ./pkgload/src/unlock.c-20-*/
> ./pkgload/src/unlock.c-21-#define FRAME_LOCK_MASK (1 << 14)
> ./pkgload/src/unlock.c:22:#define FRAME_IS_LOCKED(e) (ENVFLAGS(e) &
> FRAME_LOCK_MASK)
> ./pkgload/src/unlock.c:23:#define UNLOCK_FRAME(e) SET_ENVFLAGS(e,
> ENVFLAGS(e) & (~FRAME_LOCK_MASK))
> ./pkgload/src/unlock.c-24-
> ./pkgload/src/unlock.c-25-extern SEXP R_TrueValue;
> ./SOD/src/tmp.cpp-11394-SEXP (ENCLOS)(SEXP x);
> ./SOD/src/tmp.cpp-11395-SEXP (HASHTAB)(SEXP x);
> ./SOD/src/tmp.cpp:11396:int (ENVFLAGS)(SEXP x);
> ./SOD/src/tmp.cpp:11397:void (SET_ENVFLAGS)(SEXP x, int v);
> ./SOD/src/tmp.cpp-11398-void SET_FRAME(SEXP x, SEXP v);
> ./SOD/src/tmp.cpp-11399-void SET_ENCLOS(SEXP x, SEXP v);
> --
> ./SOD/src/tmp.h-11393-SEXP (ENCLOS)(SEXP x);
> ./SOD/src/tmp.h-11394-SEXP (HASHTAB)(SEXP x);
> ./SOD/src/tmp.h:11395:int (ENVFLAGS)(SEXP x);
> ./SOD/src/tmp.h:11396:void (SET_ENVFLAGS)(SEXP x, int v);
> ./SOD/src/tmp.h-11397-void SET_FRAME(SEXP x, SEXP v);
> ./SOD/src/tmp.h-11398-void SET_ENCLOS(SEXP x, SEXP v);
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:   luke-tierney using uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu



More information about the R-devel mailing list