Problem loading package with version, S4 classes and NAMESPACE

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem loading package with version, S4 classes and NAMESPACE

Roger Bivand
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: [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Roger Bivand
Department of Economics
NHH Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway
Reply | Threaded
Open this post in threaded view
|

Re: Problem loading package with version, S4 classes and NAMESPACE

Roger Bivand
On Fri, 20 Jan 2006, Roger Bivand wrote:

> 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.

Further to my question, hardcoding the package= argument to the versioned
package name string in setClass() removes the problem when installing with
versions (for that version), but creates the reverse problem if installed
(by default) without versions:

> library(S4nswv)
> xyd <- new("xyloc", x=runif(20), y=runif(20))
Loading required package: S4nswv_0.1-1
Error in .requirePackage(package) : unable to find required package
'S4nswv_0.1-1'
In addition: Warning message:
there is no package called 'S4nswv', version 0.1-1 in: library(package,
character.only = TRUE, logical = TRUE, warn.conflicts = warn.conflicts,  
Error in initialize(value, ...) : S language method selection got an error
when called from internal dispatch for function 'initialize'

The default for the package argument is getPackageName(where), and where =
topenv(parent.frame()). There are comments in methods/R/packageName.R
suggesting that the hidden object .packageName is being made invisible by
NAMESPACE.

It looks as though R_PACKAGE_NAME as a shell variable could be used to
smuggle the correct string in, but I'm not sure what order things happen
in.

>
> 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: [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Roger Bivand
Department of Economics
NHH Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway