Skip to content

Changes to environments in R-devel

2 messages · Duncan Murdoch, Brian Ripley

#
I've just committed some changes to R-devel which affect environments. 
Specifically:

  - using NULL as an environment is now deprecated:  use baseenv() 
instead.  (baseenv() is already available in R 2.2.0, where it returns 
NULL.  For most purposes it retains the same meaning in R-devel.) If you 
do use NULL, it will be converted to baseenv(), and a warning printed. 
For example:

 > f <- function(x) 1
 > environment(f) <- NULL
Warning message:
use of NULL environment is deprecated
 > environment(f)
<environment: base>

There may be some places where I've missed putting the conversion in 
place, and use of NULL will cause an error; please let me know if you 
find any of those.  The intention is that NULL will be usable with 
warnings through to the end of the 2.3.x releases.

  - baseenv() is no longer its own parent.  Its parent is an empty 
environment, available as emptyenv().

  - You can now create your own environment with emptyenv() as its 
parent.  Searches for variables in such an environment will not 
automatically proceed to baseenv(), as searches do in current R releases.

Duncan Murdoch
#
As a followup, these changes have some impacts on already installed 
packages, most likely including all those using lazy-loading or saved 
images.

If you are building from a checked-out version of R you will need to 
trigger re-installation of the recommended packages.  Unix users can do 
that by

    rm src/library/Recommended/*.ts
    make

but Windows users will best do 'make distclean; make all recommended' as a 
clean is needed.

One way to re-install all other packages is
at least if you have them all in the main library tree or all in one 
additional tree.  Doing it from within R ensures that the dependency order 
is maintained.  If like me you have almost all CRAN packages installed 
that will take quite a while.

Note that re-installing binary packages under Windows and MacOS X will not 
be effective until the repositories have been rebuilt.
On Thu, 3 Nov 2005, Duncan Murdoch wrote: