[Rd] (PR#1556)

Mark.Bravington@csiro.au Mark.Bravington@csiro.au
Thu, 16 May 2002 08:48:29 +0200 (MET DST)


lib.fixup

My previous post mentions a problem encountered when calling ".Internal(
lib.fixup..." in R1.5.0. I have since found a workaround. It's possible in
R1.5.0 to set attributes of search path environments directly, like so:

> env_ pos.to.env( 3)
> attr( env, 'any.attr')_ 'any.value'
> pos.to.env( 3)
<environment: package:tcltk>
attr(,"name")
[1] "package:tcltk"
attr(,"path")
[1] "C:/R/rw1050/library/tcltk"
attr(,"any.attr")
[1] "any.value"

In R1.3.1, it used to be necessary to use lib.fixup to achieve this. It's
still not possible to call

> attr( pos.to.env( 3), 'any.attr')_ 'any.value'

directly, but this doesn't matter. My (mis-typed) wish-lish-suggestion in
the last post, is therefore irrelevant, and personally I no longer need
lib.fixup. NB that it can still cause problems if it is used-- but as it's
undocumented, I don't suppose this will be a major issue.

Nevertheless, calls to ".Internal( lib.fixup..." are not things of beauty,
and I wonder whether the current usage in "library" is actually necessary?
The code currently reads

            loadenv <- new.env(hash = TRUE, parent = .GlobalEnv)
            <<...>>
                sys.source(codeFile, loadenv, keep.source = keep.source)
            <<...>>
            env <- attach(NULL, name = pkgname)
            on.exit(do.call("detach", list(name = pkgname)))
            attr(env, "path") <- file.path(which.lib.loc, package)
            .Internal(lib.fixup(loadenv, env))
            
but I seem to get satisfactory results with

      env_ attach( NULL, name = pkgname)
      on.exit(do.call("detach", list(name = pkgname)))            
      attr( env, "path") <- file.path(which.lib.loc, package)
      <<...>>
          sys.source(codeFile, env, keep.source = keep.source) # i.e.
straight into "env" not into "loadenv"
      <<...>>
      
which does away with the calls to "new.env" and "lib.fixup". As far as I can
see, the "parent=.GlobalEnv" argument to "new.env" doesn't have any effect
after "lib.fixup"; I'm not sure about the "hash=TRUE".

cheers
Mark

*******************************

Mark Bravington
CSIRO (CMIS)
PO Box 1538
Castray Esplanade
Hobart
TAS 7001

phone (61) 3 6232 5118
fax (61) 3 6232 5012
Mark.Bravington@csiro.au 

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._