SCM

SCM Repository

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

Diff of /pkg/R/Tsparse.R

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

revision 1225, Mon Mar 13 14:06:17 2006 UTC revision 1226, Mon Mar 13 14:07:58 2006 UTC
# Line 28  Line 28 
28                  stop("you cannot mix negative and positive indices")                  stop("you cannot mix negative and positive indices")
29              i0 <- (0:(di[margin]-1:1))[i]              i0 <- (0:(di[margin]-1:1))[i]
30          } else  {          } else  {
31                if(max(i) > di[margin])
32                    stop("indexing out of range 0:",di[margin])
33                if(any(z <- i == 0)) i <- i[!z]
34              i0 <- i - 1:1 # transform to 0-indexing              i0 <- i - 1:1 # transform to 0-indexing
35          }          }
36          if(has.dn) dn <- dn[i]          if(has.dn) dn <- dn[i]
# Line 39  Line 42 
42          if(!has.dn)          if(!has.dn)
43              stop(gettextf("no 'dimnames[[%d]]': cannot use character indexing"),              stop(gettextf("no 'dimnames[[%d]]': cannot use character indexing"),
44                   margin, domain = NA)                   margin, domain = NA)
45          i0 <- match(i, dn, nomatch=0)          i0 <- match(i, dn)
46            if(any(is.na(i0))) stop("invalid character indexing")
47          dn <- dn[i0]          dn <- dn[i0]
48          i0 <- i0 - 1:1          i0 <- i0 - 1:1
49      }      }
# Line 47  Line 51 
51  }  }
52    
53    
54    .ind.prep2 <- function(i, margin, di, dn)
55    {
56        ## Purpose: do the ``common things'' for "*gTMatrix" sub-assignment
57        ##          for 1 dimension, 'margin' ,
58        ##          and return match(.,.) + li = length of corresponding dimension
59        ##
60        ## i is "index"; margin in {1,2};
61        ## di = dim(x)      { used when i is "logical" }
62    
63        dn <- dn[[margin]]
64        has.dn <- is.character(dn)
65        if(is(i, "numeric")) {
66            storage.mode(i) <- "integer"
67            if(any(ineg <- i < 0:0)) {
68                if(any(i > 0:0))
69                    stop("you cannot mix negative and positive indices")
70                i0 <- (1:di[margin])[i]
71            } else  {
72                if(max(i) > di[margin])
73                    stop("indexing out of range 0:",di[margin])
74                if(any(z <- i == 0)) i <- i[!z]
75                i0 <- i
76            }
77        }
78        else if (is(i, "logical")) {
79            i0 <- (1:di[margin])[i]
80        } else { ## character
81            if(!has.dn)
82                stop(gettextf("no 'dimnames[[%d]]': cannot use character indexing"),
83                     margin, domain = NA)
84            i0 <- match(i, dn)
85            if(any(is.na(i0))) stop("invalid character indexing")
86        }
87        i0 - 1:1  # transform to 0-indexing
88    }
89    
90    
91  ## Otherwise have to write methods for all possible combinations of  ## Otherwise have to write methods for all possible combinations of
92  ##  (i , j) \in  ##  (i , j) \in
93  ##  (numeric, logical, character, missing) x (numeric, log., char., miss.)  ##  (numeric, logical, character, missing) x (numeric, log., char., miss.)

Legend:
Removed from v.1225  
changed lines
  Added in v.1226

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