SCM Repository

[matrix] Diff of /pkg/R/Auxiliaries.R
 [matrix] / pkg / R / Auxiliaries.R

Diff of /pkg/R/Auxiliaries.R

revision 1173, Mon Jan 16 20:02:16 2006 UTC revision 1174, Mon Jan 16 20:03:48 2006 UTC
# Line 247  Line 247
247      if(ok) as(x, classes[1]) else x      if(ok) as(x, classes[1]) else x
248  }  }
249
250  ## MM thinks the following should become part of 'methods' :  if(paste(R.version\$major, R.version\$minor, sep=".") < "2.3")
251        ## This will be in R 2.3.0
252  canCoerce <- function(object, Class) {  canCoerce <- function(object, Class) {
253    ## Purpose:  test if 'object' is coercable to 'Class', i.e.,    ## Purpose:  test if 'object' is coercable to 'Class', i.e.,
254    ##           as(object, Class) will {typically} work    ##           as(object, Class) will {typically} work
# Line 259  Line 260
260                           useInherited = c(from = TRUE, to = FALSE)))                           useInherited = c(from = TRUE, to = FALSE)))
261  }  }
262
263    .is.triangular <- function(object, upper = TRUE) {
264        ## pretest: is it square?
265        d <- dim(object)
266        if(d[1] != d[2]) return(FALSE)
267        ## else slower test
268        if(!is.matrix(object))
269            object <- as(object,"matrix")
270        ## == 0 even works for logical & complex:
271        if(upper)
272            all(object[lower.tri(object)] == 0)
273        else
274            all(object[upper.tri(object)] == 0)
275    }
276
277    .is.diagonal <- function(object) {
278        d <- dim(object)
279        if(d[1] != (n <- d[2])) FALSE
280        else all(object[rep(c(FALSE, rep.int(TRUE,n)), length = n^2)] == 0)
281    }

Legend:
 Removed from v.1173 changed lines Added in v.1174