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

From: Henrik Bengtsson <hb_at_stat.berkeley.edu>
Date: Mon, 17 Sep 2007 21:32:31 -0700


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



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 18 Sep 2007 - 04:40:51 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 18 Sep 2007 - 10:41:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.