sloiseau at limsi.fr
2009-Aug-26 07:37 UTC
[Rd] Problem with standard generic methods in Matrix package
I have posted this message on r-lang, but it is perhaps more appropriate
on r-devel:
---
Hello,
I'm puzzled by a problem with call to diag(), rowSums(), rownames() on
objects of class "dgtMatrix", created by sparseMatrix() or spMatrix().
I use Matrix 0.999375-30.
The weird thing is that I don't encounter any problem when I use this
functions on the R prompt, or source()-ing a script file; I encounter
problems when the code is in a package, installed with R CMD INSTALL, and
loaded with library().
I have tried to reduce the package to the bare minimum in order to
discover the problem, but it continue even when reduced up to a single
method, no dependency other than Matrix. The method is defined as:
---
getAdjacentAsSparseMatrix <- function() {
adjacents <- sparseMatrix(i=1:10, j=1:10, x=1:10)
print(class(adjacents));
diagonal <- as.vector(diag(adjacents));
if (any(diagonal != 0)) {
diagonal[diagonal > 1] <- 1;
diag(adjacents) <- diagonal;
}
return(adjacents);
}
---
And the Depends field in ./DESCRIPTION :
---
Depends: R (>= 2.5.0), Matrix
---
I have this outputs:
[1] "dgTMatrix"
Erreur dans y[1L + 0L:(m - 1L) * (n + 1L)] <- x :
types (de S4 a double) incompatibles dans l'ajustement
d'affectation de
type
> traceback()
3: diag(adjacents)
2: as.vector(diag(adjacents))
1: getAdjacentAsSparseMatrix(white3)
The same thing happens with the method rowSums(), colnames() and
rownames(). In brief, it looks as if the generic functions were called,
and not the overloaded ones. I can't figure out how to fix that, and will
be interested in any pointers.
Best,
Sylvain
Martin Maechler
2009-Aug-27 15:01 UTC
[Rd] Problem with standard generic methods in Matrix package
Dear Sylvain,>>>>> "s" == sloiseau <sloiseau at limsi.fr> >>>>> on Wed, 26 Aug 2009 09:37:34 +0200 (CEST) writes:s> I have posted this message on r-lang, but it is perhaps more appropriate s> on r-devel: [[ "r-lang" what's that ??? ]] s> --- s> Hello, s> I'm puzzled by a problem with call to diag(), rowSums(), rownames() on s> objects of class "dgtMatrix", created by sparseMatrix() or spMatrix(). s> I use Matrix 0.999375-30. s> The weird thing is that I don't encounter any problem when I use this s> functions on the R prompt, or source()-ing a script file; I encounter s> problems when the code is in a package, installed with R CMD INSTALL, and s> loaded with library(). s> I have tried to reduce the package to the bare minimum in order to s> discover the problem, but it continue even when reduced up to a single s> method, no dependency other than Matrix. The method is defined as: I think it would still be most efficient, if you do 'R CMD build <yourpackage>' and make the <yourpackage>.tar.gz file available. Ideally for every reader of this list, from a "public" URL; alternatively, send it per e-mail as attachment; if you use correct MIME type, i.e., one of application/x-tar application/x-compressed-tar application/x-gzip then the file should *not* be filtered out by the mailing list software. Best regards, Martin Maechler, ETH Zurich (one of the 'Matrix' authors) s> --- s> getAdjacentAsSparseMatrix <- function() { s> adjacents <- sparseMatrix(i=1:10, j=1:10, x=1:10) s> print(class(adjacents)); s> diagonal <- as.vector(diag(adjacents)); s> if (any(diagonal != 0)) { s> diagonal[diagonal > 1] <- 1; s> diag(adjacents) <- diagonal; s> } s> return(adjacents); s> } s> --- s> And the Depends field in ./DESCRIPTION : s> --- s> Depends: R (>= 2.5.0), Matrix s> --- s> I have this outputs: s> [1] "dgTMatrix" s> Erreur dans y[1L + 0L:(m - 1L) * (n + 1L)] <- x : s> types (de S4 a double) incompatibles dans l'ajustement d'affectation de s> type >> traceback() s> 3: diag(adjacents) s> 2: as.vector(diag(adjacents)) s> 1: getAdjacentAsSparseMatrix(white3) s> The same thing happens with the method rowSums(), colnames() and s> rownames(). In brief, it looks as if the generic functions were called, s> and not the overloaded ones. I can't figure out how to fix that, and will s> be interested in any pointers. s> Best, s> Sylvain s> ______________________________________________ s> R-devel at r-project.org mailing list s> https://stat.ethz.ch/mailman/listinfo/r-devel