SCM

SCM Repository

[matrix] Diff of /pkg/R/Matrix.R
ViewVC logotype

Diff of /pkg/R/Matrix.R

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 675, Sat Mar 26 11:16:05 2005 UTC revision 676, Sat Mar 26 15:59:18 2005 UTC
# Line 12  Line 12 
12      d <- dim(object)      d <- dim(object)
13      cl <- class(object)      cl <- class(object)
14      cat(sprintf('%d x %d Matrix of class "%s"\n', d[1], d[2], cl))      cat(sprintf('%d x %d Matrix of class "%s"\n', d[1], d[2], cl))
15      if(cl == "Matrix") { ## have no data slot  ##- no longer needed: have no objects of virtual classes:
16          cat("Dim = ", d)  ##     if(cl == "Matrix") { ## have no data slot
17          if(any(sapply(object@Dimnames,length) > 0)) {  ##         cat("Dim = ", d)
18              cat("; Dimnames = ")  ##         if(any(sapply(object@Dimnames,length) > 0)) {
19              str(object@Dimnames)  ##             cat("; Dimnames = ")
20          }  ##             str(object@Dimnames)
21          cat("\n")  ##         }
22      } else { # not "Matrix", hence have data 'x' slot  ##         cat("\n")
23    ##     } else { # not "Matrix", hence have data 'x' slot
24          m <- as(object, "matrix")          m <- as(object, "matrix")
25          maxp <- getOption("max.print")          maxp <- getOption("max.print")
26          if(prod(d) <= maxp) print(m)          if(prod(d) <= maxp) print(m)
# Line 31  Line 32 
32              print(tail(m, max(1, nr - n2)))              print(tail(m, max(1, nr - n2)))
33          }          }
34          ## DEBUG: cat("str(.):\n") ; str(object)          ## DEBUG: cat("str(.):\n") ; str(object)
35      }  ##    }
36      invisible()      invisible(object)# as print() S3 methods do
37  }  }
38    
39  setMethod("show", signature(object = "ddenseMatrix"), prMatrix)  setMethod("show", signature(object = "ddenseMatrix"), prMatrix)
40    
41    setMethod("show", signature(object = "sparseMatrix"),
42       function(object) {
43           d <- dim(object)
44           cl <- class(object)
45           cat(sprintf('%d x %d sparse Matrix of class "%s"\n', d[1], d[2], cl))
46    
47           maxp <- getOption("max.print")
48           if(prod(d) <= maxp) print(as(object, "matrix"))
49           else { ## d[1] > maxp / d[2] >= nr :
50               cat("\n Not printing large sparse matrix -- maybe increase options(max.print)\n")
51               if(FALSE) { ### need storage economic "[,]" method for sparse!!
52                   nr <- maxp %/% d[2]
53                   n2 <- ceiling(nr / 2)
54                   print(head(m, max(1, n2)))
55                   cat("\n ..........\n\n")
56                   print(tail(m, max(1, nr - n2)))
57               }
58           }
59            ## DEBUG: cat("str(.):\n") ; str(object)
60           invisible(object)
61       })
62    
63  ## this may go away {since sparse matrices need something better!} :  ## this may go away {since sparse matrices need something better!} :
64  setMethod("show", signature(object = "Matrix"), prMatrix)  setMethod("show", signature(object = "Matrix"), prMatrix)
65    
66  ## Is this sufficient for all subclasses?  ## should propagate to all subclasses:
67  setMethod("as.matrix", signature(x = "Matrix"), function(x) as(x, "matrix"))  setMethod("as.matrix", signature(x = "Matrix"), function(x) as(x, "matrix"))
68    
   
69  setMethod("dim", signature(x = "Matrix"),  setMethod("dim", signature(x = "Matrix"),
70            function(x) x@Dim, valueClass = "integer")            function(x) x@Dim, valueClass = "integer")
71  setMethod("dimnames", signature(x = "Matrix"), function(x) x@Dimnames)  setMethod("dimnames", signature(x = "Matrix"), function(x) x@Dimnames)

Legend:
Removed from v.675  
changed lines
  Added in v.676

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business Powered By FusionForge