From maechler at stat.math.ethz.ch  Thu Aug 27 17:01:47 2009
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Thu, 27 Aug 2009 17:01:47 +0200
Subject: [Rd] Problem with standard generic methods in Matrix package
In-Reply-To: <37353.193.51.130.16.1251272254.squirrel@keo.limsi.fr>
References: <37353.193.51.130.16.1251272254.squirrel@keo.limsi.fr>
Message-ID: <19094.40923.755278.599681@lynne.math.ethz.ch>

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



[Rd] Problem with standard generic methods in Matrix package
Martin Maechler