I''m trying to update the SparseM package from S3 to S4 method dispatch.
Everything seemed to be working fine until I did an "R CMD check
SparseM" and got the following error message logged in SparseM-Ex.Rout when
one of the examples failed:
R : Copyright 2002, The R Development Core Team
Version 1.6.1 (2002-11-01)
...stuff deleted...> library(''SparseM'')
Creating a new generic function for "as.matrix" in package
.GlobalEnv
Creating a new generic function for "t" in package .GlobalEnv
...stuff deleted...
Creating a new generic function for "model.matrix" in
package .GlobalEnv
[1] "SparseM library loaded"
Attaching package `SparseM'':
...stuff deleted...> cleanEx(); ..nameEx <- "SparseM.image"
> ###--
College of Business Administration
PO Box 15066
Flagstaff, AZ 86011-5066
vox: (928) 523-8726
fax: (928) 523-7331
e-mail: Pin.Ng@nau.edu
url: http://www.cba.nau.edu/pin-ng- >>> `SparseM.image''
<<<----- Image Plot for Sparse Matrices>
> ## alias help(image.matrix.csr)
> ## alias help(image.matrix.csc)
> ## alias help(SparseM.image)
>
> ##___ Examples ___:
>
> a <- rnorm(20*5)
> A <- matrix(a,20,5)
> A[row(A)>col(A)+4|row(A)<col(A)+3] <- 0
> b <- rnorm(20*5)
> B <- matrix(b,20,5)
> B[row(A)>col(A)+2|row(A)<col(A)+2] <- 0
> image(as.matrix.csr(A)%*%as.matrix.csr(t(B)))
Error in as.matrix.csr(A) %*% as.matrix.csr(t(B)) :
couldn''t find function "as.matrix.csr"
Execution halted
Following is part of the relevant class and method definitions:
setClass("matrix.csr",representation ra="numeric",
ja="numeric", ia="numeric", dimension="numeric"))
setGeneric("as.matrix.csr",function(x,...)
standardGeneric("as.matrix.csr"))
setMethod("as.matrix.csr",signature(x="ANY"),matrix.csr)
I installed SparseM anyway and ran the following test:
> library(''SparseM'')
Creating a new generic function for "as.matrix" in package
.GlobalEnv
Creating a new generic function for "t" in package .GlobalEnv
Creating a new generic function for "diag" in package
.GlobalEnv
Creating a new generic function for "diag<-" in package
.GlobalEnv
Creating a new generic function for "chol" in package
.GlobalEnv
Creating a new generic function for "backsolve" in package
.GlobalEnv
Creating a new generic function for "solve" in package
.GlobalEnv
Creating a new generic function for "model.matrix" in
package .GlobalEnv
[1] "SparseM library loaded"
Attaching package `SparseM'':
The following object(s) are masked from package:base :
%*%
> example(''SparseM.image'')
SprsM.> a <- rnorm(20 * 5)
SprsM.> A <- matrix(a, 20, 5)
SprsM.> A[row(A) > col(A) + 4 | row(A) < col(A) + 3] <- 0
SprsM.> b <- rnorm(20 * 5)
SprsM.> B <- matrix(b, 20, 5)
SprsM.> B[row(A) > col(A) + 2 | row(A) < col(A) + 2] <- 0
SprsM.> image(as.matrix.csr(A) %*% as.matrix.csr(t(B)))
Warning messages:
1: there is no package called `methods'' in: .find.package(package,
lib.loc, verbose = verbose)
2: there is no package called `ctest'' in: .find.package(package,
lib.loc, verbose = verbose)
3: there is no package called `base'' in: .find.package(package,
lib.loc, verbose = verbose) >
I don''t understand exactly what causes the warning messages but the
image was plotted without any problem. To me, it seems to suggest that the
methods for classes "matrix" and "matrix.csr" are well
defined for the generic function "as.matrix.csr". Somehow, the method
dispatch computation got lost during ''R CMD check''. Why?
The reason that ''%*%'' is masked from package:base in the
above example is because I still haven''t figured out a way to use the
S4 method dispatch for ''%*%''. Here''s what I tried:
"matmul.matrix.csr" <- function(e1,e2){ ...details deleted...}
setMethod("%*%", signature(e1 = "matrix.csr",
e2="matrix.csr"), matmul.matrix.csr)
and here''s the error message:
Error in match.call(fun, fcall) : unused argument(s) (e1 ...)
So what''s the correct way to set the method %*% for class
"matrix.csr"?
I would really appreciate if someone can shed some light on the two questions
above.
Pin
[[alternate HTML version deleted]]