[Rd] Problem loading package with version, S4 classes and NAMESPACE

Roger Bivand Roger.Bivand at nhh.no
Fri Jan 20 19:41:20 CET 2006


I've run into a problem that I hope has an obvious solution. The sp 
package uses S4 classes and has a NAMESPACE, and when installed without 
package versions, runs OK, passes R CMD check, and so on.

A user reported that he installed it  --with-package-versions, and that 
from then on it would fail at first use of a class defined in the package.

I've reconstructed the problem in a skeletal package:

http://reclus.nhh.no/R/etc/S4nswv_0.1-1.tar.gz

which when installed without versions works:

$ R CMD INSTALL S4nswv
$ R
...
> library(S4nswv)
> sessionInfo()
R version 2.2.1, 2005-12-20, i686-pc-linux-gnu 

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

other attached packages:
 S4nswv 
"0.1-1" 
> xyd <- new("xyloc", x=runif(20), y=runif(20))
> xyd
               x           y         res
 [1,] 0.01589694 0.935594239 -0.91969730
 [2,] 0.56974225 0.120906481  0.44883577
...

but fails after INSTALL --with-package-versions S4nswv

> library(S4nswv)
> sessionInfo()
R version 2.2.1, 2005-12-20, i686-pc-linux-gnu 

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

other attached packages:
S4nswv_0.1-1 
     "0.1-1" 
> xyd <- new("xyloc", x=runif(20), y=runif(20))
Error in as.environment(pkg) : no item called "package:S4nswv" on the 
search list
Error in initialize(value, ...) : S language method selection got an error 
when called from internal dispatch for function 'initialize'
> traceback()
2: initialize(value, ...)
1: new("xyloc", x = runif(20), y = runif(20))

This suggests that "package:S4nswv" and its versioned equivalent are not 
being associated, and I'd be grateful for pointers about how to do this. 

Removing the NAMESPACE, and uncommenting .First.lib() in R/zzz.R removes 
the problem, that is the skeletal package works --with-package-versions, 
but this isn't an option.

At present, the methods package is invoked in DESCRIPTION in the Depends:  
field, by "import(methods)" in NAMESPACE, and by

.onLoad <- function(lib, pkg) require(methods)

in zzz.R, which feels like overkill, but removing them one-by-one doesn't 
seem to affect the problem.

(I don't think this is the same problem as Seth's)

Roger

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-devel mailing list