Re: [R] conflict of package "Matrix" and summary of lme object

From: Martin Maechler <>
Date: Mon 24 Jul 2006 - 23:41:52 EST

>>>>> "Dirk" == Dirk Enzmann <> >>>>> on Mon, 24 Jul 2006 13:55:44 +0200 writes:

    Dirk> After loading the package "Matrix" (version 0.995-12),
    Dirk> using the summary function with an lme (package nlme
    Dirk> version 3.1-75) object results in an error message
    Dirk> saying

    Dirk> Fehler in dim(x) : kein Slot des Namens "Dim" für     Dirk> dieses Objekt der Klasse "correlation"

    Dirk> (translated: 'Error in dim(x) : no slot of the name     Dirk> "Dim" for this object of class "correlation")'.

    Dirk> Without loading "Matrix" this error message does not     Dirk> occur.

    Dirk> Any ideas?

Yes. Thank you for the report.
The error happens when PRINTing a summary.lme object, i.e.,

	ssl <- summary(<lme> )  ## works fine
	ssl                     ##-> gives the error

The short answer:

   Don't use 'Matrix' together with 'nlme' for the time being    (but rather use 'lme4' and lmer() if possible)

A long answer:

The problem happens because
'Matrix' defines a (S4) class "correlation" (which inherits from "dpoMatrix"). Hence dim( <correlation> ) is accessing the 'Dim' slot of the <correlation> object --- which obviously must fail for that part of a "summary.lme" object which is not a proper S4 object at all.

Here is reproducible example of showing the problem without even doing an nlme related thing:

> x <- round(cor(matrix(rnorm(100), 20,5)),2); class(x) <- "correlation" ; x

         [,1] [,2] [,3] [,4] [,5]

   [1,]  1.00 -0.29 -0.07 -0.11  0.03
   [2,] -0.29  1.00  0.10 -0.02  0.20
   [3,] -0.07  0.10  1.00  0.05  0.13
   [4,] -0.11 -0.02  0.05  1.00 -0.21
   [5,]  0.03  0.20  0.13 -0.21  1.00

   [1] "correlation"
> dim(x)

   [1] 5 5
> library(Matrix)

   Loading required package: lattice
> dim(x)

   Error in dim(x) : no slot of name "Dim" for this object of class "correlation"
> dim

> showMethods(dim)

   Function "dim":

    x = "ANY"
    x = "Matrix"
    x = "correlation"
       (inherited from x = "Matrix")

> showClass("correlation")


   Name:         sd         x       Dim  Dimnames      uplo   factors
   Class:   numeric   numeric   integer      list character      list


   Class "dpoMatrix", directly
   Class "dsyMatrix", by class "dpoMatrix"
   Class "ddenseMatrix", by class "dpoMatrix"
   Class "symmetricMatrix", by class "dpoMatrix"
   Class "dMatrix", by class "dpoMatrix"
   Class "denseMatrix", by class "dpoMatrix"
   Class "Matrix", by class "dpoMatrix"
   Class "Matrix", by class "dpoMatrix"
   Class "compMatrix", by class "dpoMatrix"
   Class "Matrix", by class "dpoMatrix"


A workaround -- not for you but the authors of 'Matrix' and/or 'nlme' -- is for one of the two packages to call the class differently. At the moment, I tend to do the change in 'nlme', since there, the "correlation" class has been almost entirely hidden from the user.

A workaround for you: Redefine print.summary.lme, e.g., by commenting the line

    class(corr) <- "correlation"

Martin mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Mon Jul 24 23:50:05 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 25 Jul 2006 - 00:19:55 EST.

Mailing list information is available at Please read the posting guide before posting to the list.