From hb at stat.berkeley.edu  Tue Sep 18 06:32:31 2007
From: hb at stat.berkeley.edu (Henrik Bengtsson)
Date: Mon, 17 Sep 2007 21:32:31 -0700
Subject: [Rd] Re-attaching a package environment drops the attributes
Message-ID: <59d7961d0709172132t24cb9a87q36c7a9319c19a1f0@mail.gmail.com>

Hi.

contrary to other environments, the attributes of a *package*
environment are dropped (from the new environment) when attach():ing
it to the search() path.  This might or might not be surprising, but
have some side effects if rearranging/attaching package environments.

# Example - Regular environments
env <- new.env()
attr(env, "foo") <- "bar"
print(env)
## <environment: 0x023f3128>
## attr(,"foo")
## [1] "bar"
attach(env, pos=2, name="foo", warn.conflicts=FALSE)
env2 <- as.environment("foo")
print(env2)
## <environment: 0x023f44c4>
## attr(,"name")
## [1] "foo"

# Example - Package environments
env <- as.environment("package:utils")
attr(env, "foo") <- "bar"
print(env)
## <environment: package:utils>
## attr(,"name")
## [1] "package:utils"
## attr(,"path")
## [1] "C:/PROGRA~1/R/R-2.6.0alpha/library/utils"
## attr(,"foo")
## [1] "bar"
attach(env, pos=2, name="package:utils2", warn.conflicts=FALSE)
env2 <- as.environment("package:utils2")
print(env2)
## <environment: package:utils2>
## attr(,"name")
## [1] "package:utils2"

This becomes a problem, because the 'path' attribute is dropped causing:

packageDescription("utils2")
## Error in if (pkgpath == "") { : argument is of length zero
sessionInfo()
## Error in if (pkgpath == "") { : argument is of length zero

Again, this might or might not expected.

Finally:

> sessionInfo()
R version 2.6.0 alpha (2007-09-14 r42843)
i386-pc-mingw32

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

Cheers

Henrik



[Rd] Re-attaching a package environment drops the attributes
Henrik Bengtsson