[Rd] Matrix / SparseM conflict (PR#8618)

Duncan Murdoch murdoch at stats.uwo.ca
Mon Feb 20 15:05:44 CET 2006


On 2/20/2006 8:54 AM, dpleydel at univ-fcomte.fr wrote:
> Full_Name: David Pleydell
> Version: 2.2.1
> OS: Debian Etch
> Submission from: (NULL) (193.55.70.206)
> 
> 
> There appears to be a conflict between the chol functions from the Matrix and
> the SparseM packages. chol() can only be applied to a matrix of class dspMatrix
> if SparseM is not in the path.

This isn't a bug, it's simply that both Matrix and SparseM define a 
generic for chol (though Matrix actually gets it by converting the 
function in base).

If you want access to the version in Matrix after attaching SparseM 
ahead of it in the search path, use Matrix::chol.

 > library(Matrix)
 > sm <- as(as(Matrix(diag(5) + 1), "dsyMatrix"), "dspMatrix")
 > library(SparseM)
[1] "SparseM library loaded"
 > chol(sm)
Error in chol(sm) : no applicable method for "chol"
 > Matrix::chol(sm)
5 x 5 Matrix of class "pCholesky"
      [,1]      [,2]      [,3]      [,4]      [,5]
[1,] 1.4142136 0.7071068 0.7071068 0.7071068 0.7071068
[2,]         . 1.2247449 0.4082483 0.4082483 0.4082483
[3,]         .         . 1.1547005 0.2886751 0.2886751
[4,]         .         .         . 1.1180340 0.2236068
[5,]         .         .         .         . 1.0954451

You might want to discuss this with the SparseM package maintainers; 
perhaps they don't really need to define their own generic.

Duncan Murdoch

> 
> with gratitude
> David
> 
> 
>> library(Matrix)
>> sm <- as(as(Matrix(diag(5) + 1), "dsyMatrix"), "dspMatrix")
>> chol(sm)
> 5 x 5 Matrix of class "pCholesky"
>      [,1]      [,2]      [,3]      [,4]      [,5]     
> [1,] 1.4142136 0.7071068 0.7071068 0.7071068 0.7071068
> [2,]         . 1.2247449 0.4082483 0.4082483 0.4082483
> [3,]         .         . 1.1547005 0.2886751 0.2886751
> [4,]         .         .         . 1.1180340 0.2236068
> [5,]         .         .         .         . 1.0954451
>> 
>> library(SparseM)
> [1] "SparseM library loaded"
>> chol(sm)
> Error in chol(sm) : no applicable method for "chol"
>> 
>> detach("package:SparseM")
>> chol(sm)
> 5 x 5 Matrix of class "pCholesky"
>      [,1]      [,2]      [,3]      [,4]      [,5]     
> [1,] 1.4142136 0.7071068 0.7071068 0.7071068 0.7071068
> [2,]         . 1.2247449 0.4082483 0.4082483 0.4082483
> [3,]         .         . 1.1547005 0.2886751 0.2886751
> [4,]         .         .         . 1.1180340 0.2236068
> [5,]         .         .         .         . 1.0954451
>>
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



More information about the R-devel mailing list