# SCM Repository

[matrix] Diff of /pkg/R/Matrix.R
 [matrix] / pkg / R / Matrix.R # Diff of /pkg/R/Matrix.R

revision 1467, Wed Aug 30 21:35:09 2006 UTC revision 1472, Fri Sep 1 15:31:04 2006 UTC
# Line 282  Line 282
282            function(x,i,j, drop)            function(x,i,j, drop)
283            stop("invalid or not-yet-implemented 'Matrix' subsetting"))            stop("invalid or not-yet-implemented 'Matrix' subsetting"))
284
285  ##  "logical *vector* indexing, such as  M [ M >= 10 ] :  ## logical indexing, such as M[ M >= 7 ] *BUT* also M[ M[,1] >= 3,],
286  setMethod("[", signature(x = "Matrix", i = "lMatrix", j = "missing",  ## The following is *both* for    M [ <logical>   ]
287                           drop = "ANY"),  ##                 and also for   M [ <logical> , ]
288            function (x, i, j, drop) {  .M.sub.i.logical <- function (x, i, j, drop)
289    {
290        nA <- nargs()
291        if(nA == 2) { ##  M [ M >= 7 ]
292                as(x, geClass(x))@x[as.vector(i)]                as(x, geClass(x))@x[as.vector(i)]
293                ## -> error when lengths don't match                ## -> error when lengths don't match
294            })      } else if(nA == 3) { ##  M [ M[,1, drop=FALSE] >= 7, ]
295            stop("not-yet-implemented 'Matrix' subsetting") ## FIXME
296
297  ## FIXME: The following is good for    M [ <logical>   ]      } else stop("nargs() = ", nA,
298  ##        *BUT* it also triggers for   M [ <logical> , ] where it is *WRONG*                  " should never happen; please report.")
299  ##       using nargs() does not help: it gives '3' for both cases  }
300  if(FALSE)  setMethod("[", signature(x = "Matrix", i = "lMatrix", j = "missing",
301                             drop = "ANY"),
302              .M.sub.i.logical)
303  setMethod("[", signature(x = "Matrix", i = "logical", j = "missing",  setMethod("[", signature(x = "Matrix", i = "logical", j = "missing",
304                           drop = "ANY"),                           drop = "ANY"),
305            function (x, i, j, drop) {            .M.sub.i.logical)
## DEBUG
cat("[(Matrix,i,..): nargs=", nargs(),"\n")
as(x, geClass(x))@x[i] })
306
307
308  ## "FIXME:"  ## "FIXME:"
309  ## How can we get at   A[ ij ]  where ij is (i,j) 2-column matrix?  ## ------ get at  A[ ij ]  where ij is (i,j) 2-column matrix?
310  ##  and                A[ LL ]  where LL is a logical *vector*
## -> [.data.frame uses nargs() - can we do this in the *generic* ?
311
312
313  ### "[<-" : -----------------  ### "[<-" : -----------------

Legend:
 Removed from v.1467 changed lines Added in v.1472

 root@r-forge.r-project.org ViewVC Help Powered by ViewVC 1.0.0
Thanks to:  