[R-pkg-devel] Puzzled about "locked environments".

Rolf Turner r@turner @ending from @uckl@nd@@c@nz
Mon Jul 9 00:57:46 CEST 2018


Recently I experimented with assigning a variable within the environment 
of a function in a package that I am developing.  Slightly more explicitly:

In a function "foo()" in the package, I have lines like:

    big <- 42
    assign("big",big,envir=environment(bar))

where "bar()" is another function in the package.

This causes an error to be thrown:

> Error in assign("big", big, envir = environment(bar)) : 
>   cannot add bindings to a locked environment

The reason that I am puzzled about this is that I used this syntax 
repeatedly in my CRAN package "AssetPricing".  In this latter package 
the syntax seems to work flawlessly.  No errors are thrown.  No mention 
of "locked environments".

Why would environments get "locked" in the package that I am currently 
fooling about with, but not in the AssetPricing package?  Is there 
anything that I  can do to keep environments from getting "locked"?

Can anyone suggest where I should start looking for differences in the 
nature of the two packages?

I could possibly give more detail, but I have no idea as to what might 
be relevant.

One difference is that AssetPricing involves no dynamically loaded 
Fortran code, whereas the package that I am currently fooling about with 
*does* involve such code.  (But neither "foo()" not "bar()" make direct 
calls to .Fortran().)

Grateful for any insights.

cheers,

Rolf Turner

-- 
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276



More information about the R-package-devel mailing list