[ESS] environment creation in .load.R - older R versions

Vitalie Spinu spinuvit at gmail.com
Fri May 9 19:04:23 CEST 2014


The reason is that we need the enclosing environment to be different in
different versions.  Martin made it work with R's as old as 0.92. So, I
would be wary on any attempt to improve things over there. Just Let it
be.

  Vitalie

 >>> Rainer M Krug on Fri, 09 May 2014 14:54:41 +0200 wrote:

 > Hi

 > I am trying to use R environments for storing org variables, and I am
 > looking at the code in .load.R. I am wondering abput the different R
 > versions.

 > For very old R versions, attach(NULL, name="ESSR") is used to create the
 > environment, and for other versions new.env(). But the attach(NULL,
 > name="ESSR") also works in the newest R - why is it not used for all R
 > versions?

 > ,----
 > |     ESSR <-
 > |         if(oldR) ## really old library() revert order a bit
 > |             attach(NULL, name = "ESSR")
 > |         else if(length(nn <- names(formals(new.env))) && any(nn == "parent"))
 > |             new.env(parent =
 > |                     if(Rver >= "1.9.0") getNamespace("utils")
 > |                     else .BaseNamespaceEnv)
 > |         else
 > |             new.env()
 > `----

 > If this is the case, I assume that the following code could also be simplified?

 > ,----
 > |     if(Rver >= "2.4.0")
 > |         attach(ESSR)
 > |     else if(!oldR) { ## borrow from older library()
 > |         e <- attach(NULL, name = "ESSR")
 > |         .Internal(lib.fixup(ESSR, e))
 > |     } else { ## if(oldR), use as in that old library():
 > |         .Internal(lib.fixup(ESSR, .GlobalEnv))
 > |     }
 > `----

 > Cheers,

 > Rainer



More information about the ESS-help mailing list